Krolyxon
Commit cef8d51

Branches

Refs →

nsxivcef8d51

Refined US{Position,Size} & WinGravity handling

Author
Bert Münnich
Date
2013-02-09 01:36 +0100
Parent
bf41012
Commit
cef8d51153073d694f66889ad536736109aaf77e

+39 −39

1 file changed

  1. M window.c +39 −39
M window.c View
@@ -21,7 +21,6 @@
2121
2222 #include <string.h>
2323 #include <locale.h>
24−#include <X11/Xutil.h>
2524 #include <X11/cursorfont.h>
2625
2726 #include "options.h"
@@ -30,6 +29,8 @@
3029 #include "config.h"
3130
3231 enum {
32+ WIN_MIN_W = 50,
33+ WIN_MIN_H = 30,
3334 H_TEXT_PAD = 5,
3435 V_TEXT_PAD = 1
3536 };
@@ -127,8 +128,16 @@ void win_init(win_t *win)
127128 win->bar.bgcol = win_alloc_color(win, BAR_BG_COLOR);
128129 win->bar.fgcol = win_alloc_color(win, BAR_FG_COLOR);
129130
130− win->sizehints.flags = PWinGravity;
131+ win->sizehints.flags = PWinGravity | PMinSize;
131132 win->sizehints.win_gravity = NorthWestGravity;
133+ if (options->fixed_win) {
134+ /* actual min/max values set in win_update_sizehints() */
135+ win->sizehints.flags |= PMaxSize;
136+ } else {
137+ /* min values only set here, never updated in win_update_sizehints() */
138+ win->sizehints.min_width = WIN_MIN_W;
139+ win->sizehints.min_height = WIN_MIN_H;
140+ }
132141
133142 if (setlocale(LC_CTYPE, "") == NULL || XSupportsLocale() == 0)
134143 warn("no locale support");
@@ -138,25 +147,23 @@ void win_init(win_t *win)
138147 wm_delete_win = XInternAtom(e->dpy, "WM_DELETE_WINDOW", False);
139148 }
140149
141−void win_set_sizehints(win_t *win)
150+void win_update_sizehints(win_t *win)
142151 {
143−
144152 if (win == NULL || win->xwin == None)
145153 return;
146154
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;
155+ if ((win->sizehints.flags & USSize) != 0) {
156+ win->sizehints.width = win->w;
157+ win->sizehints.height = win->h;
154158 }
155− if ((win->sizehints.flags & USPosition) == 1) {
159+ if ((win->sizehints.flags & USPosition) != 0) {
156160 win->sizehints.x = win->x;
157161 win->sizehints.y = win->y;
158162 }
159−
163+ if (options->fixed_win) {
164+ win->sizehints.min_width = win->sizehints.max_width = win->w;
165+ win->sizehints.min_height = win->sizehints.max_height = win->h + win->bar.h;
166+ }
160167 XSetWMNormalHints(win->env.dpy, win->xwin, &win->sizehints);
161168 }
162169
@@ -180,41 +187,38 @@ void win_open(win_t *win)
180187 else
181188 gmask = XParseGeometry(options->geometry, &win->x, &win->y,
182189 &win->w, &win->h);
183− if ((gmask & WidthValue) == 0) {
190+ if ((gmask & WidthValue) != 0)
191+ win->sizehints.flags |= USSize;
192+ else
184193 win->w = WIN_WIDTH;
185− } else {
194+ win->w = MAX(win->w, WIN_MIN_W);
195+ win->w = MIN(win->w, e->scrw);
196+ if ((gmask & HeightValue) != 0)
186197 win->sizehints.flags |= USSize;
187− }
188− if (win->w > e->scrw)
189− win->w = e->scrw;
190− if ((gmask & HeightValue) == 0) {
198+ else
191199 win->h = WIN_HEIGHT;
192− } else {
193− win->sizehints.flags |= USSize;
194− }
195− if (win->h > e->scrh)
196− win->h = e->scrh;
197− if ((gmask & XValue) == 0) {
198− win->x = (e->scrw - win->w) / 2;
199− } else {
200+ win->h = MAX(win->h, WIN_MIN_H);
201+ win->h = MIN(win->h, e->scrh);
202+ if ((gmask & XValue) != 0) {
200203 if ((gmask & XNegative) != 0) {
201204 win->x += e->scrw - win->w;
202205 win->sizehints.win_gravity = NorthEastGravity;
203206 }
204207 win->sizehints.flags |= USPosition;
205− }
206− if ((gmask & YValue) == 0) {
207− win->y = (e->scrh - win->h) / 2;
208208 } else {
209+ win->x = (e->scrw - win->w) / 2;
210+ }
211+ if ((gmask & YValue) != 0) {
209212 if ((gmask & YNegative) != 0) {
210213 win->y += e->scrh - win->h;
211− if (win->sizehints.win_gravity == NorthEastGravity) {
214+ if (win->sizehints.win_gravity == NorthEastGravity)
212215 win->sizehints.win_gravity = SouthEastGravity;
213− } else {
216+ else
214217 win->sizehints.win_gravity = SouthWestGravity;
215− }
216218 }
217219 win->sizehints.flags |= USPosition;
220+ } else {
221+ win->y = (e->scrh - win->h) / 2;
218222 }
219223
220224 win->xwin = XCreateWindow(e->dpy, RootWindow(e->dpy, e->scr),
@@ -254,10 +258,7 @@ void win_open(win_t *win)
254258 win->h -= win->bar.h;
255259 }
256260
257− if (options->fixed_win)
258− win->sizehints.flags |= PMinSize | PMaxSize;
259−
260− win_set_sizehints(win);
261+ win_update_sizehints(win);
261262
262263 XMapWindow(e->dpy, win->xwin);
263264 XFlush(e->dpy);
@@ -332,8 +333,7 @@ bool win_moveresize(win_t *win, int x, int y, unsigned int w, unsigned int h)
332333 win->w = w;
333334 win->h = h - win->bar.h;
334335
335−
336− win_set_sizehints(win);
336+ win_update_sizehints(win);
337337
338338 XMoveResizeWindow(win->env.dpy, win->xwin, x, y, w, h);
339339