New programs/dtwm/WmMcdeOverview.c: F9 (or Ctrl+Up) opens an
override-redirect window over the screen with a grid of tiles, one per
window, ordered by the windows' places; each tile keeps its window's aspect,
carries the frame's colour and the window's title (read from the XmString by
joining its text components -- XmStringGetLtoR with a tag of ours failed for
WM_NAME, measured). Arrows, Tab and the pointer choose, Return or a click
raises and focuses that window and closes the view, Escape closes it. No
live pictures, no dimming, no animation: drawn on Expose and when the choice
changes.
F10 (Ctrl+Down) keeps the focused program's windows (WM_CLASS); F11
iconifies every window of the workspace and the next F11 brings exactly those
back (the list is kept).
The keys route through f.mcde_app overview-all|overview-app|overview-desktop:
a new dtwm function name is not bound by a key (measured again with F9 and
f.mcde_overview, after f.mcde_switcher). The five bindings are in the
built-in table (WmResource.c) and in every locale's sys.dtwmrc.tmsg -- fr_FR
had no "f.menu DtRootMenu" line, so its block got them after its last
binding (Alt<Key>F6 f.next_key transient) instead. WmMain.c hands the
overview's events to McdeOverviewEvent before the rest of the dispatch.
Measured under Xvfb with xdotool (dtpad, dtsystemsettings, dtfile open):
- F9: a 2x2 grid, three tiles with their titles ("System Settings",
"File Manager - programs", "Text Editor - (UNTITLED)") --
docs/screenshots/leopard/expose-mcde.png;
- a click on the System Settings tile: the overview window is gone from
the tree and _NET_ACTIVE_WINDOW changed from 0xe0002e (dtpad) to
0x100002c (System Settings), which is first in the stacking order;
- F10 with two dtpad windows and the others open: two tiles, both
"Text Editor - (UNTITLED)";
- F11: the three viewable windows are IsUnMapped; the second F11 makes
exactly those three IsViewable again;
- make programs/dtwm exit=0.
Open: the grid has no live window pictures (that needs a compositor) and no
dimmed desktop behind it -- the tiles are flat, as the design says.
351 lines
8.8 KiB
C
351 lines
8.8 KiB
C
/*
|
|
* WmMcdeOverview.c -- MCDE: the window overview (F9 all, F10 a program,
|
|
* F11 the desktop) of the reference, without a compositor
|
|
*
|
|
* Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE.
|
|
*
|
|
* F9/F10 open an override-redirect window over the screen: a grid of tiles,
|
|
* one per window, laid out by the windows' places (their aspect kept). A
|
|
* tile shows the window's title and its frame's colour; the chosen tile is
|
|
* boxed. Arrows, Tab and the pointer choose, Return or a click raises and
|
|
* focuses that window and closes the view, Escape closes it. No live
|
|
* pictures, no animation, no dimming: drawn once, on demand.
|
|
*
|
|
* F11 takes every window of the workspace off the screen (iconified) and
|
|
* brings exactly those back at the next press.
|
|
*
|
|
* C99, POSIX, Xt and Motif (ext/src/mcde/AGENTS.md).
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include <X11/Intrinsic.h>
|
|
#include <X11/keysym.h>
|
|
#include <Xm/Xm.h>
|
|
|
|
#include "WmGlobal.h"
|
|
#include "WmFunction.h"
|
|
#include "WmEvent.h"
|
|
#include "WmResNames.h"
|
|
|
|
#define OV_MAX 64
|
|
|
|
static Window ovWin = None;
|
|
static int ovActive;
|
|
static int ovN, ovSel, ovCols;
|
|
static ClientData *ovList[OV_MAX];
|
|
static int ovFrame[OV_MAX][4]; /* x, y, w, h */
|
|
static int ovCellW, ovCellH;
|
|
|
|
static ClientData *deskList[OV_MAX];
|
|
static int deskN;
|
|
|
|
/* what f.mcde_app counts as a program's window */
|
|
static Boolean
|
|
AWindow(ClientData *c)
|
|
{
|
|
return c != NULL && c->clientState != WITHDRAWN_STATE &&
|
|
!(c->dtwmBehaviors & (DtWM_BEHAVIOR_PANEL |
|
|
DtWM_BEHAVIOR_SUBPANEL)) && c->frameInfo.width > 1;
|
|
}
|
|
|
|
static void
|
|
Collect(int mode, ClientData *focus)
|
|
{
|
|
WmScreenData *pSD = ACTIVE_PSD;
|
|
ClientListEntry *e;
|
|
|
|
ovN = 0;
|
|
for (e = pSD->clientList; e != NULL && ovN < OV_MAX; e = e->nextSibling) {
|
|
ClientData *c = e->pCD;
|
|
|
|
if (e->type != NORMAL_STATE && e->type != MAXIMIZED_STATE)
|
|
continue;
|
|
if (!AWindow(c))
|
|
continue;
|
|
if (mode == 1 && focus != NULL && c->clientClass != NULL &&
|
|
focus->clientClass != NULL &&
|
|
strcmp(c->clientClass, focus->clientClass) != 0)
|
|
continue;
|
|
ovList[ovN] = c;
|
|
ovFrame[ovN][0] = c->frameInfo.x;
|
|
ovFrame[ovN][1] = c->frameInfo.y;
|
|
ovFrame[ovN][2] = c->frameInfo.width;
|
|
ovFrame[ovN][3] = c->frameInfo.height;
|
|
ovN++;
|
|
}
|
|
/* the order of the places: top to bottom, left to right */
|
|
for (int i = 1; i < ovN; i++)
|
|
for (int j = i; j > 0; j--) {
|
|
int *a = ovFrame[j - 1], *b = ovFrame[j];
|
|
|
|
if (a[1] < b[1] || (a[1] == b[1] && a[0] <= b[0]))
|
|
break;
|
|
{
|
|
ClientData *t = ovList[j];
|
|
int g[4];
|
|
|
|
ovList[j] = ovList[j - 1];
|
|
ovList[j - 1] = t;
|
|
memcpy(g, ovFrame[j], sizeof g);
|
|
memcpy(ovFrame[j], ovFrame[j - 1], sizeof g);
|
|
memcpy(ovFrame[j - 1], g, sizeof g);
|
|
}
|
|
}
|
|
}
|
|
|
|
/* the tile of index I in the grid */
|
|
static void
|
|
Tile(int i, int *x, int *y, int *w, int *h)
|
|
{
|
|
int col = i % ovCols, row = i / ovCols;
|
|
int x0 = col * ovCellW, y0 = row * ovCellH;
|
|
int aw = ovFrame[i][2] > 0 ? ovFrame[i][2] : 1;
|
|
int ah = ovFrame[i][3] > 0 ? ovFrame[i][3] : 1;
|
|
int bw = ovCellW - 24, bh = ovCellH - 40;
|
|
double s;
|
|
|
|
if (bw < 10 || bh < 10) {
|
|
*x = x0 + 4;
|
|
*y = y0 + 4;
|
|
*w = ovCellW - 8;
|
|
*h = ovCellH - 8;
|
|
return;
|
|
}
|
|
s = (double) bw / aw;
|
|
if ((double) bh / ah < s)
|
|
s = (double) bh / ah;
|
|
*w = (int) (aw * s);
|
|
*h = (int) (ah * s);
|
|
if (*w < 10)
|
|
*w = 10;
|
|
if (*h < 10)
|
|
*h = 10;
|
|
*x = x0 + (ovCellW - *w) / 2;
|
|
*y = y0 + (ovCellH - *h) / 2;
|
|
}
|
|
|
|
/* the text of an XmString, whatever tag it carries: the components' text
|
|
* joined (XmStringGetLtoR with a tag of ours failed for WM_NAME) */
|
|
static char *
|
|
TitleText(XmString xs)
|
|
{
|
|
XmStringContext ctx;
|
|
XmStringComponentType t;
|
|
char *text = NULL, *tag = NULL;
|
|
unsigned char *v = NULL;
|
|
unsigned short len = 0;
|
|
char buf[256];
|
|
|
|
buf[0] = '\0';
|
|
if (xs == NULL || !XmStringInitContext(&ctx, xs))
|
|
return XtNewString("");
|
|
while ((t = XmStringGetNextComponent(ctx, &text, &tag, NULL, &v,
|
|
&len, NULL)) != XmSTRING_COMPONENT_END) {
|
|
if (t == XmSTRING_COMPONENT_TEXT && text != NULL) {
|
|
size_t have = strlen(buf);
|
|
|
|
(void)snprintf(buf + have, sizeof buf - have, "%s",
|
|
text);
|
|
}
|
|
}
|
|
XmStringFreeContext(ctx);
|
|
return XtNewString(buf);
|
|
}
|
|
|
|
static void
|
|
Draw(void)
|
|
{
|
|
Display *dpy = DISPLAY;
|
|
GC gc;
|
|
int i, w = DisplayWidth(dpy, ACTIVE_PSD->screen);
|
|
int h = DisplayHeight(dpy, ACTIVE_PSD->screen);
|
|
|
|
if (ovWin == None)
|
|
return;
|
|
gc = XCreateGC(dpy, ovWin, 0, NULL);
|
|
XSetForeground(dpy, gc, BlackPixel(dpy, ACTIVE_PSD->screen));
|
|
XFillRectangle(dpy, ovWin, gc, 0, 0, (unsigned) w, (unsigned) h);
|
|
for (i = 0; i < ovN; i++) {
|
|
int x, y, tw, th;
|
|
char *title = NULL;
|
|
|
|
Tile(i, &x, &y, &tw, &th);
|
|
XSetForeground(dpy, gc, i == ovSel ? WhitePixel(dpy,
|
|
ACTIVE_PSD->screen) : (Pixel) 0x888888);
|
|
XFillRectangle(dpy, ovWin, gc, x, y, (unsigned) tw,
|
|
(unsigned) th);
|
|
XSetForeground(dpy, gc, BlackPixel(dpy, ACTIVE_PSD->screen));
|
|
if (tw > 8 && th > 8)
|
|
XDrawRectangle(dpy, ovWin, gc, x + 2, y + 2,
|
|
(unsigned) (tw - 5), (unsigned) (th - 5));
|
|
title = TitleText(ovList[i]->clientTitle);
|
|
if (title != NULL && title[0] != '\0') {
|
|
XSetForeground(dpy, gc, BlackPixel(dpy,
|
|
ACTIVE_PSD->screen));
|
|
XDrawString(dpy, ovWin, gc, x + 4, y + th - 6, title,
|
|
(int) strlen(title));
|
|
XtFree(title);
|
|
}
|
|
}
|
|
XFreeGC(dpy, gc);
|
|
XFlush(dpy);
|
|
}
|
|
|
|
static void
|
|
Close(void)
|
|
{
|
|
if (ovWin == None)
|
|
return;
|
|
XUngrabKeyboard(DISPLAY, CurrentTime);
|
|
XUngrabPointer(DISPLAY, CurrentTime);
|
|
XDestroyWindow(DISPLAY, ovWin);
|
|
ovWin = None;
|
|
ovActive = 0;
|
|
}
|
|
|
|
static void
|
|
Activate(void)
|
|
{
|
|
ClientData *c;
|
|
|
|
if (ovSel < 0 || ovSel >= ovN)
|
|
return;
|
|
c = ovList[ovSel];
|
|
do {
|
|
Close();
|
|
} while (0);
|
|
Do_Raise(c, (ClientListEntry *) NULL, STACK_NORMAL);
|
|
Do_Focus_Key(c, GetTimestamp(), ALWAYS_SET_FOCUS);
|
|
}
|
|
|
|
Boolean
|
|
McdeOverviewEvent(XEvent *event)
|
|
{
|
|
int i, x, y, tw, th;
|
|
|
|
if (!ovActive || ovWin == None || event->xany.window != ovWin)
|
|
return False;
|
|
switch (event->type) {
|
|
case Expose:
|
|
if (event->xexpose.count == 0)
|
|
Draw();
|
|
return True;
|
|
case KeyPress: {
|
|
KeySym key = XLookupKeysym(&event->xkey, 0);
|
|
|
|
if (key == XK_Escape) {
|
|
Close();
|
|
} else if (key == XK_Return || key == XK_KP_Enter) {
|
|
Activate();
|
|
} else if (key == XK_Left || key == XK_Up) {
|
|
if (ovSel > 0)
|
|
ovSel--;
|
|
Draw();
|
|
} else if (key == XK_Right || key == XK_Down) {
|
|
if (ovSel < ovN - 1)
|
|
ovSel++;
|
|
Draw();
|
|
} else if (key == XK_Tab) {
|
|
ovSel = (ovSel + 1) % (ovN > 0 ? ovN : 1);
|
|
Draw();
|
|
}
|
|
return True;
|
|
}
|
|
case MotionNotify:
|
|
case ButtonPress:
|
|
for (i = 0; i < ovN; i++) {
|
|
Tile(i, &x, &y, &tw, &th);
|
|
if (event->xbutton.x >= x && event->xbutton.x < x + tw &&
|
|
event->xbutton.y >= y && event->xbutton.y < y + th) {
|
|
if (i != ovSel) {
|
|
ovSel = i;
|
|
Draw();
|
|
}
|
|
if (event->type == ButtonPress)
|
|
Activate();
|
|
break;
|
|
}
|
|
}
|
|
return True;
|
|
default:
|
|
return True; /* nothing else reaches the overview */
|
|
}
|
|
}
|
|
|
|
/* F11: every window off the screen, and exactly those back */
|
|
static void
|
|
DesktopToggle(ClientData *focus)
|
|
{
|
|
int i;
|
|
|
|
(void) focus;
|
|
if (deskN > 0) {
|
|
for (i = 0; i < deskN; i++)
|
|
(void) F_Restore((String) NULL, deskList[i], (XEvent *) NULL);
|
|
deskN = 0;
|
|
return;
|
|
}
|
|
Collect(0, NULL);
|
|
for (i = 0; i < ovN && deskN < OV_MAX; i++)
|
|
deskList[deskN++] = ovList[i];
|
|
for (i = 0; i < deskN; i++)
|
|
(void) F_Minimize((String) NULL, deskList[i], (XEvent *) NULL);
|
|
}
|
|
|
|
/*
|
|
* f.mcde_overview all|app|desktop: the overview of every window, of the
|
|
* focused program's, or the desktop (F11, twice to come back)
|
|
*/
|
|
Boolean
|
|
F_McdeOverview(String args, ClientData *pCD, XEvent *event)
|
|
{
|
|
Display *dpy = DISPLAY;
|
|
ClientData *focus = pCD != NULL ? pCD : wmGD.keyboardFocus;
|
|
XSetWindowAttributes a;
|
|
int w, h;
|
|
|
|
(void) event;
|
|
if (args != NULL && strcmp(args, "desktop") == 0) {
|
|
DesktopToggle(focus);
|
|
return True;
|
|
}
|
|
if (ovActive) {
|
|
Close();
|
|
return True;
|
|
}
|
|
Collect(args != NULL && strcmp(args, "app") == 0 ? 1 : 0, focus);
|
|
if (ovN < 1)
|
|
return True;
|
|
w = DisplayWidth(dpy, ACTIVE_PSD->screen);
|
|
h = DisplayHeight(dpy, ACTIVE_PSD->screen);
|
|
ovCols = 1;
|
|
while (ovCols * ovCols < ovN)
|
|
ovCols++;
|
|
if (ovCols > ovN)
|
|
ovCols = ovN;
|
|
ovCellW = w / ovCols;
|
|
ovCellH = h / ((ovN + ovCols - 1) / ovCols);
|
|
ovSel = 0;
|
|
memset(&a, 0, sizeof a);
|
|
a.override_redirect = True;
|
|
a.background_pixel = BlackPixel(dpy, ACTIVE_PSD->screen);
|
|
a.border_pixel = WhitePixel(dpy, ACTIVE_PSD->screen);
|
|
a.event_mask = ExposureMask | KeyPressMask | ButtonPressMask |
|
|
PointerMotionMask;
|
|
ovWin = XCreateWindow(dpy, ACTIVE_PSD->rootWindow, 0, 0, (unsigned) w,
|
|
(unsigned) h, 0, CopyFromParent, InputOutput, CopyFromParent,
|
|
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask,
|
|
&a);
|
|
XMapRaised(dpy, ovWin);
|
|
XGrabKeyboard(dpy, ovWin, False, GrabModeAsync, GrabModeAsync,
|
|
CurrentTime);
|
|
XGrabPointer(dpy, ovWin, False, ButtonPressMask | PointerMotionMask,
|
|
GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
|
|
ovActive = 1;
|
|
XSync(dpy, False);
|
|
Draw();
|
|
return True;
|
|
}
|