aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--main.c1
-rw-r--r--window.c73
-rw-r--r--window.h3
4 files changed, 51 insertions, 28 deletions
diff --git a/Makefile b/Makefile
index ef3bd79..1c7a95d 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-VERSION = git-20130208
+VERSION = git-20130209
PREFIX = /usr/local
MANPREFIX = $(PREFIX)/share/man
diff --git a/main.c b/main.c
index 7609151..9ff3c1e 100644
--- a/main.c
+++ b/main.c
@@ -26,7 +26,6 @@
#include <sys/select.h>
#include <sys/stat.h>
#include <sys/time.h>
-#include <X11/Xutil.h>
#include <X11/keysym.h>
#include "types.h"
diff --git a/window.c b/window.c
index e4ae641..0b1ce65 100644
--- a/window.c
+++ b/window.c
@@ -21,7 +21,6 @@
#include <string.h>
#include <locale.h>
-#include <X11/Xutil.h>
#include <X11/cursorfont.h>
#include "options.h"
@@ -127,6 +126,12 @@ void win_init(win_t *win)
win->bar.bgcol = win_alloc_color(win, BAR_BG_COLOR);
win->bar.fgcol = win_alloc_color(win, BAR_FG_COLOR);
+ win->sizehints.flags = PWinGravity;
+ win->sizehints.win_gravity = NorthWestGravity;
+ if (options->fixed_win)
+ /* actual min/max values set in win_update_sizehints() */
+ win->sizehints.flags |= PMinSize | PMaxSize;
+
if (setlocale(LC_CTYPE, "") == NULL || XSupportsLocale() == 0)
warn("no locale support");
@@ -135,19 +140,24 @@ void win_init(win_t *win)
wm_delete_win = XInternAtom(e->dpy, "WM_DELETE_WINDOW", False);
}
-void win_set_sizehints(win_t *win)
+void win_update_sizehints(win_t *win)
{
- XSizeHints sizehints;
-
if (win == NULL || win->xwin == None)
return;
- sizehints.flags = PMinSize | PMaxSize;
- sizehints.min_width = win->w;
- sizehints.max_width = win->w;
- sizehints.min_height = win->h + win->bar.h;
- sizehints.max_height = win->h + win->bar.h;
- XSetWMNormalHints(win->env.dpy, win->xwin, &sizehints);
+ if ((win->sizehints.flags & USSize) != 0) {
+ win->sizehints.width = win->w;
+ win->sizehints.height = win->h;
+ }
+ if ((win->sizehints.flags & USPosition) != 0) {
+ win->sizehints.x = win->x;
+ win->sizehints.y = win->y;
+ }
+ if (options->fixed_win) {
+ win->sizehints.min_width = win->sizehints.max_width = win->w;
+ win->sizehints.min_height = win->sizehints.max_height = win->h + win->bar.h;
+ }
+ XSetWMNormalHints(win->env.dpy, win->xwin, &win->sizehints);
}
void win_open(win_t *win)
@@ -170,22 +180,35 @@ void win_open(win_t *win)
else
gmask = XParseGeometry(options->geometry, &win->x, &win->y,
&win->w, &win->h);
- if ((gmask & WidthValue) == 0)
+ if ((gmask & WidthValue) != 0)
+ win->sizehints.flags |= USSize;
+ else
win->w = WIN_WIDTH;
- if (win->w > e->scrw)
- win->w = e->scrw;
- if ((gmask & HeightValue) == 0)
+ if ((gmask & HeightValue) != 0)
+ win->sizehints.flags |= USSize;
+ else
win->h = WIN_HEIGHT;
- if (win->h > e->scrh)
- win->h = e->scrh;
- if ((gmask & XValue) == 0)
+ if ((gmask & XValue) != 0) {
+ if ((gmask & XNegative) != 0) {
+ win->x += e->scrw - win->w;
+ win->sizehints.win_gravity = NorthEastGravity;
+ }
+ win->sizehints.flags |= USPosition;
+ } else {
win->x = (e->scrw - win->w) / 2;
- else if ((gmask & XNegative) != 0)
- win->x += e->scrw - win->w;
- if ((gmask & YValue) == 0)
+ }
+ if ((gmask & YValue) != 0) {
+ if ((gmask & YNegative) != 0) {
+ win->y += e->scrh - win->h;
+ if (win->sizehints.win_gravity == NorthEastGravity)
+ win->sizehints.win_gravity = SouthEastGravity;
+ else
+ win->sizehints.win_gravity = SouthWestGravity;
+ }
+ win->sizehints.flags |= USPosition;
+ } else {
win->y = (e->scrh - win->h) / 2;
- else if ((gmask & YNegative) != 0)
- win->y += e->scrh - win->h;
+ }
win->xwin = XCreateWindow(e->dpy, RootWindow(e->dpy, e->scr),
win->x, win->y, win->w, win->h, 0,
@@ -224,8 +247,7 @@ void win_open(win_t *win)
win->h -= win->bar.h;
}
- if (options->fixed_win)
- win_set_sizehints(win);
+ win_update_sizehints(win);
XMapWindow(e->dpy, win->xwin);
XFlush(e->dpy);
@@ -303,8 +325,7 @@ bool win_moveresize(win_t *win, int x, int y, unsigned int w, unsigned int h)
win->w = w;
win->h = h - win->bar.h;
- if (options->fixed_win)
- win_set_sizehints(win);
+ win_update_sizehints(win);
XMoveResizeWindow(win->env.dpy, win->xwin, x, y, w, h);
diff --git a/window.h b/window.h
index e8ce344..dfb39aa 100644
--- a/window.h
+++ b/window.h
@@ -20,6 +20,7 @@
#define WINDOW_H
#include <X11/Xlib.h>
+#include <X11/Xutil.h>
#include "types.h"
@@ -48,6 +49,8 @@ typedef struct {
unsigned int h; /* = win height - bar height */
unsigned int bw;
+ XSizeHints sizehints;
+
bool fullscreen;
struct {