nsxivcef8d51
Refined US{Position,Size} & WinGravity handling
+39 −39
1 file changed
- M window.c +39 −39
| @@ -21,7 +21,6 @@ | |||
| 21 | 21 | ||
| 22 | 22 | #include <string.h> | |
| 23 | 23 | #include <locale.h> | |
| 24 | − | #include <X11/Xutil.h> | |
| 25 | 24 | #include <X11/cursorfont.h> | |
| 26 | 25 | ||
| 27 | 26 | #include "options.h" | |
| @@ -30,6 +29,8 @@ | |||
| 30 | 29 | #include "config.h" | |
| 31 | 30 | ||
| 32 | 31 | enum { | |
| 32 | + | WIN_MIN_W = 50, | |
| 33 | + | WIN_MIN_H = 30, | |
| 33 | 34 | H_TEXT_PAD = 5, | |
| 34 | 35 | V_TEXT_PAD = 1 | |
| 35 | 36 | }; | |
| @@ -127,8 +128,16 @@ void win_init(win_t *win) | |||
| 127 | 128 | win->bar.bgcol = win_alloc_color(win, BAR_BG_COLOR); | |
| 128 | 129 | win->bar.fgcol = win_alloc_color(win, BAR_FG_COLOR); | |
| 129 | 130 | ||
| 130 | − | win->sizehints.flags = PWinGravity; | |
| 131 | + | win->sizehints.flags = PWinGravity | PMinSize; | |
| 131 | 132 | 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 | + | } | |
| 132 | 141 | ||
| 133 | 142 | if (setlocale(LC_CTYPE, "") == NULL || XSupportsLocale() == 0) | |
| 134 | 143 | warn("no locale support"); | |
| @@ -138,25 +147,23 @@ void win_init(win_t *win) | |||
| 138 | 147 | wm_delete_win = XInternAtom(e->dpy, "WM_DELETE_WINDOW", False); | |
| 139 | 148 | } | |
| 140 | 149 | ||
| 141 | − | void win_set_sizehints(win_t *win) | |
| 150 | + | void win_update_sizehints(win_t *win) | |
| 142 | 151 | { | |
| 143 | − | ||
| 144 | 152 | if (win == NULL || win->xwin == None) | |
| 145 | 153 | return; | |
| 146 | 154 | ||
| 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; | |
| 154 | 158 | } | |
| 155 | − | if ((win->sizehints.flags & USPosition) == 1) { | |
| 159 | + | if ((win->sizehints.flags & USPosition) != 0) { | |
| 156 | 160 | win->sizehints.x = win->x; | |
| 157 | 161 | win->sizehints.y = win->y; | |
| 158 | 162 | } | |
| 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 | + | } | |
| 160 | 167 | XSetWMNormalHints(win->env.dpy, win->xwin, &win->sizehints); | |
| 161 | 168 | } | |
| 162 | 169 | ||
| @@ -180,41 +187,38 @@ void win_open(win_t *win) | |||
| 180 | 187 | else | |
| 181 | 188 | gmask = XParseGeometry(options->geometry, &win->x, &win->y, | |
| 182 | 189 | &win->w, &win->h); | |
| 183 | − | if ((gmask & WidthValue) == 0) { | |
| 190 | + | if ((gmask & WidthValue) != 0) | |
| 191 | + | win->sizehints.flags |= USSize; | |
| 192 | + | else | |
| 184 | 193 | 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) | |
| 186 | 197 | win->sizehints.flags |= USSize; | |
| 187 | − | } | |
| 188 | − | if (win->w > e->scrw) | |
| 189 | − | win->w = e->scrw; | |
| 190 | − | if ((gmask & HeightValue) == 0) { | |
| 198 | + | else | |
| 191 | 199 | 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) { | |
| 200 | 203 | if ((gmask & XNegative) != 0) { | |
| 201 | 204 | win->x += e->scrw - win->w; | |
| 202 | 205 | win->sizehints.win_gravity = NorthEastGravity; | |
| 203 | 206 | } | |
| 204 | 207 | win->sizehints.flags |= USPosition; | |
| 205 | − | } | |
| 206 | − | if ((gmask & YValue) == 0) { | |
| 207 | − | win->y = (e->scrh - win->h) / 2; | |
| 208 | 208 | } else { | |
| 209 | + | win->x = (e->scrw - win->w) / 2; | |
| 210 | + | } | |
| 211 | + | if ((gmask & YValue) != 0) { | |
| 209 | 212 | if ((gmask & YNegative) != 0) { | |
| 210 | 213 | win->y += e->scrh - win->h; | |
| 211 | − | if (win->sizehints.win_gravity == NorthEastGravity) { | |
| 214 | + | if (win->sizehints.win_gravity == NorthEastGravity) | |
| 212 | 215 | win->sizehints.win_gravity = SouthEastGravity; | |
| 213 | − | } else { | |
| 216 | + | else | |
| 214 | 217 | win->sizehints.win_gravity = SouthWestGravity; | |
| 215 | − | } | |
| 216 | 218 | } | |
| 217 | 219 | win->sizehints.flags |= USPosition; | |
| 220 | + | } else { | |
| 221 | + | win->y = (e->scrh - win->h) / 2; | |
| 218 | 222 | } | |
| 219 | 223 | ||
| 220 | 224 | win->xwin = XCreateWindow(e->dpy, RootWindow(e->dpy, e->scr), | |
| @@ -254,10 +258,7 @@ void win_open(win_t *win) | |||
| 254 | 258 | win->h -= win->bar.h; | |
| 255 | 259 | } | |
| 256 | 260 | ||
| 257 | − | if (options->fixed_win) | |
| 258 | − | win->sizehints.flags |= PMinSize | PMaxSize; | |
| 259 | − | ||
| 260 | − | win_set_sizehints(win); | |
| 261 | + | win_update_sizehints(win); | |
| 261 | 262 | ||
| 262 | 263 | XMapWindow(e->dpy, win->xwin); | |
| 263 | 264 | XFlush(e->dpy); | |
| @@ -332,8 +333,7 @@ bool win_moveresize(win_t *win, int x, int y, unsigned int w, unsigned int h) | |||
| 332 | 333 | win->w = w; | |
| 333 | 334 | win->h = h - win->bar.h; | |
| 334 | 335 | ||
| 335 | − | ||
| 336 | − | win_set_sizehints(win); | |
| 336 | + | win_update_sizehints(win); | |
| 337 | 337 | ||
| 338 | 338 | XMoveResizeWindow(win->env.dpy, win->xwin, x, y, w, h); | |
| 339 | 339 | ||