From: "Rodolfo García Peñas (kix)" <k...@kix.es>

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:

-------------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.
---
 src/dock.c      |  127 ++++++++++++++++++-------------------------------------
 src/dock.h      |    2 +-
 src/screen.c    |   12 +-----
 src/workspace.c |    2 +-
 4 files changed, 46 insertions(+), 97 deletions(-)

diff --git a/src/dock.c b/src/dock.c
index f39a29f..210da01 100644
--- a/src/dock.c
+++ b/src/dock.c
@@ -822,6 +822,7 @@ WAppIcon *mainIconCreate(WScreen *scr, int type, char *name)
        case WM_CLIP:
                if (scr->clip_icon)
                        return scr->clip_icon;
+
                btn = wAppIconCreateForDock(scr, NULL, "Logo", "WMClip", 
TILE_CLIP);
                btn->icon->core->descriptor.handle_expose = clipIconExpose;
                x_pos = 0;
@@ -831,11 +832,13 @@ WAppIcon *mainIconCreate(WScreen *scr, int type, char 
*name)
                btn = wAppIconCreateForDock(scr, NULL, "Logo", "WMDock", 
TILE_NORMAL);
                if (wPreferences.flags.clip_merged_in_dock)
                        btn->icon->core->descriptor.handle_expose = 
clipIconExpose;
+
                x_pos = scr->scr_width - ICON_SIZE - DOCK_EXTRA_SPACE;
                break;
        case WM_DRAWER:
                if (name == NULL)
                        name = findUniqueName(scr, "Drawer");
+
                btn = wAppIconCreateForDock(scr, NULL, name, "WMDrawer", 
TILE_DRAWER);
                btn->icon->core->descriptor.handle_expose = drawerIconExpose;
                x_pos = 0;              
@@ -857,6 +860,9 @@ WAppIcon *mainIconCreate(WScreen *scr, int type, char *name)
                (type == WM_DOCK && wPreferences.flags.clip_merged_in_dock))
                scr->clip_icon = btn;
 
+       /* After the default set, set the final place */
+       set_appicon_position_from_dictionary(btn, type);
+
        return btn;
 }
 
@@ -1352,7 +1358,7 @@ static WMenu *dockMenuCreate(WScreen *scr, int type)
        return menu;
 }
 
-WDock *wDockCreate(WScreen *scr, int type, char *name)
+WDock *wDockCreate(WScreen *scr, WMPropList *state, int type, char *name)
 {
        WDock *dock;
        WAppIcon *btn;
@@ -1376,11 +1382,9 @@ WDock *wDockCreate(WScreen *scr, int type, char *name)
        dock->icon_array = wmalloc(sizeof(WAppIcon *) * dock->max_icons);
 
        btn = mainIconCreate(scr, type, name);
-
        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;
@@ -1388,6 +1392,7 @@ WDock *wDockCreate(WScreen *scr, int type, char *name)
                dock->on_right_side = scr->dock->on_right_side;
        else
                dock->on_right_side = 1;
+
        dock->collapsed = 0;
        dock->auto_collapse = 0;
        dock->auto_collapse_magic = NULL;
@@ -1397,6 +1402,34 @@ WDock *wDockCreate(WScreen *scr, int type, char *name)
        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 (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;
+                       }
+               }
+       }
+
        wRaiseFrame(btn->icon->core);
        XMoveWindow(dpy, btn->icon->core->window, btn->x_pos, btn->y_pos);
 
