From 0e0a1c27fa36a7d09a6a075501512f023e0ada14 Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Tue, 29 Apr 2014 20:54:55 +0200 Subject: [PATCH] Better error handling when getting sizehints fails --- ioncore/clientwin.c | 8 ++++++-- ioncore/clientwin.h | 7 ++++++- ioncore/eventh.c | 5 ++++- ioncore/xwindow.c | 13 ++++++++----- ioncore/xwindow.h | 7 ++++++- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/ioncore/clientwin.c b/ioncore/clientwin.c index 9d126dc3..eef10629 100644 --- a/ioncore/clientwin.c +++ b/ioncore/clientwin.c @@ -154,12 +154,14 @@ static void clientwin_get_winprops(WClientWin *cwin) } -void clientwin_get_size_hints(WClientWin *cwin) +int clientwin_get_size_hints(WClientWin *cwin) { XSizeHints tmp=cwin->size_hints; + int ret; - xwindow_get_sizehints(cwin->win, &(cwin->size_hints)); + ret=xwindow_get_sizehints(cwin->win, &(cwin->size_hints)); + /** Apply winprop settings (even when xwindow_get_sizehints failed) */ if(cwin->flags&CLIENTWIN_PROP_I_MAXSIZE){ cwin->size_hints.flags&=~PMaxSize; }else if(cwin->flags&CLIENTWIN_PROP_MAXSIZE){ @@ -191,6 +193,8 @@ void clientwin_get_size_hints(WClientWin *cwin) cwin->size_hints.height_inc=tmp.height_inc; cwin->size_hints.flags|=PResizeInc; } + + return ret; } void clientwin_get_input_wm_hint(WClientWin *cwin) diff --git a/ioncore/clientwin.h b/ioncore/clientwin.h index 9c66f78b..09c38f43 100644 --- a/ioncore/clientwin.h +++ b/ioncore/clientwin.h @@ -67,7 +67,12 @@ DECLCLASS(WClientWin){ extern void clientwin_get_protocols(WClientWin *cwin); -extern void clientwin_get_size_hints(WClientWin *cwin); +/** + * On failure, sets cwin->sizehints based on winprops and returns -1 + * On success, sets cwin->sizehints based on WM_NORMAL_HINTS and winprops + * and returns a nonnegative value. + */ +extern int clientwin_get_size_hints(WClientWin *cwin); extern void clientwin_unmapped(WClientWin *cwin); extern void clientwin_destroyed(WClientWin *cwin); extern void clientwin_kill(WClientWin *cwin); diff --git a/ioncore/eventh.c b/ioncore/eventh.c index d4b82516..7f58c4bf 100644 --- a/ioncore/eventh.c +++ b/ioncore/eventh.c @@ -28,6 +28,7 @@ #include "activity.h" #include "netwm.h" #include "xwindow.h" +#include "log.h" /*{{{ ioncore_handle_event */ @@ -235,7 +236,9 @@ void ioncore_handle_property(const XPropertyEvent *ev) } XFree(hints); }else if(ev->atom==XA_WM_NORMAL_HINTS){ - clientwin_get_size_hints(cwin); + int ret=clientwin_get_size_hints(cwin); + if(ret<0&&ev->state==PropertyNewValue) + LOG(WARN, GENERAL, "Retrieving sizehints failed for cwin '%s'", cwin->region.ni.name); }else if(ev->atom==XA_WM_NAME){ if(!(cwin->flags&CLIENTWIN_USE_NET_WM_NAME)) clientwin_get_set_name(cwin); diff --git a/ioncore/xwindow.c b/ioncore/xwindow.c index e193f501..f334a292 100644 --- a/ioncore/xwindow.c +++ b/ioncore/xwindow.c @@ -130,14 +130,17 @@ bool xwindow_pointer_pos(Window rel, int *px, int *py) /*{{{ Size hints */ -void xwindow_get_sizehints(Window win, XSizeHints *hints) +int xwindow_get_sizehints(Window win, XSizeHints *hints) { long supplied=0; - memset(hints, 0, sizeof(*hints)); - XGetWMNormalHints(ioncore_g.dpy, win, hints, &supplied); - - xsizehints_sanity_adjust(hints); + if (XGetWMNormalHints(ioncore_g.dpy, win, hints, &supplied)!=0){ + xsizehints_sanity_adjust(hints); + return 0; + }else{ + memset(hints, 0, sizeof(*hints)); + return -1; + } } diff --git a/ioncore/xwindow.h b/ioncore/xwindow.h index 30e34dc2..0f1a823f 100644 --- a/ioncore/xwindow.h +++ b/ioncore/xwindow.h @@ -27,7 +27,12 @@ extern void xwindow_do_set_focus(Window win); extern void xwindow_set_cursor(Window win, int cursor); -extern void xwindow_get_sizehints(Window win, XSizeHints *hints); +/** + * On failure, clears winprops and returns -1. + * On success, sets hints according to the window's WM_NORMAL_HINTS and + * returns a nonnegative value. + */ +extern int xwindow_get_sizehints(Window win, XSizeHints *hints); extern bool xwindow_pointer_pos(Window rel, int *px, int *py); -- 2.11.4.GIT