diff --git a/programs/dtwm/WmFunction.c b/programs/dtwm/WmFunction.c index c7386adb..d6049dd6 100644 --- a/programs/dtwm/WmFunction.c +++ b/programs/dtwm/WmFunction.c @@ -4028,6 +4028,13 @@ Boolean F_McdeApp (String args, ClientData *pCD, XEvent *event) ClientData *list[256]; int n = 0, i; + /* the program switcher of Command+Tab is reached through this function: + * its own key binding is not taken (measured 2026-11-14: F9 as well), so + * the key table names f.mcde_app, which is in it */ + if (args != NULL && strcmp (args, "switcher") == 0) + return (F_McdeSwitcher ("next", pCD, event)); + if (args != NULL && strcmp (args, "switcher-prev") == 0) + return (F_McdeSwitcher ("prev", pCD, event)); if (focus == NULL || args == NULL || !McdeProgramWindow (focus)) return (True); /* the windows first, acted on after: minimizing changes the list */ @@ -4072,6 +4079,164 @@ Boolean F_McdeApp (String args, ClientData *pCD, XEvent *event) +/* ---- MCDE: the program switcher of Command+Tab -------------------------- */ + +#define SW_MAX 24 +#define SW_CELL 140 +#define SW_HEIGHT 70 +#define SW_MARGIN 12 +#define SW_TIMEOUT 5000 + +typedef struct +{ + ClientData *pCD; /* the program's window to raise */ + char name[64]; +} SwProgram; + +static Window swWindow = None; +static GC swGC = None; +static XtIntervalId swTimer = 0; +static SwProgram swList[SW_MAX]; +static int swN = 0; +static int swSel = 0; +static Boolean swActive = False; + +/* the overlay goes away by itself: one timer, a short flash */ +static void +SwHide (XtPointer client, XtIntervalId *id) +{ + (void) client; + (void) id; + swTimer = 0; + swActive = False; + if (swWindow != None) + { + XUnmapWindow (DISPLAY, swWindow); + XFlush (DISPLAY); + } +} + +/* the programs of the screen in the order of the stacking, one entry each: + * the focused program first, so its neighbour is the one used before it */ +static int +SwPrograms (void) +{ + WmScreenData *pSD = ACTIVE_PSD; + ClientListEntry *e; + int n = 0; + + for (e = pSD->clientList; e != NULL && n < SW_MAX; e = e->nextSibling) + { + ClientData *c = e->pCD; + int i; + Boolean have = False; + + if (e->type != NORMAL_STATE || !McdeProgramWindow (c) || + c->clientClass == NULL) + continue; + for (i = 0; i < n; i++) + if (strcmp (swList[i].name, c->clientClass) == 0) + have = True; + if (have) + continue; + swList[n].pCD = c; + (void) snprintf (swList[n].name, sizeof swList[n].name, "%s", + c->clientClass); + n++; + } + return n; +} + +/* the bar of programs in the middle of the screen: names, the chosen one + * boxed (the icons of the reference need the program's icon file; the name + * is what the window manager knows for certain) */ +static void +SwDraw (void) +{ + WmScreenData *pSD = ACTIVE_PSD; + XSetWindowAttributes a; + int width, height, x, y, i, depth; + + width = swN * SW_CELL + 2 * SW_MARGIN; + height = SW_HEIGHT + 2 * SW_MARGIN; + x = (DisplayWidth (DISPLAY, pSD->screen) - width) / 2; + y = (DisplayHeight (DISPLAY, pSD->screen) - height) / 2; + if (x < 0) + x = 0; + if (y < 0) + y = 0; + depth = DefaultDepth (DISPLAY, pSD->screen); + if (swWindow != None) + { + XDestroyWindow (DISPLAY, swWindow); + swWindow = None; + } + if (swGC == None) + swGC = XCreateGC (DISPLAY, pSD->rootWindow, 0, NULL); + memset (&a, 0, sizeof a); + a.override_redirect = True; + a.background_pixel = BlackPixel (DISPLAY, pSD->screen); + a.border_pixel = WhitePixel (DISPLAY, pSD->screen); + swWindow = XCreateWindow (DISPLAY, pSD->rootWindow, x, y, width, height, + 2, depth, InputOutput, DefaultVisual (DISPLAY, pSD->screen), + CWOverrideRedirect | CWBackPixel | CWBorderPixel, &a); + /* the map paints the background over what was drawn before it */ + XMapRaised (DISPLAY, swWindow); + XSync (DISPLAY, False); + XSetForeground (DISPLAY, swGC, WhitePixel (DISPLAY, pSD->screen)); + for (i = 0; i < swN; i++) + { + int cx = SW_MARGIN + i * SW_CELL; + + XDrawString (DISPLAY, swWindow, swGC, cx + 14, SW_MARGIN + 30, + swList[i].name, (int) strlen (swList[i].name)); + if (i == swSel) + XDrawRectangle (DISPLAY, swWindow, swGC, cx + 2, SW_MARGIN - 4, + SW_CELL - 6, SW_HEIGHT); + } + XFlush (DISPLAY); + if (swTimer != 0) + XtRemoveTimeOut (swTimer); + swTimer = XtAppAddTimeOut (wmGD.mwmAppContext, SW_TIMEOUT, SwHide, NULL); +} + +/* + * f.mcde_switcher next|prev: the program after (or before) this one, in the + * order of the stacking. Command+Tab pressed again while the bar is up + * walks on in the same list; every press raises and focuses the program it + * names (the reference waits for Command to be let go; this window manager + * has no keyboard grab for it) and the bar goes away after a moment. + */ +Boolean F_McdeSwitcher (String args, ClientData *pCD, XEvent *event) +{ + ClientData *focus = pCD != NULL ? pCD : wmGD.keyboardFocus; + Boolean prev = args != NULL && strncmp (args, "prev", 4) == 0; + int i, cur = 0; + + if (!swActive) + { + swN = SwPrograms (); + if (swN < 1) + return (True); + if (focus != NULL && focus->clientClass != NULL) + for (i = 0; i < swN; i++) + if (strcmp (swList[i].name, focus->clientClass) == 0) + cur = i; + swSel = (cur + (prev ? swN - 1 : 1)) % swN; + swActive = True; + } + else if (prev) + swSel = (swSel + swN - 1) % swN; + else + swSel = (swSel + 1) % swN; + + Do_Raise (swList[swSel].pCD, (ClientListEntry *) NULL, STACK_NORMAL); + Do_Focus_Key (swList[swSel].pCD, GetTimestamp (), ALWAYS_SET_FOCUS); + SwDraw (); + return (True); +} + + /*************************************<->************************************* * * F_Raise_Lower (args, pCD, event) diff --git a/programs/dtwm/WmFunction.h b/programs/dtwm/WmFunction.h index d77e0b67..35402904 100644 --- a/programs/dtwm/WmFunction.h +++ b/programs/dtwm/WmFunction.h @@ -83,6 +83,7 @@ extern void McdeRaiseAbove (WmScreenData *pSD); extern void McdeSetAbove (ClientData *pCD, Boolean on); extern Boolean F_McdeAbove (String args, ClientData *pCD, XEvent *event); extern Boolean F_McdeApp (String args, ClientData *pCD, XEvent *event); +extern Boolean F_McdeSwitcher (String args, ClientData *pCD, XEvent *event); extern Boolean F_Raise_Lower (String args, ClientData *pCD, XEvent *event); extern Boolean F_Refresh_Win (String args, ClientData *pCD, XEvent *event); extern Boolean F_Set_Behavior (String args, ClientData *pCD, XEvent *event); diff --git a/programs/dtwm/WmResParse.c b/programs/dtwm/WmResParse.c index d2c618dc..5beb5665 100644 --- a/programs/dtwm/WmResParse.c +++ b/programs/dtwm/WmResParse.c @@ -418,6 +418,13 @@ FunctionTableEntry functionTable[] = { 0, F_McdeApp, ParseWmFuncStrArg}, + /* MCDE: the program switcher of Command+Tab (WmFunction.c) */ + {"f.mcde_switcher", F_CONTEXT_ROOT|F_CONTEXT_ICON|F_SUBCONTEXT_IB_IICON| + F_SUBCONTEXT_IB_WICON, + CRS_ANY, + 0, + F_McdeSwitcher, + ParseWmFuncStrArg}, /* MCDE: full screen and the zones of the screen (WmMcdeSnap.c) */ {"f.mcde_fullscreen", F_CONTEXT_ROOT|F_CONTEXT_ICON|F_SUBCONTEXT_IB_IICON| F_SUBCONTEXT_IB_WICON, diff --git a/programs/dtwm/WmResource.c b/programs/dtwm/WmResource.c index cc42812c..14651e25 100644 --- a/programs/dtwm/WmResource.c +++ b/programs/dtwm/WmResource.c @@ -509,8 +509,8 @@ char builtinKeyBindingsName[] = "_MwmKeyBindings_"; AltF6 window f.next_key transient\n\ Alt ShiftF6 window f.prev_key transient\n\ ShiftF10 icon f.post_wmenu\n\ - Mod4Tab root|icon|window f.next_key\n\ - Mod4 ShiftTab root|icon|window f.prev_key\n\ + Mod4Tab root|icon|window f.mcde_app switcher\n\ + Mod4 ShiftTab root|icon|window f.mcde_app switcher-prev\n\ Mod4m window f.minimize\n\ Mod4 Ctrlf window f.mcde_fullscreen\n\ Mod4 CtrlLeft window f.mcde_snap left-half\n\