Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

When using -g hint the WM that we've got user specified geometry

Without this some window managers (e.g. fvwm) will ignore the initial
window position and place it according to it's own rules.
  • Loading branch information...
commit 3f25b907bd1fbea563ddf335fb3d308094fa81c6 1 parent bcbe3b1
tv 4z3 authored

Showing 3 changed files with 53 additions and 19 deletions. Show diff stats Hide diff stats

  1. +0 1  main.c
  2. +50 18 window.c
  3. +3 0  window.h
1  main.c
@@ -26,7 +26,6 @@
26 26 #include <sys/select.h>
27 27 #include <sys/stat.h>
28 28 #include <sys/time.h>
29   -#include <X11/Xutil.h>
30 29 #include <X11/keysym.h>
31 30
32 31 #include "types.h"
68 window.c
@@ -124,6 +124,9 @@ void win_init(win_t *win) {
124 124 win->bar.bgcol = win_alloc_color(win, BAR_BG_COLOR);
125 125 win->bar.fgcol = win_alloc_color(win, BAR_FG_COLOR);
126 126
  127 + win->sizehints.flags = PWinGravity;
  128 + win->sizehints.win_gravity = NorthWestGravity;
  129 +
127 130 if (setlocale(LC_CTYPE, "") == NULL || XSupportsLocale() == 0)
128 131 warn("no locale support");
129 132
@@ -133,17 +136,24 @@ void win_init(win_t *win) {
133 136 }
134 137
135 138 void win_set_sizehints(win_t *win) {
136   - XSizeHints sizehints;
137 139
138 140 if (win == NULL || win->xwin == None)
139 141 return;
140 142
141   - sizehints.flags = PMinSize | PMaxSize;
142   - sizehints.min_width = win->w;
143   - sizehints.max_width = win->w;
144   - sizehints.min_height = win->h + win->bar.h;
145   - sizehints.max_height = win->h + win->bar.h;
146   - XSetWMNormalHints(win->env.dpy, win->xwin, &sizehints);
  143 + if ((win->sizehints.flags & PMinSize) == 1) {
  144 + win->sizehints.min_width = win->w;
  145 + win->sizehints.min_height = win->h + win->bar.h;
  146 + }
  147 + if ((win->sizehints.flags & PMaxSize) == 1) {
  148 + win->sizehints.max_width = win->w;
  149 + win->sizehints.max_height = win->h + win->bar.h;
  150 + }
  151 + if ((win->sizehints.flags & USPosition) == 1) {
  152 + win->sizehints.x = win->x;
  153 + win->sizehints.y = win->y;
  154 + }
  155 +
  156 + XSetWMNormalHints(win->env.dpy, win->xwin, &win->sizehints);
147 157 }
148 158
149 159 void win_open(win_t *win) {
@@ -165,22 +175,42 @@ void win_open(win_t *win) {
165 175 else
166 176 gmask = XParseGeometry(options->geometry, &win->x, &win->y,
167 177 &win->w, &win->h);
168   - if ((gmask & WidthValue) == 0)
  178 + if ((gmask & WidthValue) == 0) {
169 179 win->w = WIN_WIDTH;
  180 + } else {
  181 + win->sizehints.flags |= USSize;
  182 + }
170 183 if (win->w > e->scrw)
171 184 win->w = e->scrw;
172   - if ((gmask & HeightValue) == 0)
  185 + if ((gmask & HeightValue) == 0) {
173 186 win->h = WIN_HEIGHT;
  187 + } else {
  188 + win->sizehints.flags |= USSize;
  189 + }
174 190 if (win->h > e->scrh)
175 191 win->h = e->scrh;
176   - if ((gmask & XValue) == 0)
  192 + if ((gmask & XValue) == 0) {
177 193 win->x = (e->scrw - win->w) / 2;
178   - else if ((gmask & XNegative) != 0)
179   - win->x += e->scrw - win->w;
180   - if ((gmask & YValue) == 0)
  194 + } else {
  195 + if ((gmask & XNegative) != 0) {
  196 + win->x += e->scrw - win->w;
  197 + win->sizehints.win_gravity = NorthEastGravity;
  198 + }
  199 + win->sizehints.flags |= USPosition;
  200 + }
  201 + if ((gmask & YValue) == 0) {
181 202 win->y = (e->scrh - win->h) / 2;
182   - else if ((gmask & YNegative) != 0)
183   - win->y += e->scrh - win->h;
  203 + } else {
  204 + if ((gmask & YNegative) != 0) {
  205 + win->y += e->scrh - win->h;
  206 + if (win->sizehints.win_gravity == NorthEastGravity) {
  207 + win->sizehints.win_gravity = SouthEastGravity;
  208 + } else {
  209 + win->sizehints.win_gravity = SouthWestGravity;
  210 + }
  211 + }
  212 + win->sizehints.flags |= USPosition;
  213 + }
184 214
185 215 win->xwin = XCreateWindow(e->dpy, RootWindow(e->dpy, e->scr),
186 216 win->x, win->y, win->w, win->h, 0,
@@ -220,7 +250,9 @@ void win_open(win_t *win) {
220 250 }
221 251
222 252 if (options->fixed_win)
223   - win_set_sizehints(win);
  253 + win->sizehints.flags |= PMinSize | PMaxSize;
  254 +
  255 + win_set_sizehints(win);
224 256
225 257 XMapWindow(e->dpy, win->xwin);
226 258 XFlush(e->dpy);
@@ -291,8 +323,8 @@ bool win_moveresize(win_t *win, int x, int y, unsigned int w, unsigned int h) {
291 323 win->w = w;
292 324 win->h = h - win->bar.h;
293 325
294   - if (options->fixed_win)
295   - win_set_sizehints(win);
  326 +
  327 + win_set_sizehints(win);
296 328
297 329 XMoveResizeWindow(win->env.dpy, win->xwin, x, y, w, h);
298 330
3  window.h
@@ -20,6 +20,7 @@
20 20 #define WINDOW_H
21 21
22 22 #include <X11/Xlib.h>
  23 +#include <X11/Xutil.h>
23 24
24 25 #include "types.h"
25 26
@@ -48,6 +49,8 @@ typedef struct {
48 49 unsigned int h; /* = win height - bar height */
49 50 unsigned int bw;
50 51
  52 + XSizeHints sizehints;
  53 +
51 54 bool fullscreen;
52 55
53 56 struct {

0 comments on commit 3f25b90

Please sign in to comment.
Something went wrong with that request. Please try again.