Krolyxon
Commit bf41012

Branches

Refs →

nsxivbf41012

Merge remote-tracking branch '4z3/set-user-specified-sizehints' into sizehints

Author
Bert Münnich
Date
2013-02-09 01:21 +0100
Parents
f7301cf 3f25b90
Commit
bf4101249306669ebd5134fd0594376f00cb4538

+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
@@ -127,6 +127,9 @@ void win_init(win_t *win)
127127 win->bar.bgcol = win_alloc_color(win, BAR_BG_COLOR);
128128 win->bar.fgcol = win_alloc_color(win, BAR_FG_COLOR);
129129
130+ win->sizehints.flags = PWinGravity;
131+ win->sizehints.win_gravity = NorthWestGravity;
132+
130133 if (setlocale(LC_CTYPE, "") == NULL || XSupportsLocale() == 0)
131134 warn("no locale support");
132135
@@ -137,17 +140,24 @@ void win_init(win_t *win)
137140
138141 void win_set_sizehints(win_t *win)
139142 {
140− XSizeHints sizehints;
141143
142144 if (win == NULL || win->xwin == None)
143145 return;
144146
145− sizehints.flags = PMinSize | PMaxSize;
146− sizehints.min_width = win->w;
147− sizehints.max_width = win->w;
148− sizehints.min_height = win->h + win->bar.h;
149− sizehints.max_height = win->h + win->bar.h;
150− XSetWMNormalHints(win->env.dpy, win->xwin, &sizehints);
147+ if ((win->sizehints.flags & PMinSize) == 1) {
148+ win->sizehints.min_width = win->w;
149+ win->sizehints.min_height = win->h + win->bar.h;
150+ }
151+ if ((win->sizehints.flags & PMaxSize) == 1) {
152+ win->sizehints.max_width = win->w;
153+ win->sizehints.max_height = win->h + win->bar.h;
154+ }
155+ if ((win->sizehints.flags & USPosition) == 1) {
156+ win->sizehints.x = win->x;
157+ win->sizehints.y = win->y;
158+ }
159+
160+ XSetWMNormalHints(win->env.dpy, win->xwin, &win->sizehints);
151161 }
152162
153163 void win_open(win_t *win)
@@ -170,22 +180,42 @@ void win_open(win_t *win)
170180 else
171181 gmask = XParseGeometry(options->geometry, &win->x, &win->y,
172182 &win->w, &win->h);
173− if ((gmask & WidthValue) == 0)
183+ if ((gmask & WidthValue) == 0) {
174184 win->w = WIN_WIDTH;
185+ } else {
186+ win->sizehints.flags |= USSize;
187+ }
175188 if (win->w > e->scrw)
176189 win->w = e->scrw;
177− if ((gmask & HeightValue) == 0)
190+ if ((gmask & HeightValue) == 0) {
178191 win->h = WIN_HEIGHT;
192+ } else {
193+ win->sizehints.flags |= USSize;
194+ }
179195 if (win->h > e->scrh)
180196 win->h = e->scrh;
181− if ((gmask & XValue) == 0)
197+ if ((gmask & XValue) == 0) {
182198 win->x = (e->scrw - win->w) / 2;
183− else if ((gmask & XNegative) != 0)
184− win->x += e->scrw - win->w;
185− if ((gmask & YValue) == 0)
199+ } else {
200+ if ((gmask & XNegative) != 0) {
201+ win->x += e->scrw - win->w;
202+ win->sizehints.win_gravity = NorthEastGravity;
203+ }
204+ win->sizehints.flags |= USPosition;
205+ }
206+ if ((gmask & YValue) == 0) {
186207 win->y = (e->scrh - win->h) / 2;
187− else if ((gmask & YNegative) != 0)
188− win->y += e->scrh - win->h;
208+ } else {
209+ if ((gmask & YNegative) != 0) {
210+ win->y += e->scrh - win->h;
211+ if (win->sizehints.win_gravity == NorthEastGravity) {
212+ win->sizehints.win_gravity = SouthEastGravity;
213+ } else {
214+ win->sizehints.win_gravity = SouthWestGravity;
215+ }
216+ }
217+ win->sizehints.flags |= USPosition;
218+ }
189219
190220 win->xwin = XCreateWindow(e->dpy, RootWindow(e->dpy, e->scr),
191221 win->x, win->y, win->w, win->h, 0,
@@ -225,7 +255,9 @@ void win_open(win_t *win)
225255 }
226256
227257 if (options->fixed_win)
228− win_set_sizehints(win);
258+ win->sizehints.flags |= PMinSize | PMaxSize;
259+
260+ win_set_sizehints(win);
229261
230262 XMapWindow(e->dpy, win->xwin);
231263 XFlush(e->dpy);
@@ -300,8 +332,8 @@ bool win_moveresize(win_t *win, int x, int y, unsigned int w, unsigned int h)
300332 win->w = w;
301333 win->h = h - win->bar.h;
302334
303− if (options->fixed_win)
304− win_set_sizehints(win);
335+
336+ win_set_sizehints(win);
305337
306338 XMoveResizeWindow(win->env.dpy, win->xwin, x, y, w, h);
307339
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 {