Skip to content

Instantly share code, notes, and snippets.

@jgrar
Created December 30, 2015 00:51
Show Gist options
  • Save jgrar/e689f11f3002ebb226ed to your computer and use it in GitHub Desktop.
Save jgrar/e689f11f3002ebb226ed to your computer and use it in GitHub Desktop.
add window rule to dwm maximise patch
diff --git a/config.def.h b/config.def.h
index 7054c06..859bdcf 100644
--- a/config.def.h
+++ b/config.def.h
@@ -24,9 +24,9 @@ static const Rule rules[] = {
* WM_CLASS(STRING) = instance, class
* WM_NAME(STRING) = title
*/
- /* class instance title tags mask isfloating monitor */
- { "Gimp", NULL, NULL, 0, 1, -1 },
- { "Firefox", NULL, NULL, 1 << 8, 0, -1 },
+ /* class instance title tags mask isfloating ismax monitor */
+ { "Gimp", NULL, NULL, 0, 1, 0, -1 },
+ { "Firefox", NULL, NULL, 1 << 8, 0, 0, -1 },
};
/* layout(s) */
diff --git a/dwm.c b/dwm.c
index 0362114..8fbe2ec 100644
--- a/dwm.c
+++ b/dwm.c
@@ -92,7 +92,7 @@ struct Client {
int basew, baseh, incw, inch, maxw, maxh, minw, minh;
int bw, oldbw;
unsigned int tags;
- int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
+ int ismax, wasfloating, isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
Client *next;
Client *snext;
Monitor *mon;
@@ -138,6 +138,7 @@ typedef struct {
const char *title;
unsigned int tags;
int isfloating;
+ int ismax;
int monitor;
} Rule;
@@ -297,6 +298,7 @@ applyrules(Client *c)
&& (!r->instance || strstr(instance, r->instance)))
{
c->isfloating = r->isfloating;
+ c->ismax = r->ismax;
c->tags |= r->tags;
for (m = mons; m && m->num != r->monitor; m = m->next);
if (m)
@@ -1047,10 +1049,17 @@ manage(Window w, XWindowAttributes *wa)
applyrules(c);
}
/* geometry */
- c->x = c->oldx = wa->x;
- c->y = c->oldy = wa->y;
- c->w = c->oldw = wa->width;
- c->h = c->oldh = wa->height;
+ if (!c->ismax) {
+ c->x = c->oldx = wa->x;
+ c->y = c->oldy = wa->y;
+ c->w = c->oldw = wa->width;
+ c->h = c->oldh = wa->height;
+ } else {
+ c->x = c->oldx = selmon->wx;
+ c->y = c->oldy = selmon->wy;
+ c->w = c->oldw = selmon->ww - 2 * borderpx;
+ c->h = c->oldh = selmon->wh - 2 * borderpx;
+ }
c->oldbw = wa->border_width;
if (c->x + WIDTH(c) > c->mon->mx + c->mon->mw)
@@ -1072,6 +1081,8 @@ manage(Window w, XWindowAttributes *wa)
updatewmhints(c);
XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
grabbuttons(c, 0);
+ c->wasfloating = 0;
+ c->ismax = 0;
if (!c->isfloating)
c->isfloating = c->oldstate = trans != None || c->isfixed;
if (c->isfloating)
diff --git a/maximize.c b/maximize.c
new file mode 100644
index 0000000..07568d8
--- /dev/null
+++ b/maximize.c
@@ -0,0 +1,41 @@
+void
+maximize(int x, int y, int w, int h) {
+ XEvent ev;
+
+ if(!selmon->sel || selmon->sel->isfixed)
+ return;
+ XRaiseWindow(dpy, selmon->sel->win);
+ if(!selmon->sel->ismax) {
+ if(!selmon->lt[selmon->sellt]->arrange || selmon->sel->isfloating)
+ selmon->sel->wasfloating = 1;
+ else {
+ togglefloating(NULL);
+ selmon->sel->wasfloating = 0;
+ }
+ resize(selmon->sel, x, y, w, h, 1);
+ selmon->sel->ismax = 1;
+ }
+ else {
+ resize(selmon->sel, selmon->sel->oldx, selmon->sel->oldy, selmon->sel->oldw, selmon->sel->oldh, 1);
+ if(!selmon->sel->wasfloating)
+ togglefloating(NULL);
+ selmon->sel->ismax = 0;
+ }
+ drawbar(selmon);
+ while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
+}
+
+void
+togglemaximize(const Arg *arg) {
+ maximize(selmon->wx, selmon->wy, selmon->ww - 2 * borderpx, selmon->wh - 2 * borderpx);
+}
+
+void
+toggleverticalmax(const Arg *arg) {
+ maximize(selmon->sel->x, selmon->wy, selmon->sel->w, selmon->wh - 2 * borderpx);
+}
+
+void
+togglehorizontalmax(const Arg *arg) {
+ maximize(selmon->wx, selmon->sel->y, selmon->ww - 2 * borderpx, selmon->sel->h);
+}
@jgrar
Copy link
Author

jgrar commented Dec 31, 2015

Maximise

Original

http://dwm.suckless.org/patches/maximize

Applies to

http://git.suckless.org/dwm/commit/?id=3465bed290abc62cb2e69a8096084ba6b8eb4956

Changes

I was unhappy with scripted solutions for automatic on-window-open maximization using xdotool (wmctrl wouldn't even work for me), preferring it to just be provided by the window manager I've added a window rule which automatically starts a window maximized.

Changes also include:

  • updating the patch to apply to 3465bed290ab
    • Change boolean values to integers
  • removing redundant size saving in maximize() as resizeclient() does this already

Usage

There's not much to it really, just flip the new ismax field of Rules from 0 to non-zero!

// ... static const Rule rules[] = {
    /* class    instance          title       tags mask     isfloating     ismax         monitor */
    { NULL,     "maximiseme",     NULL,       0,            1,             0,            -1 },
// ...
const char *maximisethiscmd[] = {"urxvtc", "-name", "maximiseme", "-e", "example", NULL};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment