| @@ -124,6 +124,9 @@ void win_init(win_t *win) { |
| 124 | 124 | | win->bar.bgcol = win_alloc_color(win, BAR_BG_COLOR); |
| 125 | 125 | | win->bar.fgcol = win_alloc_color(win, BAR_FG_COLOR); |
| 126 | 126 | | |
| 127 | + | win->sizehints.flags = PWinGravity; |
| 128 | + | win->sizehints.win_gravity = NorthWestGravity; |
| 129 | + | |
| 127 | 130 | | if (setlocale(LC_CTYPE, "") == NULL || XSupportsLocale() == 0) |
| 128 | 131 | | warn("no locale support"); |
| 129 | 132 | | |
| @@ -133,17 +136,24 @@ void win_init(win_t *win) { |
| 133 | 136 | | } |
| 134 | 137 | | |
| 135 | 138 | | void win_set_sizehints(win_t *win) { |
| 136 | | − | XSizeHints sizehints; |
| 137 | 139 | | |
| 138 | 140 | | if (win == NULL || win->xwin == None) |
| 139 | 141 | | return; |
| 140 | 142 | | |
| 141 | | − | sizehints.flags = PMinSize | PMaxSize; |
| 142 | | − | sizehints.min_width = win->w; |
| 143 | | − | sizehints.max_width = win->w; |
| 144 | | − | sizehints.min_height = win->h + win->bar.h; |
| 145 | | − | sizehints.max_height = win->h + win->bar.h; |
| 146 | | − | XSetWMNormalHints(win->env.dpy, win->xwin, &sizehints); |
| 143 | + | if ((win->sizehints.flags & PMinSize) == 1) { |
| 144 | + | win->sizehints.min_width = win->w; |
| 145 | + | win->sizehints.min_height = win->h + win->bar.h; |
| 146 | + | } |
| 147 | + | if ((win->sizehints.flags & PMaxSize) == 1) { |
| 148 | + | win->sizehints.max_width = win->w; |
| 149 | + | win->sizehints.max_height = win->h + win->bar.h; |
| 150 | + | } |
| 151 | + | if ((win->sizehints.flags & USPosition) == 1) { |
| 152 | + | win->sizehints.x = win->x; |
| 153 | + | win->sizehints.y = win->y; |
| 154 | + | } |
| 155 | + | |
| 156 | + | XSetWMNormalHints(win->env.dpy, win->xwin, &win->sizehints); |
| 147 | 157 | | } |
| 148 | 158 | | |
| 149 | 159 | | void win_open(win_t *win) { |
| @@ -165,22 +175,42 @@ void win_open(win_t *win) { |
| 165 | 175 | | else |
| 166 | 176 | | gmask = XParseGeometry(options->geometry, &win->x, &win->y, |
| 167 | 177 | | &win->w, &win->h); |
| 168 | | − | if ((gmask & WidthValue) == 0) |
| 178 | + | if ((gmask & WidthValue) == 0) { |
| 169 | 179 | | win->w = WIN_WIDTH; |
| 180 | + | } else { |
| 181 | + | win->sizehints.flags |= USSize; |
| 182 | + | } |
| 170 | 183 | | if (win->w > e->scrw) |
| 171 | 184 | | win->w = e->scrw; |
| 172 | | − | if ((gmask & HeightValue) == 0) |
| 185 | + | if ((gmask & HeightValue) == 0) { |
| 173 | 186 | | win->h = WIN_HEIGHT; |
| 187 | + | } else { |
| 188 | + | win->sizehints.flags |= USSize; |
| 189 | + | } |
| 174 | 190 | | if (win->h > e->scrh) |
| 175 | 191 | | win->h = e->scrh; |
| 176 | | − | if ((gmask & XValue) == 0) |
| 192 | + | if ((gmask & XValue) == 0) { |
| 177 | 193 | | win->x = (e->scrw - win->w) / 2; |
| 178 | | − | else if ((gmask & XNegative) != 0) |
| 179 | | − | win->x += e->scrw - win->w; |
| 180 | | − | if ((gmask & YValue) == 0) |
| 194 | + | } else { |
| 195 | + | if ((gmask & XNegative) != 0) { |
| 196 | + | win->x += e->scrw - win->w; |
| 197 | + | win->sizehints.win_gravity = NorthEastGravity; |
| 198 | + | } |
| 199 | + | win->sizehints.flags |= USPosition; |
| 200 | + | } |
| 201 | + | if ((gmask & YValue) == 0) { |
| 181 | 202 | | win->y = (e->scrh - win->h) / 2; |
| 182 | | − | else if ((gmask & YNegative) != 0) |
| 183 | | − | win->y += e->scrh - win->h; |
| 203 | + | } else { |
| 204 | + | if ((gmask & YNegative) != 0) { |
| 205 | + | win->y += e->scrh - win->h; |
| 206 | + | if (win->sizehints.win_gravity == NorthEastGravity) { |
| 207 | + | win->sizehints.win_gravity = SouthEastGravity; |
| 208 | + | } else { |
| 209 | + | win->sizehints.win_gravity = SouthWestGravity; |
| 210 | + | } |
| 211 | + | } |
| 212 | + | win->sizehints.flags |= USPosition; |
| 213 | + | } |
| 184 | 214 | | |
| 185 | 215 | | win->xwin = XCreateWindow(e->dpy, RootWindow(e->dpy, e->scr), |
| 186 | 216 | | win->x, win->y, win->w, win->h, 0, |
| @@ -220,7 +250,9 @@ void win_open(win_t *win) { |
| 220 | 250 | | } |
| 221 | 251 | | |
| 222 | 252 | | if (options->fixed_win) |
| 223 | | − | win_set_sizehints(win); |
| 253 | + | win->sizehints.flags |= PMinSize | PMaxSize; |
| 254 | + | |
| 255 | + | win_set_sizehints(win); |
| 224 | 256 | | |
| 225 | 257 | | XMapWindow(e->dpy, win->xwin); |
| 226 | 258 | | XFlush(e->dpy); |
| @@ -291,8 +323,8 @@ bool win_moveresize(win_t *win, int x, int y, unsigned int w, unsigned int h) { |
| 291 | 323 | | win->w = w; |
| 292 | 324 | | win->h = h - win->bar.h; |
| 293 | 325 | | |
| 294 | | − | if (options->fixed_win) |
| 295 | | − | win_set_sizehints(win); |
| 326 | + | |
| 327 | + | win_set_sizehints(win); |
| 296 | 328 | | |
| 297 | 329 | | XMoveResizeWindow(win->env.dpy, win->xwin, x, y, w, h); |
| 298 | 330 | | |