| @@ -127,6 +127,9 @@ void win_init(win_t *win) |
| 127 | 127 | | win->bar.bgcol = win_alloc_color(win, BAR_BG_COLOR); |
| 128 | 128 | | win->bar.fgcol = win_alloc_color(win, BAR_FG_COLOR); |
| 129 | 129 | | |
| 130 | + | win->sizehints.flags = PWinGravity; |
| 131 | + | win->sizehints.win_gravity = NorthWestGravity; |
| 132 | + | |
| 130 | 133 | | if (setlocale(LC_CTYPE, "") == NULL || XSupportsLocale() == 0) |
| 131 | 134 | | warn("no locale support"); |
| 132 | 135 | | |
| @@ -137,17 +140,24 @@ void win_init(win_t *win) |
| 137 | 140 | | |
| 138 | 141 | | void win_set_sizehints(win_t *win) |
| 139 | 142 | | { |
| 140 | | − | XSizeHints sizehints; |
| 141 | 143 | | |
| 142 | 144 | | if (win == NULL || win->xwin == None) |
| 143 | 145 | | return; |
| 144 | 146 | | |
| 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); |
| 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; |
| 154 | + | } |
| 155 | + | if ((win->sizehints.flags & USPosition) == 1) { |
| 156 | + | win->sizehints.x = win->x; |
| 157 | + | win->sizehints.y = win->y; |
| 158 | + | } |
| 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,42 @@ 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) { |
| 174 | 184 | | win->w = WIN_WIDTH; |
| 185 | + | } else { |
| 186 | + | win->sizehints.flags |= USSize; |
| 187 | + | } |
| 175 | 188 | | if (win->w > e->scrw) |
| 176 | 189 | | win->w = e->scrw; |
| 177 | | − | if ((gmask & HeightValue) == 0) |
| 190 | + | if ((gmask & HeightValue) == 0) { |
| 178 | 191 | | win->h = WIN_HEIGHT; |
| 192 | + | } else { |
| 193 | + | win->sizehints.flags |= USSize; |
| 194 | + | } |
| 179 | 195 | | if (win->h > e->scrh) |
| 180 | 196 | | win->h = e->scrh; |
| 181 | | − | if ((gmask & XValue) == 0) |
| 197 | + | if ((gmask & XValue) == 0) { |
| 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 | + | } else { |
| 200 | + | if ((gmask & XNegative) != 0) { |
| 201 | + | win->x += e->scrw - win->w; |
| 202 | + | win->sizehints.win_gravity = NorthEastGravity; |
| 203 | + | } |
| 204 | + | win->sizehints.flags |= USPosition; |
| 205 | + | } |
| 206 | + | if ((gmask & YValue) == 0) { |
| 186 | 207 | | win->y = (e->scrh - win->h) / 2; |
| 187 | | − | else if ((gmask & YNegative) != 0) |
| 188 | | − | win->y += e->scrh - win->h; |
| 208 | + | } else { |
| 209 | + | if ((gmask & YNegative) != 0) { |
| 210 | + | win->y += e->scrh - win->h; |
| 211 | + | if (win->sizehints.win_gravity == NorthEastGravity) { |
| 212 | + | win->sizehints.win_gravity = SouthEastGravity; |
| 213 | + | } else { |
| 214 | + | win->sizehints.win_gravity = SouthWestGravity; |
| 215 | + | } |
| 216 | + | } |
| 217 | + | win->sizehints.flags |= USPosition; |
| 218 | + | } |
| 189 | 219 | | |
| 190 | 220 | | win->xwin = XCreateWindow(e->dpy, RootWindow(e->dpy, e->scr), |
| 191 | 221 | | win->x, win->y, win->w, win->h, 0, |
| @@ -225,7 +255,9 @@ void win_open(win_t *win) |
| 225 | 255 | | } |
| 226 | 256 | | |
| 227 | 257 | | if (options->fixed_win) |
| 228 | | − | win_set_sizehints(win); |
| 258 | + | win->sizehints.flags |= PMinSize | PMaxSize; |
| 259 | + | |
| 260 | + | win_set_sizehints(win); |
| 229 | 261 | | |
| 230 | 262 | | XMapWindow(e->dpy, win->xwin); |
| 231 | 263 | | XFlush(e->dpy); |
| @@ -300,8 +332,8 @@ bool win_moveresize(win_t *win, int x, int y, unsigned int w, unsigned int h) |
| 300 | 332 | | win->w = w; |
| 301 | 333 | | win->h = h - win->bar.h; |
| 302 | 334 | | |
| 303 | | − | if (options->fixed_win) |
| 304 | | − | win_set_sizehints(win); |
| 335 | + | |
| 336 | + | win_set_sizehints(win); |
| 305 | 337 | | |
| 306 | 338 | | XMoveResizeWindow(win->env.dpy, win->xwin, x, y, w, h); |
| 307 | 339 | | |