Krolyxon
Commit 3f25b90

Branches

Refs →

nsxiv3f25b90

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.
Author
tv
Date
2013-01-30 20:39 +0100
Committer
tv · 2013-01-30 20:51 +0100
Parent
bcbe3b1
Commit
3f25b907bd1fbea563ddf335fb3d308094fa81c6

+53 −19

3 files changed

  1. M main.c +0 −1
  2. M window.c +50 −18
  3. M window.h +3 −0
M main.c View
@@ -26,7 +26,6 @@
2626 #include <sys/select.h>
2727 #include <sys/stat.h>
2828 #include <sys/time.h>
29−#include <X11/Xutil.h>
3029 #include <X11/keysym.h>
3130
3231 #include "types.h"
M window.c View
@@ -124,6 +124,9 @@ void win_init(win_t *win) {
124124 win->bar.bgcol = win_alloc_color(win, BAR_BG_COLOR);
125125 win->bar.fgcol = win_alloc_color(win, BAR_FG_COLOR);
126126
127+ win->sizehints.flags = PWinGravity;
128+ win->sizehints.win_gravity = NorthWestGravity;
129+
127130 if (setlocale(LC_CTYPE, "") == NULL || XSupportsLocale() == 0)
128131 warn("no locale support");
129132
@@ -133,17 +136,24 @@ void win_init(win_t *win) {
133136 }
134137
135138 void win_set_sizehints(win_t *win) {
136− XSizeHints sizehints;
137139
138140 if (win == NULL || win->xwin == None)
139141 return;
140142
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);
147157 }
148158
149159 void win_open(win_t *win) {
@@ -165,22 +175,42 @@ void win_open(win_t *win) {
165175 else
166176 gmask = XParseGeometry(options->geometry, &win->x, &win->y,
167177 &win->w, &win->h);
168− if ((gmask & WidthValue) == 0)
178+ if ((gmask & WidthValue) == 0) {
169179 win->w = WIN_WIDTH;
180+ } else {
181+ win->sizehints.flags |= USSize;
182+ }
170183 if (win->w > e->scrw)
171184 win->w = e->scrw;
172− if ((gmask & HeightValue) == 0)
185+ if ((gmask & HeightValue) == 0) {
173186 win->h = WIN_HEIGHT;
187+ } else {
188+ win->sizehints.flags |= USSize;
189+ }
174190 if (win->h > e->scrh)
175191 win->h = e->scrh;
176− if ((gmask & XValue) == 0)
192+ if ((gmask & XValue) == 0) {
177193 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) {
181202 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+ }
184214
185215 win->xwin = XCreateWindow(e->dpy, RootWindow(e->dpy, e->scr),
186216 win->x, win->y, win->w, win->h, 0,
@@ -220,7 +250,9 @@ void win_open(win_t *win) {
220250 }
221251
222252 if (options->fixed_win)
223− win_set_sizehints(win);
253+ win->sizehints.flags |= PMinSize | PMaxSize;
254+
255+ win_set_sizehints(win);
224256
225257 XMapWindow(e->dpy, win->xwin);
226258 XFlush(e->dpy);
@@ -291,8 +323,8 @@ bool win_moveresize(win_t *win, int x, int y, unsigned int w, unsigned int h) {
291323 win->w = w;
292324 win->h = h - win->bar.h;
293325
294− if (options->fixed_win)
295− win_set_sizehints(win);
326+
327+ win_set_sizehints(win);
296328
297329 XMoveResizeWindow(win->env.dpy, win->xwin, x, y, w, h);
298330
M window.h View
@@ -20,6 +20,7 @@
2020 #define WINDOW_H
2121
2222 #include <X11/Xlib.h>
23+#include <X11/Xutil.h>
2324
2425 #include "types.h"
2526
@@ -48,6 +49,8 @@ typedef struct {
4849 unsigned int h; /* = win height - bar height */
4950 unsigned int bw;
5051
52+ XSizeHints sizehints;
53+
5154 bool fullscreen;
5255
5356 struct {