Krolyxon
Commit c6bfac1

Branches

Refs →

nsxivc6bfac1

Merge branch 'sizehints', fixed issue #78

Author
Bert Münnich
Date
2013-02-09 19:07 +0100
Parents
a527025 1e2ddc4
Commit
c6bfac15664d8d9619ca7793118e719d6e0dcd44

+51 −28

4 files changed

  1. M Makefile +1 −1
  2. M main.c +0 −1
  3. M window.c +47 −26
  4. M window.h +3 −0
M Makefile View
@@ -1,4 +1,4 @@
1−VERSION = git-20130208
1+VERSION = git-20130209
22
33 PREFIX = /usr/local
44 MANPREFIX = $(PREFIX)/share/man
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
@@ -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"
@@ -127,6 +126,12 @@ void win_init(win_t *win)
127126 win->bar.bgcol = win_alloc_color(win, BAR_BG_COLOR);
128127 win->bar.fgcol = win_alloc_color(win, BAR_FG_COLOR);
129128
129+ win->sizehints.flags = PWinGravity;
130+ win->sizehints.win_gravity = NorthWestGravity;
131+ if (options->fixed_win)
132+ /* actual min/max values set in win_update_sizehints() */
133+ win->sizehints.flags |= PMinSize | PMaxSize;
134+
130135 if (setlocale(LC_CTYPE, "") == NULL || XSupportsLocale() == 0)
131136 warn("no locale support");
132137
@@ -135,19 +140,24 @@ void win_init(win_t *win)
135140 wm_delete_win = XInternAtom(e->dpy, "WM_DELETE_WINDOW", False);
136141 }
137142
138−void win_set_sizehints(win_t *win)
143+void win_update_sizehints(win_t *win)
139144 {
140− XSizeHints sizehints;
141−
142145 if (win == NULL || win->xwin == None)
143146 return;
144147
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);
148+ if ((win->sizehints.flags & USSize) != 0) {
149+ win->sizehints.width = win->w;
150+ win->sizehints.height = win->h;
151+ }
152+ if ((win->sizehints.flags & USPosition) != 0) {
153+ win->sizehints.x = win->x;
154+ win->sizehints.y = win->y;
155+ }
156+ if (options->fixed_win) {
157+ win->sizehints.min_width = win->sizehints.max_width = win->w;
158+ win->sizehints.min_height = win->sizehints.max_height = win->h + win->bar.h;
159+ }
160+ XSetWMNormalHints(win->env.dpy, win->xwin, &win->sizehints);
151161 }
152162
153163 void win_open(win_t *win)
@@ -170,22 +180,35 @@ 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)
184+ win->sizehints.flags |= USSize;
185+ else
174186 win->w = WIN_WIDTH;
175− if (win->w > e->scrw)
176− win->w = e->scrw;
177− if ((gmask & HeightValue) == 0)
187+ if ((gmask & HeightValue) != 0)
188+ win->sizehints.flags |= USSize;
189+ else
178190 win->h = WIN_HEIGHT;
179− if (win->h > e->scrh)
180− win->h = e->scrh;
181− if ((gmask & XValue) == 0)
191+ if ((gmask & XValue) != 0) {
192+ if ((gmask & XNegative) != 0) {
193+ win->x += e->scrw - win->w;
194+ win->sizehints.win_gravity = NorthEastGravity;
195+ }
196+ win->sizehints.flags |= USPosition;
197+ } else {
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+ }
200+ if ((gmask & YValue) != 0) {
201+ if ((gmask & YNegative) != 0) {
202+ win->y += e->scrh - win->h;
203+ if (win->sizehints.win_gravity == NorthEastGravity)
204+ win->sizehints.win_gravity = SouthEastGravity;
205+ else
206+ win->sizehints.win_gravity = SouthWestGravity;
207+ }
208+ win->sizehints.flags |= USPosition;
209+ } else {
186210 win->y = (e->scrh - win->h) / 2;
187− else if ((gmask & YNegative) != 0)
188− win->y += e->scrh - win->h;
211+ }
189212
190213 win->xwin = XCreateWindow(e->dpy, RootWindow(e->dpy, e->scr),
191214 win->x, win->y, win->w, win->h, 0,
@@ -224,8 +247,7 @@ void win_open(win_t *win)
224247 win->h -= win->bar.h;
225248 }
226249
227− if (options->fixed_win)
228− win_set_sizehints(win);
250+ win_update_sizehints(win);
229251
230252 XMapWindow(e->dpy, win->xwin);
231253 XFlush(e->dpy);
@@ -303,8 +325,7 @@ bool win_moveresize(win_t *win, int x, int y, unsigned int w, unsigned int h)
303325 win->w = w;
304326 win->h = h - win->bar.h;
305327
306− if (options->fixed_win)
307− win_set_sizehints(win);
328+ win_update_sizehints(win);
308329
309330 XMoveResizeWindow(win->env.dpy, win->xwin, x, y, w, h);
310331
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 {