commit e583fbee30395a54d4141b576c928fa15ec351c2
parent c9d9707e7d57118338a9e08bd130661e561597c5
Author: Lucas de Sena <lucas@seninha.org>
Date: Sat, 8 Apr 2023 18:08:59 -0300
add rules for desktop id; fix #39
Diffstat:
5 files changed, 28 insertions(+), 11 deletions(-)
diff --git a/config.c b/config.c
@@ -54,12 +54,12 @@ struct Config config = {
/* the following are hardcoded rules; use X Resources to set rules without recompiling */
.rules = (struct Rule []){
- /* class instance role type state bitmask */
+ /* class instance role type state desktop*/
/* Although Firefox's PictureInPicture is technically a utility (sub)window, make it a normal one */
- { NULL, NULL, "PictureInPicture", TYPE_NORMAL, ABOVE },
+ { NULL, NULL, "PictureInPicture", TYPE_NORMAL, ABOVE, 0 },
/* Last rule must be all NULL! */
- { NULL, NULL, NULL, TYPE_NORMAL, 0 },
+ { NULL, NULL, NULL, TYPE_NORMAL, 0, 0 },
}
};
diff --git a/shod.1 b/shod.1
@@ -804,6 +804,10 @@ and
.It Ic shod.CLASS.NAME.ROLE.dockpos
Define the position in the dock of a docked application matching the given class, name and role.
Its value should be a number, starting from position 1.
+.It Ic shod.CLASS.NAME.ROLE.desktop
+Define the number of the desktop to send the matching application to.
+Different of other window managers, shod counts desktop from 1;
+so the first desktop is desktop 1, not the desktop 0.
.El
.Sh ENVIRONMENT
The following environment variables affect the execution of
diff --git a/shod.h b/shod.h
@@ -31,6 +31,7 @@
/* CLASS NAME */\
X(RES_TYPE, "Type", "type" )\
X(RES_STATE, "State", "state" )\
+ X(RES_DESKTOP, "Desktop", "desktop" )\
X(RES_DOCK_POS, "Dockpos", "dockpos" )\
X(RES_FACE_NAME, "FaceName", "faceName" )\
X(RES_FOREGROUND, "Foreground", "foreground" )\
@@ -688,6 +689,7 @@ struct Config {
/* type, state, etc to apply on matching windows */
int type;
int state;
+ int desktop;
} *rules;
/* the values below are computed from the values above */
diff --git a/xcontainer.c b/xcontainer.c
@@ -1855,13 +1855,11 @@ containernewwithtab(struct Tab *tab, struct Monitor *mon, int desk, XRectangle r
rowaddtab(row, tab, NULL);
containerredecorate(c, NULL, NULL, 0);
XMapSubwindows(dpy, c->frame);
- if (!c->isminimized) {
- containerplace(c, mon, desk, (state & USERPLACED));
- containermoveresize(c, 0);
+ containerplace(c, mon, desk, (state & USERPLACED));
+ containermoveresize(c, 0);
+ if (containerisvisible(c, wm.selmon, wm.selmon->seldesk)) {
containerhide(c, 0);
tabfocus(tab, 0);
- } else {
- containermoveresize(c, 0);
}
/* no need to call shodgrouptab() and shodgroupcontainer(); tabfocus() already calls them */
ewmhsetwmdesktop(c);
diff --git a/xevents.c b/xevents.c
@@ -380,7 +380,7 @@ getextrahints(Window win, Atom prop, unsigned long nmemb, size_t size, void *hin
/* get window info based on its type */
static int
-getwintype(Window *win_ret, Window *leader, struct Tab **tab, int *state, XRectangle *rect)
+getwintype(Window *win_ret, Window *leader, struct Tab **tab, int *state, XRectangle *rect, int *desk)
{
/* rules for identifying windows */
enum { I_APP, I_CLASS, I_INSTANCE, I_ROLE, I_RESOURCE, I_NULL, I_LAST };
@@ -420,6 +420,9 @@ getwintype(Window *win_ret, Window *leader, struct Tab **tab, int *state, XRecta
if (config.rules[i].state >= 0) {
*state = config.rules[i].state;
}
+ if (config.rules[i].desktop > 0 && config.rules[i].desktop <= config.ndesktops) {
+ *desk = config.rules[i].desktop - 1;
+ }
}
}
@@ -504,6 +507,15 @@ getwintype(Window *win_ret, Window *leader, struct Tab **tab, int *state, XRecta
}
}
+ /* get desktop id from X resources */
+ class[I_RESOURCE] = wm.resources[RES_DESKTOP].class;
+ name[I_RESOURCE] = wm.resources[RES_DESKTOP].name;
+ if ((value = getresource(xdb, class, name)) != NULL) {
+ if ((n = strtol(value, NULL, 10)) > 0 && n <= config.ndesktops) {
+ *desk = n - 1;
+ }
+ }
+
/* we already got the type of the window, return */
if (type != TYPE_UNKNOWN)
goto done;
@@ -733,10 +745,11 @@ manage(Window win, XRectangle rect, int ignoreunmap)
struct Tab *tab;
Window leader;
int state, type;
+ int desk = wm.selmon->seldesk;
if (getmanaged(win) != NULL)
return;
- type = getwintype(&win, &leader, &tab, &state, &rect);
+ type = getwintype(&win, &leader, &tab, &state, &rect, &desk);
if (type == TYPE_DESKTOP || type == TYPE_POPUP) {
/* we do not handle desktop windows */
if (type == TYPE_DESKTOP)
@@ -747,7 +760,7 @@ manage(Window win, XRectangle rect, int ignoreunmap)
return;
}
preparewin(win);
- (*managefuncs[type])(tab, wm.selmon, wm.selmon->seldesk, win, leader, rect, state, ignoreunmap);
+ (*managefuncs[type])(tab, wm.selmon, desk, win, leader, rect, state, ignoreunmap);
}
/* perform container switching (aka alt-tab) */