Skip to content

Commit

Permalink
Don't map icon windows on start and limit wmattributes reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
moetunes committed Aug 1, 2016
1 parent 05543fd commit b6ea3f2
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 16 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
@@ -1,3 +1,6 @@
1/8/16
Dont map icon windows on starts

28/7/16
Added options in rc.conf MINW_W and MINW_H to set the
minumum window size in stacking mode
Expand Down
3 changes: 2 additions & 1 deletion bar.c
Expand Up @@ -52,6 +52,7 @@ void status_bar() {
XSelectInput(dis, sb_area, ButtonPressMask|ExposureMask|EnterWindowMask|LeaveWindowMask);
XChangeWindowAttributes(dis, sb_area, vmask, &setattr);
XMapWindow(dis, sb_area);
XWindowAttributes attr;
XGetWindowAttributes(dis, sb_area, &attr);
total_w = attr.width;
area_sb = XCreatePixmap(dis, root, total_w, sb_height, DefaultDepth(dis, screen));
Expand Down Expand Up @@ -203,7 +204,7 @@ void update_output(unsigned int messg) {
text_length += 1;
output[text_length] = '\0';
}
XFree(win_name);
if(win_name) XFree(win_name);

for(n=0;n<text_length;++n) {
while(output[n] == '&') {
Expand Down
12 changes: 7 additions & 5 deletions events.c
Expand Up @@ -32,6 +32,7 @@ void maprequest(XEvent *e) {
}

void map_window(Window neww) {
XWindowAttributes attr;
if(XGetWindowAttributes(dis, neww, &attr) == 0) return;
if(attr.override_redirect == True) return;
if(check_dock(neww) == 0) {
Expand Down Expand Up @@ -263,7 +264,7 @@ void buttonpress(XEvent *e) {
XGrabPointer(dis, ev->subwindow, True,
PointerMotionMask|ButtonReleaseMask, GrabModeAsync,
GrabModeAsync, None, None, CurrentTime);
XGetWindowAttributes(dis, ev->subwindow, &attr);
XGetWindowAttributes(dis, ev->subwindow, &mattr);
starter = e->xbutton; doresize = 1;
}

Expand All @@ -286,14 +287,15 @@ void motionnotify(XEvent *e) {
int xdiff = ev->x_root - starter.x_root;
int ydiff = ev->y_root - starter.y_root;
XMoveResizeWindow(dis, ev->window,
attr.x + (starter.button==1 ? xdiff : 0),
attr.y + (starter.button==1 ? ydiff : 0),
MAX(1, attr.width + (starter.button==3 ? xdiff : 0)),
MAX(1, attr.height + (starter.button==3 ? ydiff : 0)));
mattr.x + (starter.button==1 ? xdiff : 0),
mattr.y + (starter.button==1 ? ydiff : 0),
MAX(1, mattr.width + (starter.button==3 ? xdiff : 0)),
MAX(1, mattr.height + (starter.button==3 ? ydiff : 0)));
}

void buttonrelease(XEvent *e) {
client *c;
XWindowAttributes attr;
XButtonEvent *ev = &e->xbutton;

XUngrabPointer(dis, CurrentTime);
Expand Down
1 change: 1 addition & 0 deletions readrc.c
Expand Up @@ -372,6 +372,7 @@ void update_config() {
XSetWindowBorder(dis,sb_area,theme[3].barcolor);
XSetWindowBackground(dis, sb_area, theme[1].barcolor);
XMoveResizeWindow(dis, sb_area, desktops[barmon].x+sb_width, y, desktops[barmon].w-(sb_desks+4)+bdw-lessbar-2*ug_bar,sb_height);
XWindowAttributes attr;
XGetWindowAttributes(dis, sb_area, &attr);
total_w = attr.width;
if(area_sb != 0) {
Expand Down
52 changes: 42 additions & 10 deletions snapwm.c
Expand Up @@ -136,6 +136,7 @@ static int check_dock(Window w);
static void check_start();
static void client_to_desktop(const Arg arg);
static void configurerequest(XEvent *e);
static void cull_windows(Window *windows, unsigned int cnt);
static void destroynotify(XEvent *e);
static void draw_desk(Window win, unsigned int barcolor, unsigned int gc, unsigned int x, char *string, unsigned int len);
static void draw_text(Window win, unsigned int gc, unsigned int x, char *string, unsigned int len);
Expand Down Expand Up @@ -231,8 +232,8 @@ static client *head, *current, *focus;
static char font_list[256], buffer[256], dummy[256];
static char RC_FILE[100], KEY_FILE[100], APPS_FILE[100];
static char winname[101];
static Atom alphaatom, wm_delete_window, wm_state, protos, *protocols, dockatom, typeatom;
static XWindowAttributes attr;
static Atom alphaatom, wm_delete_window, protos, *protocols, dockatom, typeatom;
static XWindowAttributes mattr; // For motionnotify events
static XButtonEvent starter;
static Arg barrtclkarg;

Expand Down Expand Up @@ -1023,6 +1024,7 @@ void grabkeys() {
void warp_pointer() {
// Move cursor to the center of the current window
if(followmouse != 0) return;
XWindowAttributes attr;
if(dowarp < 1 && current != NULL) {
XGetWindowAttributes(dis, current->win, &attr);
XWarpPointer(dis, None, current->win, 0, 0, 0, 0, attr.width/2, attr.height/2);
Expand All @@ -1046,7 +1048,7 @@ int check_dock(Window w) {
for(j=0; j<count; j++)
if(type[j] == dockatom) ret = 0;
}
XFree(temp);
if(temp) XFree(temp);
}
return ret;
}
Expand All @@ -1056,7 +1058,7 @@ void kill_client() {
Window w = focus->win;
kill_client_now(w);
if(w) return;
remove_client(focus, 0);
if(focus != NULL) remove_client(focus, 0);
update_current();
if(STATUS_BAR == 0) update_bar();
}
Expand All @@ -1078,7 +1080,7 @@ void kill_client_now(Window w) {
}
}
} else XKillClient(dis, w);
XFree(protocols);
if(protocols) XFree(protocols);
}

void quit() {
Expand Down Expand Up @@ -1148,15 +1150,46 @@ void logger(const char* e) {
fflush(stderr);
}

void cull_windows(Window *windows, unsigned int cnt) {
unsigned int i, j;
XWindowAttributes attr;

for(i=0;i<cnt;++i) {
if(XGetWindowAttributes(dis, windows[i], &attr) == 0) {
windows[i] = None;
continue;
}
if((attr.map_state != IsViewable && attr.map_state != IsUnmapped) ||
attr.override_redirect == True || attr.class == InputOnly){
windows[i] = None;
continue;
}

XWMHints *wmhints = XGetWMHints(dis, windows[i]);
if (wmhints) {
if (wmhints->flags & IconWindowHint) {
if(windows[i] != wmhints->icon_window) {
for(j=0;j<cnt;++j) {
if(windows[j] == wmhints->icon_window)
windows[j] = None;
}
}
}
XFree(wmhints);
}
}
}

void check_start() {
unsigned int i, num;
Window w1, *tree = NULL;

if(XQueryTree(dis, root, &w1, &w1, &tree, &num) == 0) return;
for(i=0;i<num;i++) {
if(XGetWindowAttributes(dis, tree[i], &attr) == 0) continue;
if(attr.map_state != IsViewable && attr.map_state != IsUnmapped) continue;
if(attr.class != InputOnly) map_window(tree[i]);
cull_windows(tree, num);
for(i=num;i>0;--i) {
if(tree[i-1] != None)
XUnmapWindow(dis, tree[i]);
map_window(tree[i-1]);
}

if(tree) XFree(tree);
Expand Down Expand Up @@ -1206,7 +1239,6 @@ void init_start() {
alphaatom = XInternAtom(dis, "_NET_WM_WINDOW_OPACITY", False);
wm_delete_window = XInternAtom(dis, "WM_DELETE_WINDOW", False);
protos = XInternAtom(dis, "WM_PROTOCOLS", False);
wm_state = XInternAtom(dis, "WM_STATE", False);
typeatom = XInternAtom(dis, "_NET_WM_WINDOW_TYPE", False);
dockatom = XInternAtom(dis, "_NET_WM_WINDOW_TYPE_DOCK", False);
// To catch maprequest and destroynotify (if other wm running)
Expand Down

0 comments on commit b6ea3f2

Please sign in to comment.