From 7857f297eae5c487a43d7fb525bf2ed7a8010ad4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20D=C3=A9chelotte?= Date: Wed, 2 Sep 2009 00:05:46 +0200 Subject: [PATCH] Fix for omnipresent AppIcon bug at startup Bug overview: right after start up, omnipresent AppIcons (living in the Clip) are displayed but non-functionnal. How to reproduce it: place two AppIcons in the Clip, make the first one (A) omnipresent and leave the second one (B) as is. Make the Clip "autocollapse". Switch to the second workspace and restart wmaker. Wmaker starts in the first workspace; the Clip is closed (its text color corresponds to the closed state, AppIcon B is not shown). However, AppIcon A is displayed. Moreover, A does not react when the Clip expands or collapses. Finally, a click on A makes it disappear. Fortunately, changing to another workspace fixes the problem definitively. Explanation and correction: internally, wmaker maintains as many clips as workspaces. When the user switches to another workspace, the omnipresent AppIcons are moved to the new "current" clip. In the situation above (trying to reproduce the bug), when wmaker restarts, the omnipresent AppIcons are restored in the second workspace, whereas the first workspace is active. In the previous code, a "hack" (calling XMapWindow()) unconditionally displayed the omnipresent AppIcons. The proposed patch makes sure the omnipresent AppIcons are moved to the first workspace on wmaker startup. --- src/workspace.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/workspace.c b/src/workspace.c index 6bac7bdc..2114ff4a 100644 --- a/src/workspace.c +++ b/src/workspace.c @@ -1387,6 +1387,7 @@ void wWorkspaceRestoreState(WScreen * scr) wfree(scr->workspaces[i]->name); scr->workspaces[i]->name = wstrdup(WMGetFromPLString(pstr)); if (!wPreferences.flags.noclip) { + int added_omnipresent_icons = 0; clip_state = WMGetFromPLDictionary(wks_state, dClip); if (scr->workspaces[i]->clip) wDockDestroy(scr->workspaces[i]->clip); @@ -1401,13 +1402,32 @@ void wWorkspaceRestoreState(WScreen * scr) */ for (j = 0; j < scr->workspaces[i]->clip->max_icons; j++) { WAppIcon *aicon = scr->workspaces[i]->clip->icon_array[j]; - - if (aicon && aicon->omnipresent) { - aicon->omnipresent = 0; - wClipMakeIconOmnipresent(aicon, True); - XMapWindow(dpy, aicon->icon->core->window); - } + int k; + + if (!aicon || !aicon->omnipresent) + continue; + aicon->omnipresent = 0; + if (wClipMakeIconOmnipresent(aicon, True) != WO_SUCCESS) + continue; + if (i == 0) + continue; + + /* Move this appicon from workspace i to workspace 0 */ + scr->workspaces[i]->clip->icon_array[j] = NULL; + scr->workspaces[i]->clip->icon_count--; + + added_omnipresent_icons++; + /* If there are too many omnipresent appicons, we are in trouble */ + assert(scr->workspaces[0]->clip->icon_count + added_omnipresent_icons + <= scr->workspaces[0]->clip->max_icons); + /* Find first free spot on workspace 0 */ + for (k = 0; k < scr->workspaces[0]->clip->max_icons; k++) + if (scr->workspaces[0]->clip->icon_array[k] == NULL) + break; + scr->workspaces[0]->clip->icon_array[k] = aicon; + aicon->dock = scr->workspaces[0]->clip; } + scr->workspaces[0]->clip->icon_count += added_omnipresent_icons; } WMPostNotificationName(WMNWorkspaceNameChanged, scr, (void *)(uintptr_t) i); -- 2.11.4.GIT