@@ -1834,49 +1867,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, NULL);
-
-       if (!clip_state)
-               return icon;
-
-       WMRetainPropList(clip_state);
-
-       /* restore position */
-
-       value = WMGetFromPLDictionary(clip_state, dPosition);
-
-       if (value) {
-               if (!WMIsPLString(value)) {
-                       COMPLAIN("Position");
-               } else {
-                       if (sscanf(WMGetFromPLString(value), "%i,%i", 
&icon->x_pos, &icon->y_pos) != 2)
-                               COMPLAIN("Position");
-
-                       /* check position sanity */
-                       if (!onScreen(scr, icon->x_pos, icon->y_pos))
-                               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;
@@ -1885,47 +1875,13 @@ WDock *wDockRestoreState(WScreen *scr, WMPropList 
*dock_state, int type)
        WAppIcon *aicon, *old_top;
        int count, i;
 
-       dock = wDockCreate(scr, type, NULL);
+       dock = wDockCreate(scr, dock_state, type, NULL);
 
        if (!dock_state)
                return dock;
 
        WMRetainPropList(dock_state);
 
-       /* restore position */
-       value = WMGetFromPLDictionary(dock_state, dPosition);
-       if (value) {
-               if (!WMIsPLString(value)) {
-                       COMPLAIN("Position");
-               } else {
-                       if (sscanf(WMGetFromPLString(value), "%i,%i", 
&dock->x_pos, &dock->y_pos) != 2)
-                               COMPLAIN("Position");
-
-                       /* check position sanity */
-                       if (!onScreen(scr, dock->x_pos, dock->y_pos)) {
-                               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;
 
@@ -4456,7 +4412,7 @@ static int addADrawer(WScreen *scr)
                 * ICON_SIZE multiple, as some space is lost above and under it 
*/
                return -1;
 
-       drawer = wDockCreate(scr, WM_DRAWER, NULL);
+       drawer = wDockCreate(scr, NULL, WM_DRAWER, NULL);
        drawer->lowered = scr->dock->lowered;
        drawer->auto_raise_lower = scr->dock->auto_raise_lower;
        drawer->x_pos = dock->x_pos;
@@ -4814,7 +4770,7 @@ static void drawerConsolidateIcons(WDock *drawer)
 
 
 /* similar to wDockRestoreState, but a lot a specific stuff too... */
-static WDock * drawerRestoreState(WScreen *scr, WMPropList *drawer_state)
+static WDock *drawerRestoreState(WScreen *scr, WMPropList *drawer_state)
 {
        WDock *drawer;
        WMPropList *apps, *value, *dock_state;
@@ -4830,7 +4786,7 @@ static WDock * drawerRestoreState(WScreen *scr, 
WMPropList *drawer_state)
 
        /* Get the instance name, and create a drawer */
        value = WMGetFromPLDictionary(drawer_state, dName);
-       drawer = wDockCreate(scr, WM_DRAWER, WMGetFromPLString(value));
+       drawer = wDockCreate(scr, NULL, WM_DRAWER, WMGetFromPLString(value));
 
        /* restore DnD command and paste command */
 #ifdef XDND
@@ -4876,6 +4832,7 @@ static WDock * drawerRestoreState(WScreen *scr, 
WMPropList *drawer_state)
                ChangeStackingLevel(drawer->icon_array[0]->icon->core, 
WMDockLevel);
        else
                ChangeStackingLevel(drawer->icon_array[0]->icon->core, 
WMNormalLevel);
+
        wRaiseFrame(drawer->icon_array[0]->icon->core);
 
        /* restore collapsed state */
diff --git a/src/dock.h b/src/dock.h
index bac7ab3..4e0bf3e 100644
--- a/src/dock.h
+++ b/src/dock.h
@@ -67,7 +67,7 @@ typedef struct WDock {
 
 
 
-WDock *wDockCreate(WScreen *scr, int type, char *name);
+WDock *wDockCreate(WScreen *scr, WMPropList *state, int type, char *name);
 WDock *wDockRestoreState(WScreen *scr, WMPropList *dock_state, int type);
 
 void wDockDestroy(WDock *dock);
diff --git a/src/screen.c b/src/screen.c
index 4b40537..f996736 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -837,9 +837,8 @@ void wScreenRestoreState(WScreen * scr)
                wfree(path);
        }
 
-       if (!scr->session_state) {
+       if (!scr->session_state)
                scr->session_state = WMCreatePLDictionary(NULL, NULL);
-       }
 
        if (!wPreferences.flags.nodock) {
                state = WMGetFromPLDictionary(scr->session_state, dDock);
@@ -848,17 +847,10 @@ void wScreenRestoreState(WScreen * scr)
                 * wDockRestoreState()->wDockCreate()->mainIconCreate() */
        }
 
-       if (!wPreferences.flags.noclip) {
-               state = WMGetFromPLDictionary(scr->session_state, dClip);
-               scr->clip_icon = wClipRestoreState(scr, state);
-       }
-       
-       if (!wPreferences.flags.nodrawer) {
+       if (!wPreferences.flags.nodrawer)
                wDrawersRestoreState(scr);
-       }
 
        wWorkspaceRestoreState(scr);
-
        wScreenUpdateUsableArea(scr);
 }
 
diff --git a/src/workspace.c b/src/workspace.c
index b0d6891..e48bc66 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, NULL);
+                       wspace->clip = wDockCreate(scr, NULL, WM_CLIP, NULL);
 
                list = wmalloc(sizeof(WWorkspace *) * scr->workspace_count);
 
-- 
1.7.10.4


-- 
To unsubscribe, send mail to wmaker-dev-unsubscr...@lists.windowmaker.org.

Reply via email to