From ddf64e9db2fdd732aab0c5413f8c162c371034eb Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 26 Oct 2007 18:23:15 +0200 Subject: [PATCH] grab some window function from client.c and move them in window.c --- Makefile | 2 +- awesome.c | 1 + client.c | 84 +-------------------------------------------- client.h | 2 -- event.c | 1 + window.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ window.h | 33 ++++++++++++++++++ 7 files changed, 138 insertions(+), 86 deletions(-) create mode 100644 window.c create mode 100644 window.h diff --git a/Makefile b/Makefile index 8fd08c92..05bf3986 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ include config.mk -SRC = client.c draw.c event.c layout.c awesome.c tag.c util.c config.c screen.c statusbar.c uicb.c tab.c +SRC = client.c draw.c event.c layout.c awesome.c tag.c util.c config.c screen.c statusbar.c uicb.c tab.c window.c OBJ = ${SRC:.c=.o} ${LAYOUTS:.c=.o} all: options awesome diff --git a/awesome.c b/awesome.c index 15a1830d..a17bc767 100644 --- a/awesome.c +++ b/awesome.c @@ -45,6 +45,7 @@ #include "util.h" #include "statusbar.h" #include "uicb.h" +#include "window.h" #define CONTROL_FIFO_PATH ".awesome_ctl" #define CONTROL_UNIX_SOCKET_PATH ".awesome_so_ctl" diff --git a/client.c b/client.c index 9db3dbf5..772b228c 100644 --- a/client.c +++ b/client.c @@ -21,7 +21,6 @@ #include #include -#include #include #include "screen.h" @@ -31,6 +30,7 @@ #include "tag.h" #include "util.h" #include "statusbar.h" +#include "window.h" #include "layouts/floating.h" /** Get a Client by its window @@ -159,42 +159,6 @@ isprotodel(Display *disp, Window win) return ret; } -/** Set client WM_STATE property - * \param c the client - * \param state no idea - */ -static void -window_setstate(Display *disp, Window win, long state) -{ - long data[] = { state, None }; - - XChangeProperty(disp, win, XInternAtom(disp, "WM_STATE", False), - XInternAtom(disp, "WM_STATE", False), 32, - PropModeReplace, (unsigned char *) data, 2); -} - -/** Set client transparency using composite - * \param c client - * \param opacity opacity percentage - */ -static void -window_settrans(Display *disp, Window win, double opacity) -{ - unsigned int real_opacity = 0xffffffff; - - if(opacity >= 0 && opacity <= 100) - { - real_opacity = ((opacity / 100.0) * 0xffffffff); - XChangeProperty(disp, win, - XInternAtom(disp, "_NET_WM_WINDOW_OPACITY", False), - XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &real_opacity, 1L); - } - else - XDeleteProperty(disp, win, XInternAtom(disp, "_NET_WM_WINDOW_OPACITY", False)); - - XSync(disp, False); -} - /** Swap two client in the linked list clients * \param c1 first client * \param c2 second client @@ -245,52 +209,6 @@ ban(Client * c) window_setstate(c->display, c->win, IconicState); } -/** Configure client - * \param c the client - */ -void -window_configure(Display *disp, Window win, int x, int y, int w, int h, int border) -{ - XConfigureEvent ce; - - ce.type = ConfigureNotify; - ce.display = disp; - ce.event = win; - ce.window = win; - ce.x = x; - ce.y = y; - ce.width = w; - ce.height = h; - ce.border_width = border; - ce.above = None; - ce.override_redirect = False; - XSendEvent(disp, win, False, StructureNotifyMask, (XEvent *) & ce); -} - -/** Get a window state (WM_STATE) - * \param disp Display ref - * \param w Client window - * \return state - */ -long -window_getstate(Display *disp, Window w) -{ - int format, status; - long result = -1; - unsigned char *p = NULL; - unsigned long n, extra; - Atom real; - status = XGetWindowProperty(disp, w, XInternAtom(disp, "WM_STATE", False), - 0L, 2L, False, XInternAtom(disp, "WM_STATE", False), - &real, &format, &n, &extra, (unsigned char **) &p); - if(status != Success) - return -1; - if(n != 0) - result = *p; - p_delete(&p); - return result; -} - /** Attach client after another one * \param client to attach to * \param c the client diff --git a/client.h b/client.h index 291e1283..8ca84130 100644 --- a/client.h +++ b/client.h @@ -33,8 +33,6 @@ inline void client_attach(Client **, Client *); inline void client_detach(Client **, Client *); void client_reattach_after(Client *, Client *); void ban(Client *); -void window_configure(Display *, Window, int, int, int, int, int); -long window_getstate(Display *, Window); void focus(Client *, Bool, awesome_config *); void manage(Window, XWindowAttributes *, awesome_config *); void resize(Client *, int, int, int, int, awesome_config *, Bool); diff --git a/event.c b/event.c index 2752b9db..9446eea1 100644 --- a/event.c +++ b/event.c @@ -32,6 +32,7 @@ #include "draw.h" #include "statusbar.h" #include "util.h" +#include "window.h" #include "layouts/tile.h" #include "layouts/floating.h" diff --git a/window.c b/window.c new file mode 100644 index 00000000..a206fd3a --- /dev/null +++ b/window.c @@ -0,0 +1,101 @@ +/* + * window.c - window handling functions + * + * Copyright © 2007 Julien Danjou + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include + +#include "window.h" +#include "util.h" + +/** Set client WM_STATE property + * \param disp Display ref + * \param win Window + * \param state state + */ +int +window_setstate(Display *disp, Window win, long state) +{ + long data[] = { state, None }; + + return XChangeProperty(disp, win, XInternAtom(disp, "WM_STATE", False), + XInternAtom(disp, "WM_STATE", False), 32, + PropModeReplace, (unsigned char *) data, 2); +} + +/** Get a window state (WM_STATE) + * \param disp Display ref + * \param w Client window + * \return state + */ +long +window_getstate(Display *disp, Window w) +{ + int format; + long result = -1; + unsigned char *p = NULL; + unsigned long n, extra; + Atom real; + if(XGetWindowProperty(disp, w, XInternAtom(disp, "WM_STATE", False), + 0L, 2L, False, XInternAtom(disp, "WM_STATE", False), + &real, &format, &n, &extra, (unsigned char **) &p) != Success) + return -1; + if(n != 0) + result = *p; + p_delete(&p); + return result; +} + +Status +window_configure(Display *disp, Window win, int x, int y, int w, int h, int border) +{ + XConfigureEvent ce; + + ce.type = ConfigureNotify; + ce.display = disp; + ce.event = win; + ce.window = win; + ce.x = x; + ce.y = y; + ce.width = w; + ce.height = h; + ce.border_width = border; + ce.above = None; + ce.override_redirect = False; + return XSendEvent(disp, win, False, StructureNotifyMask, (XEvent *) & ce); +} + +void +window_settrans(Display *disp, Window win, double opacity) +{ + unsigned int real_opacity = 0xffffffff; + + if(opacity >= 0 && opacity <= 100) + { + real_opacity = ((opacity / 100.0) * 0xffffffff); + XChangeProperty(disp, win, XInternAtom(disp, "_NET_WM_WINDOW_OPACITY", False), + XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &real_opacity, 1L); + } + else + XDeleteProperty(disp, win, XInternAtom(disp, "_NET_WM_WINDOW_OPACITY", False)); + + XSync(disp, False); +} + +// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 diff --git a/window.h b/window.h new file mode 100644 index 00000000..b510365e --- /dev/null +++ b/window.h @@ -0,0 +1,33 @@ +/* + * window.h - window handling functions header + * + * Copyright © 2007 Julien Danjou + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#ifndef AWESOME_WINDOW_H +#define AWESOME_WINDOW_H + +#include + +int window_setstate(Display *, Window, long); +long window_getstate(Display *, Window); +Status window_configure(Display *, Window, int, int, int, int, int); +void window_settrans(Display *, Window, double); + +#endif +// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99