| @@ -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" |
| @@ -127,6 +126,12 @@ void win_init(win_t *win) |
| 127 | 126 | | win->bar.bgcol = win_alloc_color(win, BAR_BG_COLOR); |
| 128 | 127 | | win->bar.fgcol = win_alloc_color(win, BAR_FG_COLOR); |
| 129 | 128 | | |
| 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 | + | |
| 130 | 135 | | if (setlocale(LC_CTYPE, "") == NULL || XSupportsLocale() == 0) |
| 131 | 136 | | warn("no locale support"); |
| 132 | 137 | | |
| @@ -135,19 +140,24 @@ void win_init(win_t *win) |
| 135 | 140 | | wm_delete_win = XInternAtom(e->dpy, "WM_DELETE_WINDOW", False); |
| 136 | 141 | | } |
| 137 | 142 | | |
| 138 | | − | void win_set_sizehints(win_t *win) |
| 143 | + | void win_update_sizehints(win_t *win) |
| 139 | 144 | | { |
| 140 | | − | XSizeHints sizehints; |
| 141 | | − | |
| 142 | 145 | | if (win == NULL || win->xwin == None) |
| 143 | 146 | | return; |
| 144 | 147 | | |
| 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); |
| 151 | 161 | | } |
| 152 | 162 | | |
| 153 | 163 | | void win_open(win_t *win) |
| @@ -170,22 +180,35 @@ void win_open(win_t *win) |
| 170 | 180 | | else |
| 171 | 181 | | gmask = XParseGeometry(options->geometry, &win->x, &win->y, |
| 172 | 182 | | &win->w, &win->h); |
| 173 | | − | if ((gmask & WidthValue) == 0) |
| 183 | + | if ((gmask & WidthValue) != 0) |
| 184 | + | win->sizehints.flags |= USSize; |
| 185 | + | else |
| 174 | 186 | | 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 |
| 178 | 190 | | 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 { |
| 182 | 198 | | 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 { |
| 186 | 210 | | win->y = (e->scrh - win->h) / 2; |
| 187 | | − | else if ((gmask & YNegative) != 0) |
| 188 | | − | win->y += e->scrh - win->h; |
| 211 | + | } |
| 189 | 212 | | |
| 190 | 213 | | win->xwin = XCreateWindow(e->dpy, RootWindow(e->dpy, e->scr), |
| 191 | 214 | | win->x, win->y, win->w, win->h, 0, |
| @@ -224,8 +247,7 @@ void win_open(win_t *win) |
| 224 | 247 | | win->h -= win->bar.h; |
| 225 | 248 | | } |
| 226 | 249 | | |
| 227 | | − | if (options->fixed_win) |
| 228 | | − | win_set_sizehints(win); |
| 250 | + | win_update_sizehints(win); |
| 229 | 251 | | |
| 230 | 252 | | XMapWindow(e->dpy, win->xwin); |
| 231 | 253 | | XFlush(e->dpy); |
| @@ -303,8 +325,7 @@ bool win_moveresize(win_t *win, int x, int y, unsigned int w, unsigned int h) |
| 303 | 325 | | win->w = w; |
| 304 | 326 | | win->h = h - win->bar.h; |
| 305 | 327 | | |
| 306 | | − | if (options->fixed_win) |
| 307 | | − | win_set_sizehints(win); |
| 328 | + | win_update_sizehints(win); |
| 308 | 329 | | |
| 309 | 330 | | XMoveResizeWindow(win->env.dpy, win->xwin, x, y, w, h); |
| 310 | 331 | | |