MEASURED 2026-11-15 on Xvfb with plain XTest keys: a session loads Dtwm*keyBindings: DtKeyBindings, and that block of sys.dtwmrc had no Mod4 line; the 25 Command/Ctrl+Left/Right/Eject/screenshot lines stood only in DefaultKeyBindings (and in the Sun-keyboard variant), so XGrabKey of Mod4+h from a second client succeeded (nothing grabbed) and the keys did nothing. The 25 lines are copied into message 11 of all 11 sys.dtwmrc.tmsg. SEEN after (C locale): Ctrl+Right goes to workspace Two; Command+Ctrl+Left makes the focused File Manager the left half, Command+Ctrl+BackSpace gives it back, Command+H minimizes it to an icon. Not run: the other ten locales (only C is built on this host); they got their own lines of DefaultKeyBindings, placed after the F9-F11 lines of their message 11 like the lines that stand there. With the front panel focused, Command+Ctrl+Left made it half the screen: f.mcde_snap and f.mcde_fullscreen now ignore panel windows (seen: unchanged). tools/mcde-xkey.sh presses keys by plain keycodes (XTest): xdotool 3.20160805 sends Alt_L first and the F-key with Alt held on this keymap, which made every plain F-key binding look dead (the F9 of t0216). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
322 lines
8.5 KiB
C
322 lines
8.5 KiB
C
/*
|
|
* WmMcdeSnap.c -- MCDE: windows snap to zones of the screen; full screen
|
|
*
|
|
* License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
|
|
*
|
|
* Every monitor (Xinerama head, else the screen) below the top bar is a grid
|
|
* of three columns and two rows (Konrad, 2026-11-11: "3 zonen oben und 3
|
|
* zonen untere haelfte ... welche auch kombiniert werden koennen"). While a
|
|
* window is dragged (HandleClientFrameMove, WmWinConf.c):
|
|
*
|
|
* top edge the upper zone of the column under the pointer
|
|
* bottom edge the lower zone of that column
|
|
* left/right edge the middle third: that half of the monitor;
|
|
* above or below it: the upper or lower outer zone
|
|
*
|
|
* Sliding along the edges from one zone to the next joins them (top left,
|
|
* then top middle: two thirds of the upper row; top left, then down the left
|
|
* edge: the left column). The target is drawn as dtwm's XOR outline (no
|
|
* transparency, nothing for the graphics card to blend); on release the
|
|
* window takes it and its size before is kept, so that dragging it off again
|
|
* gives it back. f.mcde_snap NAME does the same from the keyboard, and
|
|
* f.mcde_fullscreen toggles _NET_WM_STATE_FULLSCREEN (WmEwmh.c).
|
|
*/
|
|
|
|
#include "WmGlobal.h"
|
|
#include "WmCDInfo.h"
|
|
#include "WmEvent.h"
|
|
#include "WmFunction.h"
|
|
#include "WmMultiHead.h"
|
|
#include "WmWinConf.h"
|
|
#include "WmWinState.h"
|
|
#include "WmMcdeSnap.h"
|
|
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#define EDGE 2 /* pixels from a monitor's edge that count as at it */
|
|
|
|
/* the zone grid in columns 0..2 and rows 0..1, or a half */
|
|
typedef struct {
|
|
int c0, c1, r0, r1; /* inclusive; c0 < 0: nothing */
|
|
int half; /* -1 left half, 1 right half, 0 a grid span */
|
|
} Zone;
|
|
|
|
static Zone anchor = { -1, -1, -1, -1, 0 };
|
|
static Zone current = { -1, -1, -1, -1, 0 };
|
|
static Boolean shown;
|
|
static int shownX, shownY;
|
|
static unsigned int shownW, shownH;
|
|
|
|
/* the monitor around (px, py), below the top bar */
|
|
static void
|
|
Monitor(ClientData *pcd, int px, int py, int *x, int *y, int *w, int *h)
|
|
{
|
|
WmHeadInfo_t *hi;
|
|
int id;
|
|
|
|
*x = 0;
|
|
*y = 0;
|
|
*w = DisplayWidth(DISPLAY, SCREEN_FOR_CLIENT(pcd));
|
|
*h = DisplayHeight(DISPLAY, SCREEN_FOR_CLIENT(pcd));
|
|
for (id = 0; (hi = GetHeadInfoById(id)) != NULL; id++) {
|
|
if (px >= hi->x_org && py >= hi->y_org &&
|
|
px < hi->x_org + (int) hi->width &&
|
|
py < hi->y_org + (int) hi->height) {
|
|
*x = hi->x_org;
|
|
*y = hi->y_org;
|
|
*w = (int) hi->width;
|
|
*h = (int) hi->height;
|
|
free(hi);
|
|
break;
|
|
}
|
|
free(hi);
|
|
}
|
|
McdeExcludeBar(SCREEN_FOR_CLIENT(pcd), x, y, w, h);
|
|
}
|
|
|
|
/* the zone the pointer is at, from the monitor's edges */
|
|
static Boolean
|
|
ZoneAt(int px, int py, int mx, int my, int mw, int mh, Zone *z)
|
|
{
|
|
int col = (px - mx) * 3 / mw, row = (py - my) * 2 / mh;
|
|
|
|
if (col < 0)
|
|
col = 0;
|
|
if (col > 2)
|
|
col = 2;
|
|
if (row < 0)
|
|
row = 0;
|
|
if (row > 1)
|
|
row = 1;
|
|
z->half = 0;
|
|
/* the top edge is the bar's lower border or the screen's */
|
|
if (py <= my + EDGE) {
|
|
z->c0 = z->c1 = col;
|
|
z->r0 = z->r1 = 0;
|
|
return True;
|
|
}
|
|
if (py >= my + mh - 1 - EDGE) {
|
|
z->c0 = z->c1 = col;
|
|
z->r0 = z->r1 = 1;
|
|
return True;
|
|
}
|
|
if (px <= mx + EDGE || px >= mx + mw - 1 - EDGE) {
|
|
int side = px <= mx + EDGE ? 0 : 2;
|
|
|
|
if (py > my + mh / 3 && py < my + 2 * mh / 3) {
|
|
z->half = side == 0 ? -1 : 1;
|
|
z->c0 = z->c1 = side;
|
|
z->r0 = 0;
|
|
z->r1 = 1;
|
|
} else {
|
|
z->c0 = z->c1 = side;
|
|
z->r0 = z->r1 = row;
|
|
}
|
|
return True;
|
|
}
|
|
return False;
|
|
}
|
|
|
|
/* the frame rectangle of a zone */
|
|
static void
|
|
ZoneRect(const Zone *z, int mx, int my, int mw, int mh,
|
|
int *x, int *y, unsigned int *w, unsigned int *h)
|
|
{
|
|
int x0, x1, y0, y1;
|
|
|
|
if (z->half != 0) {
|
|
x0 = z->half < 0 ? mx : mx + mw / 2;
|
|
x1 = z->half < 0 ? mx + mw / 2 : mx + mw;
|
|
y0 = my;
|
|
y1 = my + mh;
|
|
} else {
|
|
x0 = mx + z->c0 * mw / 3;
|
|
x1 = mx + (z->c1 + 1) * mw / 3;
|
|
y0 = my + z->r0 * mh / 2;
|
|
y1 = my + (z->r1 + 1) * mh / 2;
|
|
}
|
|
*x = x0;
|
|
*y = y0;
|
|
*w = (unsigned int) (x1 - x0);
|
|
*h = (unsigned int) (y1 - y0);
|
|
}
|
|
|
|
/* the target's outline: XOR while dtwm holds the server (freezeOnConfig,
|
|
* CDE's default), else four thin windows -- never FlashOutline, which
|
|
* redraws in a loop while the pointer rests at the edge */
|
|
static void
|
|
Outline(int x, int y, unsigned int w, unsigned int h)
|
|
{
|
|
if (wmGD.freezeOnConfig)
|
|
MoveOutline(x, y, w, h);
|
|
else
|
|
WindowOutline(x, y, w, h);
|
|
}
|
|
|
|
static void
|
|
HideTarget(void)
|
|
{
|
|
if (shown)
|
|
Outline(0, 0, 0, 0);
|
|
shown = False;
|
|
}
|
|
|
|
/* is a zone shown (the window's own outline is not drawn then) */
|
|
Boolean
|
|
McdeSnapActive(void)
|
|
{
|
|
return shown;
|
|
}
|
|
|
|
/* the pointer moved while PCD is dragged: show the zone it would take */
|
|
void
|
|
McdeSnapMotion(ClientData *pcd, int px, int py)
|
|
{
|
|
int mx, my, mw, mh, x, y;
|
|
unsigned int w, h;
|
|
Zone z;
|
|
|
|
Monitor(pcd, px, py, &mx, &my, &mw, &mh);
|
|
if (!ZoneAt(px, py, mx, my, mw, mh, &z)) {
|
|
anchor.c0 = current.c0 = -1;
|
|
HideTarget();
|
|
return;
|
|
}
|
|
if (z.half != 0 || anchor.c0 < 0 || anchor.half != 0) {
|
|
anchor = z;
|
|
current = z;
|
|
} else {
|
|
/* along the edges: the zones from the first to this one */
|
|
current.half = 0;
|
|
current.c0 = anchor.c0 < z.c0 ? anchor.c0 : z.c0;
|
|
current.c1 = anchor.c1 > z.c1 ? anchor.c1 : z.c1;
|
|
current.r0 = anchor.r0 < z.r0 ? anchor.r0 : z.r0;
|
|
current.r1 = anchor.r1 > z.r1 ? anchor.r1 : z.r1;
|
|
}
|
|
ZoneRect(¤t, mx, my, mw, mh, &x, &y, &w, &h);
|
|
if (!shown || x != shownX || y != shownY || w != shownW ||
|
|
h != shownH) {
|
|
Outline(x, y, w, h);
|
|
shown = True;
|
|
shownX = x;
|
|
shownY = y;
|
|
shownW = w;
|
|
shownH = h;
|
|
}
|
|
}
|
|
|
|
/* PCD's frame to the rectangle (frame coordinates), its size before kept */
|
|
static void
|
|
Place(ClientData *pcd, int x, int y, unsigned int w, unsigned int h)
|
|
{
|
|
int dx = 0, dy = 0;
|
|
|
|
if (!pcd->mcdeSnapped) {
|
|
pcd->mcdeSnapped = True;
|
|
pcd->mcdeSnapWidth = pcd->clientWidth;
|
|
pcd->mcdeSnapHeight = pcd->clientHeight;
|
|
}
|
|
if (pcd->clientState == MAXIMIZED_STATE)
|
|
SetClientState(pcd, NORMAL_STATE, GetTimestamp());
|
|
/* the size is the client's, the position the frame's (as
|
|
* CompleteFrameConfig hands them over) */
|
|
FrameToClient(pcd, &dx, &dy, &w, &h);
|
|
ProcessNewConfiguration(pcd, x, y, w, h, False);
|
|
}
|
|
|
|
/* the drag ended; True if a zone took the window */
|
|
Boolean
|
|
McdeSnapRelease(ClientData *pcd)
|
|
{
|
|
int mx, my, mw, mh, x, y;
|
|
unsigned int w, h;
|
|
Boolean snapped = shown && current.c0 >= 0;
|
|
|
|
HideTarget();
|
|
if (snapped) {
|
|
Monitor(pcd, shownX + 1, shownY + 1, &mx, &my, &mw, &mh);
|
|
ZoneRect(¤t, mx, my, mw, mh, &x, &y, &w, &h);
|
|
Place(pcd, x, y, w, h);
|
|
}
|
|
anchor.c0 = current.c0 = -1;
|
|
return snapped;
|
|
}
|
|
|
|
/* a snapped window was dropped elsewhere: its size from before */
|
|
void
|
|
McdeSnapUnsnap(ClientData *pcd)
|
|
{
|
|
if (!pcd->mcdeSnapped)
|
|
return;
|
|
pcd->mcdeSnapped = False;
|
|
ProcessNewConfiguration(pcd, pcd->clientX - pcd->clientOffset.x,
|
|
pcd->clientY - pcd->clientOffset.y,
|
|
(unsigned int) pcd->mcdeSnapWidth,
|
|
(unsigned int) pcd->mcdeSnapHeight, False);
|
|
}
|
|
|
|
/* the front panel and its sub-panels are not windows to place: with the panel
|
|
* focused, Command+Ctrl+Left made it half the screen (2026-11-15, measured) */
|
|
static Boolean
|
|
IsPanel(ClientData *pcd)
|
|
{
|
|
return (pcd->dtwmBehaviors &
|
|
(DtWM_BEHAVIOR_PANEL | DtWM_BEHAVIOR_SUBPANEL)) != 0;
|
|
}
|
|
|
|
/* f.mcde_snap NAME: the zone from the keyboard (the monitor of the window) */
|
|
Boolean
|
|
F_McdeSnap(String args, ClientData *pcd, XEvent *event)
|
|
{
|
|
static const struct {
|
|
const char *name;
|
|
Zone z;
|
|
} names[] = {
|
|
{ "left-half", { 0, 0, 0, 1, -1 } },
|
|
{ "right-half", { 2, 2, 0, 1, 1 } },
|
|
{ "top", { 0, 2, 0, 0, 0 } },
|
|
{ "bottom", { 0, 2, 1, 1, 0 } },
|
|
{ "top-left", { 0, 0, 0, 0, 0 } },
|
|
{ "top-middle", { 1, 1, 0, 0, 0 } },
|
|
{ "top-right", { 2, 2, 0, 0, 0 } },
|
|
{ "bottom-left", { 0, 0, 1, 1, 0 } },
|
|
{ "bottom-middle", { 1, 1, 1, 1, 0 } },
|
|
{ "bottom-right", { 2, 2, 1, 1, 0 } },
|
|
{ "left", { 0, 0, 0, 1, 0 } },
|
|
{ "middle", { 1, 1, 0, 1, 0 } },
|
|
{ "right", { 2, 2, 0, 1, 0 } },
|
|
};
|
|
int mx, my, mw, mh, x, y;
|
|
unsigned int w, h;
|
|
size_t i;
|
|
|
|
(void) event;
|
|
if (pcd == NULL || args == NULL || IsPanel(pcd))
|
|
return True;
|
|
if (strcmp(args, "restore") == 0) {
|
|
McdeSnapUnsnap(pcd);
|
|
return True;
|
|
}
|
|
for (i = 0; i < sizeof names / sizeof names[0]; i++)
|
|
if (strcmp(args, names[i].name) == 0)
|
|
break;
|
|
if (i == sizeof names / sizeof names[0])
|
|
return True;
|
|
Monitor(pcd, pcd->clientX + 1, pcd->clientY + 1, &mx, &my, &mw, &mh);
|
|
ZoneRect(&names[i].z, mx, my, mw, mh, &x, &y, &w, &h);
|
|
Place(pcd, x, y, w, h);
|
|
return True;
|
|
}
|
|
|
|
/* f.mcde_fullscreen: the window over everything, the bar and panel too */
|
|
Boolean
|
|
F_McdeFullscreen(String args, ClientData *pcd, XEvent *event)
|
|
{
|
|
(void) args;
|
|
(void) event;
|
|
if (pcd != NULL && !IsPanel(pcd))
|
|
McdeToggleFullscreen(pcd);
|
|
return True;
|
|
}
|