> From: "Rodolfo García Peñas (kix)" <[email protected]>
> 
> This patch set the icon position for the WDock using the icon image,
> because this method is used by the Clip and the Dock.
> 
> Now, when the WAppIcon image is created, the final position is set:

The patch seems to blur even more the difference between object
creation and state restoration. Cf. the static function mainIconCreate
that will actually restore position from the saved state, and restore
only that it seems. Or wDockCreate() that now takes a WMPropList
*state parameter. I agree wClipRestoreState() is a good candidate for
removal, as it seems to do a subset of wDockRestoreState() does, and
the latter handles clips already, but I'm not convinced with the
patch.

I'd have to spend more time understanding the session restoration
process. Avoiding the creation of a useless clip before creating the
final one (patch 5) might be enough to prevent the startup flash. If
not, the culprit could be that statement
       XMapWindow(dpy, btn->icon->core->window);
from dock.c:mainIconCreate(), showing the appicon before it's ready.
IMO, the ideal startup sequence would be
1. Create objects with default settings
2. Restore saved state
3. Show final objects (map them)

-- Daniel

> -------------8<----------------
> @ -750,6 +751,9 @@ static WAppIcon *mainIconCreate(WScreen *scr, int
> type)
>         if (type == WM_CLIP)
>                 scr->clip_icon = btn;
> 
> +       /* After the default set, set the final place */
> +       set_appicon_position_from_dictionary(btn, type);
> +
> -------------8<----------------
> 
> Therefore, we don't need use that code in wClipRestoreState nor
> wDockRestoreState. Then, wClipRestoreState and wDockRestoreState are
> similar functions, and then we can replace wClipRestoreState() by
> wDockRestoreState() using the type of the Dock.
> 
> Finally, the Dock/Clip needs know their final position after the
> function
> set_appicon_position_from_dictionary(), because, for example,
> the Dock can be placed on the right side or the left side of the
> screen.
> Then, we must move the code from wDockRestoreState to wDockCreate:
> 
> -------------8<----------------
> +       } else {
> +               /* Set the Dock/Clip in the right side */
> +               if (dock->type == WM_CLIP) {
> +                       if (dock->x_pos < 0)
> +                               dock->x_pos = 0;
> +                       else if (dock->x_pos >
> dock->screen_ptr->scr_width - ICON_SIZE)
> +                               dock->x_pos =
> dock->screen_ptr->scr_width - ICON_SIZE;
> +               } else {
> +                       if (dock->x_pos >= 0) {
> +                               dock->x_pos = DOCK_EXTRA_SPACE;
> +                               dock->on_right_side = 0;
> +                       } else {
> +                               dock->x_pos =
> dock->screen_ptr->scr_width - DOCK_EXTRA_SPACE - ICON_SIZE;
> +                               dock->on_right_side = 1;
> +                       }
> +               }
> +       }
> -------------8<----------------
> 
> The only exception is if we call wDockCreate() in wWorkspaceNew(),
> because in that case, we are creating a new WorkSpace, then, we
> cannot
> find the position for the Clip in the Config file. Then, we use the
> position of the Clip in the Workspace 0:
> 
> -------------8<----------------
> +       /* Now, read from the config file */
> +       if (state == NULL && type == WM_CLIP) {
> +               /* New desktop! use other desktop Clip position */
> +               dock->x_pos = scr->workspaces[0]->clip->x_pos;
> +               dock->y_pos = scr->workspaces[0]->clip->y_pos;
> -------------8<----------------
> 
> Then, after all these changes, we can remove the Clip creation in
> screen.c
> because that Clip is an extra Clip, used only to set the WAppIcon,
> used
> by the Clips when they are created when the workspace is created (the
> clip_icon in screen.h). Because now this variable is set when the
> first
> real Clip is created, is not used anymore.
> 
> Then, we can remove wClipRestoreState(), because is not used.
> 
> Signed-off-by: Rodolfo García Peñas (kix) <[email protected]>
> ---
>  src/dock.c      |  135
>  +++++++++++++++----------------------------------------
>  src/dock.h      |    3 +-
>  src/screen.c    |    6 ---
>  src/workspace.c |    2 +-
>  4 files changed, 37 insertions(+), 109 deletions(-)
> 
> diff --git a/src/dock.c b/src/dock.c
> index 529740a..de2329d 100644
> --- a/src/dock.c
> +++ b/src/dock.c
> @@ -117,6 +117,7 @@ static void clipAutoLower(void *cdata);
>  static void clipAutoRaise(void *cdata);
>  static void reattachIcon(WDock *dock, WAppIcon *icon, int x, int y);
>  static WAppIcon *mainIconCreate(WScreen *scr, int type);
> +void set_appicon_position_from_dictionary(WAppIcon *icon, int type);
>  
>  static void make_keys(void)
>  {
> @@ -750,6 +751,9 @@ static WAppIcon *mainIconCreate(WScreen *scr, int
> type)
>       if (type == WM_CLIP)
>               scr->clip_icon = btn;
>  
> +     /* After the default set, set the final place */
> +     set_appicon_position_from_dictionary(btn, type);
> +
>       return btn;
>  }
>  
> @@ -1084,7 +1088,7 @@ static WMenu *create_alt_menu(WScreen *scr, int
> type)
>       return menu;
>  }
>  
> -WDock *wDockCreate(WScreen *scr, int type)
> +WDock *wDockCreate(WScreen *scr, WMPropList *state, int type)
>  {
>       WDock *dock;
>       WAppIcon *btn;
> @@ -1094,15 +1098,10 @@ WDock *wDockCreate(WScreen *scr, int type)
>       dock = wmalloc(sizeof(WDock));
>  
>       dock->max_icons = DOCK_MAX_ICONS;
> -
>       dock->icon_array = wmalloc(sizeof(WAppIcon *) * dock->max_icons);
>  
>       btn = mainIconCreate(scr, type);
> -
>       btn->dock = dock;
> -
> -     dock->x_pos = btn->x_pos;
> -     dock->y_pos = btn->y_pos;
>       dock->screen_ptr = scr;
>       dock->type = type;
>       dock->icon_count = 1;
> @@ -1116,6 +1115,35 @@ WDock *wDockCreate(WScreen *scr, int type)
>       dock->attract_icons = 0;
>       dock->lowered = 1;
>       dock->icon_array[0] = btn;
> +
> +     /* Set the coords for the dock
> +      * Use the icon as default */
> +     dock->x_pos = btn->x_pos;
> +     dock->y_pos = btn->y_pos;
> +
> +     /* Now, read from the config file */
> +     if (state == NULL && type == WM_CLIP) {
> +             /* New desktop! use other desktop Clip position */
> +             dock->x_pos = scr->workspaces[0]->clip->x_pos;
> +             dock->y_pos = scr->workspaces[0]->clip->y_pos;
> +     } else {
> +             /* Set the Dock/Clip in the right side */
> +             if (dock->type == WM_CLIP) {
> +                     if (dock->x_pos < 0)
> +                             dock->x_pos = 0;
> +                     else if (dock->x_pos > dock->screen_ptr->scr_width - 
> ICON_SIZE)
> +                             dock->x_pos = dock->screen_ptr->scr_width - 
> ICON_SIZE;
> +             } else {
> +                     if (dock->x_pos >= 0) {
> +                             dock->x_pos = DOCK_EXTRA_SPACE;
> +                             dock->on_right_side = 0;
> +                     } else {
> +                             dock->x_pos = dock->screen_ptr->scr_width - 
> DOCK_EXTRA_SPACE -
> ICON_SIZE;
> +                             dock->on_right_side = 1;
> +                     }
> +             }
> +     }
> +
>       wRaiseFrame(btn->icon->core);
>       XMoveWindow(dpy, btn->icon->core->window, btn->x_pos, btn->y_pos);
>  
> @@ -1556,57 +1584,6 @@ void
> set_appicon_position_from_dictionary(WAppIcon *icon, int type)
>       WMReleasePropList(state);
>  }
>  
> -WAppIcon *wClipRestoreState(WScreen *scr, WMPropList *clip_state)
> -{
> -     WAppIcon *icon;
> -     WMPropList *value;
> -
> -     icon = mainIconCreate(scr, WM_CLIP);
> -
> -     if (!clip_state)
> -             return icon;
> -
> -     WMRetainPropList(clip_state);
> -
> -     /* restore position */
> -
> -     value = WMGetFromPLDictionary(clip_state, dPosition);
> -
> -     if (value) {
> -             if (!WMIsPLString(value)) {
> -                     COMPLAIN("Position");
> -             } else {
> -                     WMRect rect;
> -                     int flags;
> -
> -                     if (sscanf(WMGetFromPLString(value), "%i,%i", 
> &icon->x_pos,
> &icon->y_pos) != 2)
> -                             COMPLAIN("Position");
> -
> -                     /* check position sanity */
> -                     rect.pos.x = icon->x_pos;
> -                     rect.pos.y = icon->y_pos;
> -                     rect.size.width = rect.size.height = ICON_SIZE;
> -
> -                     wGetRectPlacementInfo(scr, rect, &flags);
> -                     if (flags & (XFLAG_DEAD | XFLAG_PARTIAL))
> -                             wScreenKeepInside(scr, &icon->x_pos, 
> &icon->y_pos, ICON_SIZE,
> ICON_SIZE);
> -             }
> -     }
> -#ifdef XDND                  /* was OFFIX */
> -     value = WMGetFromPLDictionary(clip_state, dDropCommand);
> -     if (value && WMIsPLString(value))
> -             icon->dnd_command = wstrdup(WMGetFromPLString(value));
> -#endif
> -
> -     value = WMGetFromPLDictionary(clip_state, dPasteCommand);
> -     if (value && WMIsPLString(value))
> -             icon->paste_command = wstrdup(WMGetFromPLString(value));
> -
> -     WMReleasePropList(clip_state);
> -
> -     return icon;
> -}
> -
>  WDock *wDockRestoreState(WScreen *scr, WMPropList *dock_state, int
>  type)
>  {
>       WDock *dock;
> @@ -1615,55 +1592,13 @@ WDock *wDockRestoreState(WScreen *scr,
> WMPropList *dock_state, int type)
>       WAppIcon *aicon, *old_top;
>       int count, i;
>  
> -     dock = wDockCreate(scr, type);
> +     dock = wDockCreate(scr, dock_state, type);
>  
>       if (!dock_state)
>               return dock;
>  
>       WMRetainPropList(dock_state);
>  
> -     /* restore position */
> -     value = WMGetFromPLDictionary(dock_state, dPosition);
> -     if (value) {
> -             if (!WMIsPLString(value)) {
> -                     COMPLAIN("Position");
> -             } else {
> -                     WMRect rect;
> -                     int flags;
> -
> -                     if (sscanf(WMGetFromPLString(value), "%i,%i", 
> &dock->x_pos,
> &dock->y_pos) != 2)
> -                             COMPLAIN("Position");
> -
> -                     /* check position sanity */
> -                     rect.pos.x = dock->x_pos;
> -                     rect.pos.y = dock->y_pos;
> -                     rect.size.width = rect.size.height = ICON_SIZE;
> -
> -                     wGetRectPlacementInfo(scr, rect, &flags);
> -                     if (flags & (XFLAG_DEAD | XFLAG_PARTIAL)) {
> -                             int x = dock->x_pos;
> -                             wScreenKeepInside(scr, &x, &dock->y_pos, 
> ICON_SIZE, ICON_SIZE);
> -                     }
> -
> -                     /* Is this needed any more? */
> -                     if (type == WM_CLIP) {
> -                             if (dock->x_pos < 0) {
> -                                     dock->x_pos = 0;
> -                             } else if (dock->x_pos > scr->scr_width - 
> ICON_SIZE) {
> -                                     dock->x_pos = scr->scr_width - 
> ICON_SIZE;
> -                             }
> -                     } else {
> -                             if (dock->x_pos >= 0) {
> -                                     dock->x_pos = DOCK_EXTRA_SPACE;
> -                                     dock->on_right_side = 0;
> -                             } else {
> -                                     dock->x_pos = scr->scr_width - 
> DOCK_EXTRA_SPACE - ICON_SIZE;
> -                                     dock->on_right_side = 1;
> -                             }
> -                     }
> -             }
> -     }
> -
>       /* restore lowered/raised state */
>       dock->lowered = 0;
>  
> diff --git a/src/dock.h b/src/dock.h
> index 9ff0a98..fb3ecfc 100644
> --- a/src/dock.h
> +++ b/src/dock.h
> @@ -67,7 +67,7 @@ typedef struct WDock {
>  
>  
>  
> -WDock *wDockCreate(WScreen *scr, int type);
> +WDock *wDockCreate(WScreen *scr, WMPropList *state, int type);
>  WDock *wDockRestoreState(WScreen *scr, WMPropList *dock_state, int
>  type);
>  
>  void wDockDestroy(WDock *dock);
> @@ -97,7 +97,6 @@ int wDockReceiveDNDDrop(WScreen *scr, XEvent
> *event);
>  void wClipIconPaint(WAppIcon *aicon);
>  void wClipSaveState(WScreen *scr);
>  WMPropList *wClipSaveWorkspaceState(WScreen *scr, int workspace);
> -WAppIcon *wClipRestoreState(WScreen *scr, WMPropList *clip_state);
>  
>  void wClipUpdateForWorkspaceChange(WScreen *scr, int workspace);
>  
> diff --git a/src/screen.c b/src/screen.c
> index 6ae613a..601175d 100644
> --- a/src/screen.c
> +++ b/src/screen.c
> @@ -844,13 +844,7 @@ void wScreenRestoreState(WScreen * scr)
>               scr->dock = wDockRestoreState(scr, state, WM_DOCK);
>       }
>  
> -     if (!wPreferences.flags.noclip) {
> -             state = WMGetFromPLDictionary(scr->session_state, dClip);
> -             scr->clip_icon = wClipRestoreState(scr, state);
> -     }
> -
>       wWorkspaceRestoreState(scr);
> -
>       wScreenUpdateUsableArea(scr);
>  }
>  
> diff --git a/src/workspace.c b/src/workspace.c
> index f0a0031..f13d49b 100644
> --- a/src/workspace.c
> +++ b/src/workspace.c
> @@ -103,7 +103,7 @@ int wWorkspaceNew(WScreen *scr, Bool with_clip)
>               }
>  
>               if (!wPreferences.flags.noclip && with_clip)
> -                     wspace->clip = wDockCreate(scr, WM_CLIP);
> +                     wspace->clip = wDockCreate(scr, NULL, WM_CLIP);
>  
>               list = wmalloc(sizeof(WWorkspace *) * scr->workspace_count);
>  
> --
> 1.7.10.4
> 
> 
> --
> To unsubscribe, send mail to
> [email protected].
> 


--
To unsubscribe, send mail to [email protected].

Reply via email to