From c68aa48bc2927b6f74fa24677ed6108dd4b3d061 Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Fri, 13 Feb 2009 23:02:03 +0100 Subject: [PATCH] All: Update !!!! \o/ --- python/.gitignore | 2 - python/libwmfs.c | 210 ------------------------------------------- python/libwmfs.h | 62 ------------- python/screen_func.c | 96 -------------------- python/setup.py | 21 ----- python/tag_func.c | 52 ----------- src/client.c | 2 +- src/config.c | 95 +++++++++++--------- src/event.c | 4 +- src/ewmh.c | 4 +- src/layout.c | 72 +++++++-------- src/structs.h | 2 +- src/util.c | 22 ++++- src/wmfs.c | 28 +++--- src/wmfs.h | 18 ++-- 15 files changed, 138 insertions(+), 552 deletions(-) delete mode 100644 python/.gitignore delete mode 100644 python/libwmfs.c delete mode 100644 python/libwmfs.h delete mode 100644 python/screen_func.c delete mode 100644 python/setup.py delete mode 100644 python/tag_func.c diff --git a/python/.gitignore b/python/.gitignore deleted file mode 100644 index 5975d97..0000000 --- a/python/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*~ -build/ diff --git a/python/libwmfs.c b/python/libwmfs.c deleted file mode 100644 index bfd79dc..0000000 --- a/python/libwmfs.c +++ /dev/null @@ -1,210 +0,0 @@ -/* - * libwmfs.c - * Copyright © 2008 Martin Duquesnoy - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of the nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "libwmfs.h" - -/* Set Methods */ -static PyMethodDef WmfsMethods[] = -{ - {"init", wmfs_init, METH_VARARGS, "Init wmfs module"}, - {"uicb", wmfs_uicb, METH_VARARGS, "Exec an uicb function"}, - {"statustext", wmfs_statustext, METH_VARARGS, "Wrote in the statustext"}, - {"tag_set", wmfs_tag_set, METH_VARARGS, "Set a tag"}, - {"screen_set", wmfs_screen_set, METH_VARARGS, "Set the selected screen"}, - {"screen_get_current", wmfs_screen_get_cur, METH_VARARGS, "Get the current screen number"}, - {"screen_count", wmfs_screen_count, METH_VARARGS, "Get how many screen there are"}, - {"spawn", wmfs_spawn, METH_VARARGS, "Execute a command"}, - /* Sentinel */ - {NULL, NULL, 0, NULL} -}; - -void -send_client_message(char* atom_name, long data_l[5]) -{ - XEvent ev; - int i; - - ev.xclient.type = ClientMessage; - ev.xclient.serial = 0; - ev.xclient.send_event = True; - ev.xclient.message_type = ATOM(atom_name); - ev.xclient.window = ROOT; - ev.xclient.format = 32; - - for(i = 0; i < 6; ++i) - ev.xclient.data.l[i] = data_l[i]; - - XSendEvent(dpy, ROOT, False, SubstructureRedirectMask|SubstructureNotifyMask, &ev); - XSync(dpy, False); - - return; -} - -PyObject* -wmfs_init(PyObject *self, PyObject *args) -{ - Atom rt; - int rf; - unsigned long ir, il; - unsigned char *ret; - - PyArg_ParseTuple(args, ""); - - if(!(dpy = XOpenDisplay(NULL))) - { - fprintf(stderr, "wmfs-control: cannot open X server.\n"); - exit(EXIT_FAILURE); - } - - /* Check if wmfs is running */ - XGetWindowProperty(dpy, ROOT, ATOM("_WMFS_RUNNING"), 0L, 4096, - False, XA_CARDINAL, &rt, &rf, &ir, &il, &ret); - - /* Else, exit. */ - if(!ret) - { - XFree(ret); - PyErr_SetString(WmfsInitError, "WMFS not running?"); - return NULL; - } - XFree(ret); - - inited = True; - - Py_INCREF(Py_None); - - return Py_None; -} - -PyObject* -wmfs_uicb(PyObject *self, PyObject *args) -{ - long data[5]; - char *func; - char *cmd; - - if(!PyArg_ParseTuple(args, "ss", &func, &cmd)) - return NULL; - - data[4] = True; - - XChangeProperty(dpy, ROOT, ATOM("_WMFS_FUNCTION"), ATOM("UTF8_STRING"), - 8, PropModeReplace, (unsigned char*)func, strlen(func)); - - XChangeProperty(dpy, ROOT, ATOM("_WMFS_CMD"), ATOM("UTF8_STRING"), - 8, PropModeReplace, (unsigned char*)cmd, strlen(cmd)); - - send_client_message("_WMFS_FUNCTION", data); - - Py_INCREF(Py_None); - - return Py_None; -} - - -PyObject* -wmfs_statustext(PyObject *self, PyObject *args) -{ - char *arg; - long data[5]; - - if(!PyArg_ParseTuple(args, "s", &arg)) - return NULL; - - data[4] = True; - - XChangeProperty(dpy, ROOT, ATOM("_WMFS_STATUSTEXT"), ATOM("UTF8_STRING"), - 8, PropModeReplace, (unsigned char*)arg, strlen(arg)); - - send_client_message("_WMFS_STATUSTEXT", data); - - Py_INCREF(Py_None); - - return Py_None; -} - -PyObject* -wmfs_spawn(PyObject *self, PyObject *args) -{ - char *arg, *sh; - - Py_INCREF(Py_None); - - if(!PyArg_ParseTuple(args, "s", &arg)) - return NULL; - - if(!(sh = getenv("SHELL"))) - sh = "/bin/sh"; - if(!strlen(arg)) - return Py_None; /* Error ? */ - - if(fork() == 0) - { - if(fork() == 0) - { - setsid(); - execl(sh, sh, "-c", arg, (char*)NULL); - } - exit(EXIT_SUCCESS); - } - - return Py_None; -} - - -PyMODINIT_FUNC -initwmfs(void) -{ - PyObject *m = Py_InitModule("wmfs", WmfsMethods); - - if(m == NULL) - return; - - WmfsInitError = PyErr_NewException("wmfs.WmfsInitError", NULL, NULL); - - Py_INCREF(WmfsInitError); - PyModule_AddObject(m, "WmfsInitError", WmfsInitError); -} - -int -main(int argc, char **argv) -{ - Py_SetProgramName(argv[0]); - - /* Initialize the Python interpreter. Required. */ - Py_Initialize(); - - /* Init Module */ - initwmfs(); - - return 0; -} diff --git a/python/libwmfs.h b/python/libwmfs.h deleted file mode 100644 index c6c9411..0000000 --- a/python/libwmfs.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * libwmfs.h - * Copyright © 2008 Martin Duquesnoy - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of the nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include - -#include -#include -#include - -/* Xlib util macro */ -#define ROOT RootWindow(dpy, SCREEN) -#define ATOM(a) XInternAtom(dpy, a, False) -#define SCREEN DefaultScreen(dpy) - -/* Prototypes */ - -/* screen_func.c */ -PyObject* wmfs_screen_set(PyObject *self, PyObject *args); -PyObject* wmfs_screen_get_cur(PyObject *self, PyObject *args); -PyObject* wmfs_screen_count(PyObject *self, PyObject *args); - -/* tag_func.c */ -PyObject* wmfs_tag_set(PyObject *self, PyObject *args); - -/* libwmfs.c */ -PyObject* wmfs_init(PyObject *self, PyObject *args); -PyObject* wmfs_uicb(PyObject *self, PyObject *args); -PyObject* wmfs_statustext(PyObject *self, PyObject *args); -PyObject* wmfs_spawn(PyObject *self, PyObject *args); - -Display *dpy; -static PyObject *WmfsInitError; -Bool inited; diff --git a/python/screen_func.c b/python/screen_func.c deleted file mode 100644 index 8ead8b2..0000000 --- a/python/screen_func.c +++ /dev/null @@ -1,96 +0,0 @@ -/* - * screen_func.c - * Copyright © 2008 Martin Duquesnoy - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of the nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "libwmfs.h" - -PyObject* -wmfs_screen_set(PyObject *self, PyObject *args) -{ - long data[5]; - int arg; - - if(!PyArg_ParseTuple(args, "i", &arg)) - return NULL; - - data[0] = arg; - - send_client_message("_WMFS_SET_SCREEN", data); - - Py_INCREF(Py_None); - - return Py_None; -} - - -PyObject* -wmfs_screen_get_cur(PyObject *self, PyObject *args) -{ - Atom rt; - int rf; - unsigned long ir, il; - unsigned char *ret; - int i = 0; - - PyArg_ParseTuple(args, ""); - - if(XGetWindowProperty(dpy, ROOT, ATOM("_WMFS_CURRENT_SCREEN"), 0L, 4096, - False, XA_CARDINAL, &rt, &rf, &ir, &il, &ret) == Success); - { - i = *(long*)ret; - XFree(ret); - } - - return Py_BuildValue("i", i); -} - -PyObject* -wmfs_screen_count(PyObject *self, PyObject *args) -{ - Atom rt; - int rf; - unsigned long ir, il; - unsigned char *ret; - int i = 1; - - PyArg_ParseTuple(args, ""); - - if(XGetWindowProperty(dpy, ROOT, ATOM("_WMFS_SCREEN_COUNT"), 0L, 4096, - False, XA_CARDINAL, &rt, &rf, &ir, &il, &ret) == Success); - { - i = *(long*)ret; - XFree(ret); - } - - printf("screen count: %i\n", i); - - return Py_BuildValue("i", i); -} diff --git a/python/setup.py b/python/setup.py deleted file mode 100644 index 5aaa498..0000000 --- a/python/setup.py +++ /dev/null @@ -1,21 +0,0 @@ -from distutils.core import setup, Extension - -module1 = Extension('wmfs', - include_dirs = ['/usr/local/include'], - libraries = ['X11'], - library_dirs = ['/usr/local/lib'], - sources = ['screen_func.c', - 'tag_func.c', - 'libwmfs.c']) - -setup (name = 'wmfs', - version = '0.1', - description = 'WMFS client library', - author = 'Martin Duquesnoy', - author_email = '', - url = 'http://wmfs.sangor.net/', - long_description = ''' -This is a control librarie for the WM named WMFS. -''', - ext_modules = [module1]) - diff --git a/python/tag_func.c b/python/tag_func.c deleted file mode 100644 index cec5814..0000000 --- a/python/tag_func.c +++ /dev/null @@ -1,52 +0,0 @@ -3* - * tag_func.c - * Copyright © 2008 Martin Duquesnoy - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of the nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "libwmfs.h" - -PyObject* -wmfs_tag_set(PyObject *self, PyObject *args) -{ - long data[5]; - int arg; - - if(!PyArg_ParseTuple(args, "i", &arg)) - return NULL; - - if(arg >= 0) - data[0] = arg; - - send_client_message("_NET_CURRENT_DESKTOP", data); - - Py_INCREF(Py_None); - - return Py_None; -} diff --git a/src/client.c b/src/client.c index 3679715..8055494 100644 --- a/src/client.c +++ b/src/client.c @@ -238,7 +238,7 @@ client_get_name(Client *c) { XFetchName(dpy, c->win, &(c->title)); if(!c->title) - c->title = strdup("WMFS"); + c->title = _strdup("WMFS"); frame_update(c); diff --git a/src/config.c b/src/config.c index 5b5764b..b07ca1b 100644 --- a/src/config.c +++ b/src/config.c @@ -94,7 +94,7 @@ mouse_section(MouseBinding mb[], cfg_t *cfg, int ns) mb[i].screen = cfg_getint(tmp, "screen"); mb[i].button = char_to_button(cfg_getstr(tmp, "button"), mouse_button_list); mb[i].func = name_to_func(cfg_getstr(tmp, "func"), func_list); - mb[i].cmd = strdup(alias_to_str(cfg_getstr(tmp, "cmd"))); + mb[i].cmd = _strdup(alias_to_str(cfg_getstr(tmp, "cmd"))); } return; @@ -109,8 +109,8 @@ conf_alias_section(cfg_t *cfg_a) for(i = 0; i < cfg_size(cfg_a, "alias"); ++i) { cfgtmp = cfg_getnsec(cfg_a, "alias", i); - conf.alias[i].name = strdup(cfg_title(cfgtmp)); - conf.alias[i].content = strdup(cfg_getstr(cfgtmp, "content")); + conf.alias[i].name = _strdup(cfg_title(cfgtmp)); + conf.alias[i].content = _strdup(cfg_getstr(cfgtmp, "content")); } else { @@ -124,7 +124,7 @@ conf_alias_section(cfg_t *cfg_a) void conf_misc_section(cfg_t *cfg_m) { - conf.font = alias_to_str(strdup(cfg_getstr(cfg_m, "font"))); + conf.font = alias_to_str(_strdup(cfg_getstr(cfg_m, "font"))); conf.raisefocus = cfg_getbool(cfg_m, "raisefocus"); conf.raiseswitch = cfg_getbool(cfg_m, "raiseswitch"); @@ -136,8 +136,8 @@ conf_bar_section(cfg_t *cfg_b) { conf.border.bar = cfg_getbool(cfg_b, "border"); conf.colors.bar = getcolor(alias_to_str(cfg_getstr(cfg_b, "bg"))); - conf.colors.text = strdup(alias_to_str(cfg_getstr(cfg_b, "fg"))); - conf.bartop = (strcmp(strdup(cfg_getstr(cfg_b, "position")), "top") == 0) ? True : False; + conf.colors.text = _strdup(alias_to_str(cfg_getstr(cfg_b, "fg"))); + conf.bartop = (strcmp(_strdup(cfg_getstr(cfg_b, "position")), "top") == 0) ? True : False; return; } @@ -145,10 +145,13 @@ conf_bar_section(cfg_t *cfg_b) void conf_root_section(cfg_t *cfg_r) { - conf.root.background_command = strdup(alias_to_str(cfg_getstr(cfg_r, "background_command"))); + conf.root.background_command = _strdup(alias_to_str(cfg_getstr(cfg_r, "background_command"))); conf.root.nmouse = cfg_size(cfg_r, "mouse"); - conf.root.mouse = emalloc(conf.root.nmouse, sizeof(MouseBinding)); - mouse_section(conf.root.mouse, cfg_r, conf.root.nmouse); + if(conf.root.nmouse) + { + conf.root.mouse = emalloc(conf.root.nmouse, sizeof(MouseBinding)); + mouse_section(conf.root.mouse, cfg_r, conf.root.nmouse); + } return; } @@ -164,9 +167,11 @@ conf_client_section(cfg_t *cfg_c) conf.client.resizecorner_normal = getcolor(alias_to_str(cfg_getstr(cfg_c, "resize_corner_normal"))); conf.client.resizecorner_focus = getcolor(alias_to_str(cfg_getstr(cfg_c, "resize_corner_focus"))); conf.client.mod |= char_to_modkey(cfg_getstr(cfg_c, "modifier"), key_list); - conf.client.nmouse = cfg_size(cfg_c, "mouse"); - conf.client.mouse = emalloc(conf.client.nmouse, sizeof(MouseBinding)); - mouse_section(conf.client.mouse, cfg_c, conf.client.nmouse); + if((conf.client.nmouse = cfg_size(cfg_c, "mouse"))) + { + conf.client.mouse = emalloc(conf.client.nmouse, sizeof(MouseBinding)); + mouse_section(conf.client.mouse, cfg_c, conf.client.nmouse); + } /* Titlebar part */ cfgtmp = cfg_getsec(cfg_c, "titlebar"); @@ -174,10 +179,11 @@ conf_client_section(cfg_t *cfg_c) conf.titlebar.stipple = cfg_getbool(cfgtmp, "stipple"); conf.titlebar.fg_normal = alias_to_str(cfg_getstr(cfgtmp, "fg_normal")); conf.titlebar.fg_focus = alias_to_str(cfg_getstr(cfgtmp, "fg_focus")); - conf.titlebar.nmouse = cfg_size(cfgtmp, "mouse"); - conf.titlebar.mouse = emalloc(conf.titlebar.nmouse, sizeof(MouseBinding)); - mouse_section(conf.titlebar.mouse, cfgtmp, conf.titlebar.nmouse); - + if((conf.titlebar.nmouse = cfg_size(cfgtmp, "mouse"))) + { + conf.titlebar.mouse = emalloc(conf.titlebar.nmouse, sizeof(MouseBinding)); + mouse_section(conf.titlebar.mouse, cfgtmp, conf.titlebar.nmouse); + } return; } @@ -194,10 +200,10 @@ conf_layout_section(cfg_t *cfg_l) } conf.border.layout = cfg_getbool(cfg_l, "border"); - conf.colors.layout_fg = strdup(alias_to_str(cfg_getstr(cfg_l, "fg"))); + conf.colors.layout_fg = _strdup(alias_to_str(cfg_getstr(cfg_l, "fg"))); conf.colors.layout_bg = getcolor(alias_to_str(cfg_getstr(cfg_l, "bg"))); - if(strcmp(strdup(alias_to_str(cfg_getstr(cfg_l, "system"))), "menu") == 0) + if(strcmp(_strdup(alias_to_str(cfg_getstr(cfg_l, "system"))), "menu") == 0) conf.layout_system = True; if((conf.nlayout = cfg_size(cfg_l, "layout")) > NUM_OF_LAYOUT @@ -205,11 +211,11 @@ conf_layout_section(cfg_t *cfg_l) { fprintf(stderr, "WMFS Configuration: Too many or no layouts (%d)\n", conf.nlayout); conf.nlayout = 1; - conf.layout[0].symbol = strdup("TILE"); + conf.layout[0].symbol = _strdup("TILE"); conf.layout[0].func = tile; } - if(conf.layout_system) + if(conf.layout_system && conf.nlayout > 1) menu_init(&menulayout, "menulayout", conf.nlayout, /* Colors */ conf.colors.layout_bg, @@ -223,21 +229,21 @@ conf_layout_section(cfg_t *cfg_l) for(i = 0; i < conf.nlayout; ++i) { cfgtmp = cfg_getnsec(cfg_l, "layout", i); - if(!name_to_func(strdup(cfg_getstr(cfgtmp, "type")), layout_list)) + if(!name_to_func(_strdup(cfg_getstr(cfgtmp, "type")), layout_list)) { fprintf(stderr, "WMFS Configuration: Unknow Layout type: \"%s\"\n", - strdup(cfg_getstr(cfgtmp, "type"))); + _strdup(cfg_getstr(cfgtmp, "type"))); exit(EXIT_FAILURE); } else { - if(conf.layout_system) + if(conf.layout_system && conf.nlayout > 1) menu_new_item(&menulayout.item[i], - strdup(alias_to_str(cfg_getstr(cfgtmp, "symbol"))), - uicb_set_layout, strdup(cfg_getstr(cfgtmp, "type"))); + _strdup(alias_to_str(cfg_getstr(cfgtmp, "symbol"))), + uicb_set_layout, _strdup(cfg_getstr(cfgtmp, "type"))); - conf.layout[i].symbol = strdup(alias_to_str(cfg_getstr(cfgtmp, "symbol"))); - conf.layout[i].func = name_to_func(strdup(cfg_getstr(cfgtmp, "type")), layout_list); + conf.layout[i].symbol = _strdup(alias_to_str(cfg_getstr(cfgtmp, "symbol"))); + conf.layout[i].func = name_to_func(_strdup(cfg_getstr(cfgtmp, "type")), layout_list); } } } @@ -258,7 +264,7 @@ conf_tag_section(cfg_t *cfg_t) layout_name_to_struct(conf.layout, "tile_right", conf.nlayout, layout_list) }; conf.tag_round = cfg_getbool(cfg_t, "tag_round"); - conf.colors.tagselfg = strdup(alias_to_str(cfg_getstr(cfg_t, "sel_fg"))); + conf.colors.tagselfg = _strdup(alias_to_str(cfg_getstr(cfg_t, "sel_fg"))); conf.colors.tagselbg = getcolor(alias_to_str(cfg_getstr(cfg_t, "sel_bg"))); conf.colors.tag_occupied_bg = getcolor(alias_to_str(cfg_getstr(cfg_t, "occupied_bg"))); conf.border.tag = cfg_getbool(cfg_t, "border"); @@ -266,6 +272,7 @@ conf_tag_section(cfg_t *cfg_t) /* Alloc all */ conf.ntag = emalloc(screen_count(), sizeof(int)); tags = emalloc(screen_count(), sizeof(Tag*)); + for(i = 0; i < screen_count(); ++i) tags[i] = emalloc(cfg_size(cfg_t, "tag") + 1, sizeof(Tag)); @@ -281,7 +288,7 @@ conf_tag_section(cfg_t *cfg_t) ((j == -1) ? ++k : --l)) { ++conf.ntag[k]; - tags[k][conf.ntag[k]].name = strdup(cfg_getstr(cfgtmp, "name")); + tags[k][conf.ntag[k]].name = _strdup(cfg_getstr(cfgtmp, "name")); tags[k][conf.ntag[k]].mwfact = cfg_getfloat(cfgtmp, "mwfact"); tags[k][conf.ntag[k]].nmaster = cfg_getint(cfgtmp, "nmaster"); tags[k][conf.ntag[k]].resizehint = cfg_getbool(cfgtmp, "resizehint"); @@ -322,7 +329,7 @@ conf_menu_section(cfg_t *cfg_m) { cfgtmp = cfg_getnsec(cfg_m, "set_menu", i); - conf.menu[i].name = strdup(cfg_getstr(cfgtmp, "name")); + conf.menu[i].name = _strdup(cfg_getstr(cfgtmp, "name")); if(!(conf.menu[i].place_at_mouse = cfg_getbool(cfgtmp, "place_at_mouse"))) { @@ -330,10 +337,10 @@ conf_menu_section(cfg_t *cfg_m) conf.menu[i].y = cfg_getint(cfgtmp, "y"); } - conf.menu[i].colors.focus.bg = getcolor(strdup(cfg_getstr(cfgtmp, "bg_focus"))); - conf.menu[i].colors.focus.fg = strdup(cfg_getstr(cfgtmp, "fg_focus")); - conf.menu[i].colors.normal.bg = getcolor(strdup(cfg_getstr(cfgtmp, "bg_normal"))); - conf.menu[i].colors.normal.fg = strdup(cfg_getstr(cfgtmp, "fg_normal")); + conf.menu[i].colors.focus.bg = getcolor(_strdup(cfg_getstr(cfgtmp, "bg_focus"))); + conf.menu[i].colors.focus.fg = _strdup(cfg_getstr(cfgtmp, "fg_focus")); + conf.menu[i].colors.normal.bg = getcolor(_strdup(cfg_getstr(cfgtmp, "bg_normal"))); + conf.menu[i].colors.normal.fg = _strdup(cfg_getstr(cfgtmp, "fg_normal")); conf.menu[i].nitem = cfg_size(cfgtmp, "item"); @@ -344,10 +351,10 @@ conf_menu_section(cfg_t *cfg_m) { cfgtmp2 = cfg_getnsec(cfgtmp, "item", j); - conf.menu[i].item[j].name = strdup(cfg_getstr(cfgtmp2, "name")); - conf.menu[i].item[j].func = name_to_func(strdup(cfg_getstr(cfgtmp2, "func")), func_list); - conf.menu[i].item[j].cmd = (!strdup(alias_to_str((cfg_getstr(cfgtmp2, "cmd")))) - ? NULL : strdup(alias_to_str(cfg_getstr(cfgtmp2, "cmd")))); + conf.menu[i].item[j].name = _strdup(cfg_getstr(cfgtmp2, "name")); + conf.menu[i].item[j].func = name_to_func(_strdup(cfg_getstr(cfgtmp2, "func")), func_list); + conf.menu[i].item[j].cmd = (!_strdup(alias_to_str((cfg_getstr(cfgtmp2, "cmd")))) + ? NULL : _strdup(alias_to_str(cfg_getstr(cfgtmp2, "cmd")))); } } } @@ -368,9 +375,9 @@ conf_launcher_section(cfg_t *cfg_l) { cfgtmp = cfg_getnsec(cfg_l, "set_launcher", i); - conf.launcher[i].name = alias_to_str(strdup(cfg_getstr(cfgtmp, "name"))); - conf.launcher[i].prompt = alias_to_str(strdup(cfg_getstr(cfgtmp, "prompt"))); - conf.launcher[i].command = alias_to_str(strdup(cfg_getstr(cfgtmp, "command"))); + conf.launcher[i].name = alias_to_str(_strdup(cfg_getstr(cfgtmp, "name"))); + conf.launcher[i].prompt = alias_to_str(_strdup(cfg_getstr(cfgtmp, "prompt"))); + conf.launcher[i].command = alias_to_str(_strdup(cfg_getstr(cfgtmp, "command"))); } return; @@ -399,8 +406,8 @@ conf_keybind_section(cfg_t *cfg_k) cfg_getstr(cfgtmp, "func")); exit(EXIT_FAILURE); } - keys[i].cmd = (!strdup(alias_to_str((cfg_getstr(cfgtmp, "cmd")))) - ? NULL : strdup(alias_to_str(cfg_getstr(cfgtmp, "cmd")))); + keys[i].cmd = (!_strdup(alias_to_str((cfg_getstr(cfgtmp, "cmd")))) + ? NULL : _strdup(alias_to_str(cfg_getstr(cfgtmp, "cmd")))); } return; } @@ -414,7 +421,7 @@ init_conf(void) { int ret; - sprintf(final_path, "%s/%s", strdup(getenv("HOME")), strdup(FILE_NAME)); + sprintf(final_path, "%s/%s", _strdup(getenv("HOME")), _strdup(FILE_NAME)); cfg = cfg_init(opts, CFGF_NONE); ret = cfg_parse(cfg, final_path); diff --git a/src/event.c b/src/event.c index f84ccad..b0b5b33 100644 --- a/src/event.c +++ b/src/event.c @@ -32,8 +32,6 @@ #include "wmfs.h" -//#include "config_struct.h" - /** ButtonPress handle event * \param ev XButtonEvent pointer */ @@ -84,7 +82,7 @@ buttonpress(XButtonEvent *ev) } /* Layout button */ - if(ev->window == infobar[selscreen].layout_button->win) + if(ev->window == infobar[selscreen].layout_button->win && conf.nlayout > 1) { if(conf.layout_system && (ev->button == Button1 || ev->button == Button3)) /* True -> menu */ { diff --git a/src/ewmh.c b/src/ewmh.c index 4d13d5f..a35fb39 100644 --- a/src/ewmh.c +++ b/src/ewmh.c @@ -264,7 +264,7 @@ ewmh_manage_net_wm_state(long data_l[], Client *c) { c->state_fullscreen = False; client_moveresize(c, c->tmp_geo, False); - tags[selscreen][seltag[selscreen]].layout.func(); + tags[selscreen][seltag[selscreen]].layout.func(selscreen); } } /* Manage _NET_WM_STATE_DEMANDS_ATTENTION */ @@ -314,7 +314,7 @@ ewmh_manage_window_type(Client *c) sel->tile = sel->max = sel->lmax = False; client_moveresize(sel, sel->ogeo, True); client_focus(c); - tags[selscreen][seltag[selscreen]].layout.func(); + tags[selscreen][seltag[selscreen]].layout.func(selscreen); } } XFree(data); diff --git a/src/layout.c b/src/layout.c index 000da02..49ea305 100644 --- a/src/layout.c +++ b/src/layout.c @@ -48,7 +48,7 @@ arrange(int screen) client_hide(c); } - tags[screen][seltag[screen]].layout.func(); + tags[screen][seltag[screen]].layout.func(screen); infobar_draw(screen); ewmh_get_current_layout(); @@ -58,7 +58,7 @@ arrange(int screen) /** The free layout function */ void -freelayout(void) +freelayout(int screen) { Client *c; @@ -100,7 +100,7 @@ layoutswitch(Bool b) } } ewmh_get_current_layout(); - tags[selscreen][seltag[selscreen]].layout.func(); + tags[selscreen][seltag[selscreen]].layout.func(selscreen); infobar_draw(selscreen); return; @@ -131,11 +131,11 @@ uicb_layout_prev(uicb_t cmd) /** Max layout function */ void -maxlayout(void) +maxlayout(int screen) { Client *c; - for(c = nexttiled(clients); c; c = nexttiled(c->next)) + for(c = nexttiled(screen, clients); c; c = nexttiled(screen, c->next)) { c->tile = False; c->lmax = True; @@ -151,11 +151,11 @@ maxlayout(void) * \return a client pointer */ Client* -nexttiled(Client *c) +nexttiled(int screen, Client *c) { for(;c && (c->max || c->free - || c->screen != selscreen + || c->screen != screen || c->state_fullscreen || ishide(c)); c = c->next); @@ -179,7 +179,7 @@ uicb_set_mwfact(uicb_t cmd) return; tags[selscreen][seltag[selscreen]].mwfact += c; - tags[selscreen][seltag[selscreen]].layout.func(); + tags[selscreen][seltag[selscreen]].layout.func(selscreen); return; } @@ -195,14 +195,14 @@ uicb_set_nmaster(uicb_t cmd) screen_get_sel(); - for(nc = 0, c = nexttiled(clients); c; c = nexttiled(c->next), ++nc); + for(nc = 0, c = nexttiled(selscreen, clients); c; c = nexttiled(selscreen, c->next), ++nc); if(!nc || tags[selscreen][seltag[selscreen]].nmaster + n == 0 || tags[selscreen][seltag[selscreen]].nmaster + n > nc) return; tags[selscreen][seltag[selscreen]].nmaster += n; - tags[selscreen][seltag[selscreen]].layout.func(); + tags[selscreen][seltag[selscreen]].layout.func(selscreen); return; } @@ -210,15 +210,15 @@ uicb_set_nmaster(uicb_t cmd) /** Grid layout function */ void -grid(void) +grid(int screen) { Client *c; - XRectangle sg = sgeo[selscreen]; + XRectangle sg = sgeo[screen]; XRectangle cgeo = {sg.x, sg.y, 0, 0}; unsigned int i, n, cols, rows, cpcols = 0; unsigned int border = BORDH * 2; - for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next), ++n); + for(n = 0, c = nexttiled(screen, clients); c; c = nexttiled(screen, c->next), ++n); CHECK(n); for(rows = 0; rows <= n / 2; ++rows) @@ -229,7 +229,7 @@ grid(void) ? rows - 1 : rows; - for(i = 0, c = nexttiled(clients); c; c = nexttiled(c->next), ++i) + for(i = 0, c = nexttiled(screen, clients); c; c = nexttiled(screen, c->next), ++i) { /* Set client property */ c->max = c->lmax = False; @@ -247,7 +247,7 @@ grid(void) cgeo.width = sg.width - (cgeo.x - (sg.x - border)); /* Resize */ - client_moveresize(c, cgeo, tags[selscreen][seltag[selscreen]].resizehint); + client_moveresize(c, cgeo, tags[screen][seltag[screen]].resizehint); /* Set all the other size with current client info */ cgeo.y = c->geo.y + c->geo.height + border + TBARH; @@ -266,16 +266,16 @@ grid(void) * \param type Postion type { Top, Bottom, Left, Right } */ void -multi_tile(Position type) +multi_tile(int screen, Position type) { Client *c; - XRectangle sg = sgeo[selscreen]; + XRectangle sg = sgeo[screen]; XRectangle mastergeo = {sg.x, sg.y, 0, 0}; XRectangle cgeo = {sg.x, sg.y, 0, 0}; - uint i , n, tilesize, mwfact, nmaster = tags[selscreen][seltag[selscreen]].nmaster; + uint i , n, tilesize, mwfact, nmaster = tags[screen][seltag[screen]].nmaster; uint border = BORDH * 2; - for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next), ++n); + for(n = 0, c = nexttiled(screen, clients); c; c = nexttiled(screen, c->next), ++n); CHECK(n); /* FIX NMASTER */ @@ -283,8 +283,8 @@ multi_tile(Position type) /* SET MWFACT */ mwfact = (type == Top || type == Bottom) - ? tags[selscreen][seltag[selscreen]].mwfact * sg.height - : tags[selscreen][seltag[selscreen]].mwfact * sg.width; + ? tags[screen][seltag[screen]].mwfact * sg.height + : tags[screen][seltag[screen]].mwfact * sg.width; /* MASTER SIZE */ if(type == Top || type == Bottom) @@ -312,7 +312,7 @@ multi_tile(Position type) } - for(i = 0, c = nexttiled(clients); c; c = nexttiled(c->next), ++i) + for(i = 0, c = nexttiled(screen, clients); c; c = nexttiled(screen, c->next), ++i) { /* Set client property */ c->max = c->lmax = False; @@ -380,7 +380,7 @@ multi_tile(Position type) } /* Magic instant */ - client_moveresize(c, cgeo, tags[selscreen][seltag[selscreen]].resizehint); + client_moveresize(c, cgeo, tags[screen][seltag[screen]].resizehint); /* Set the position of the next client */ if(type == Top || type == Bottom) @@ -395,9 +395,9 @@ multi_tile(Position type) /** Tile Right function */ void -tile(void) +tile(int screen) { - multi_tile(Right); + multi_tile(screen, Right); return; } @@ -405,9 +405,9 @@ tile(void) /** Tile Left function */ void -tile_left(void) +tile_left(int screen) { - multi_tile(Left); + multi_tile(screen, Left); return; } @@ -415,9 +415,9 @@ tile_left(void) /** Tile Top function */ void -tile_top(void) +tile_top(int screen) { - multi_tile(Top); + multi_tile(screen, Top); return; } @@ -426,9 +426,9 @@ tile_top(void) /** Tile Bottom function */ void -tile_bottom(void) +tile_bottom(int screen) { - multi_tile(Bottom); + multi_tile(screen, Bottom); return; } @@ -445,12 +445,12 @@ uicb_tile_switch(uicb_t cmd) if(!sel || sel->hint || !sel->tile || sel->state_fullscreen) return; - if((c = sel) == nexttiled(clients)) - CHECK((c = nexttiled(c->next))); + if((c = sel) == nexttiled(selscreen, clients)) + CHECK((c = nexttiled(selscreen, c->next))); client_detach(c); client_attach(c); client_focus(c); - tags[selscreen][seltag[selscreen]].layout.func(); + tags[selscreen][seltag[selscreen]].layout.func(selscreen); return; } @@ -474,7 +474,7 @@ uicb_togglefree(uicb_t cmd) else sel->ogeo = sel->geo; - tags[selscreen][seltag[selscreen]].layout.func(); + tags[selscreen][seltag[selscreen]].layout.func(selscreen); return; } @@ -500,7 +500,7 @@ uicb_togglemax(uicb_t cmd) else { sel->max = False; - tags[selscreen][seltag[selscreen]].layout.func(); + tags[selscreen][seltag[selscreen]].layout.func(selscreen); } return; diff --git a/src/structs.h b/src/structs.h index f48f54e..589237a 100644 --- a/src/structs.h +++ b/src/structs.h @@ -187,7 +187,7 @@ typedef struct typedef struct { char *symbol; - void (*func)(void); + void (*func)(int screen); } Layout; /* Tag Structure */ diff --git a/src/util.c b/src/util.c index 163ef1e..678471b 100644 --- a/src/util.c +++ b/src/util.c @@ -102,6 +102,24 @@ setwinstate(Window win, long state) return; } +/** My strdup. the strdup of string.h isn't ansi compatible.. + * \param str char pointer +*/ +char* +_strdup(char const *str) +{ + char *ret = NULL; + + if (str != NULL) + { + ret = malloc((strlen(str) + 1) * sizeof *ret); + if (ret != NULL) + strcpy(ret, str); + } + + return ret; +} + /* The following function are for configuration usage. {{{ @@ -172,9 +190,9 @@ alias_to_str(char *conf_choice) tmpchar = conf.alias[i].content; if(tmpchar) - return strdup(tmpchar); + return _strdup(tmpchar); else - return strdup(conf_choice); + return _strdup(conf_choice); return NULL; } diff --git a/src/wmfs.c b/src/wmfs.c index a28efce..f667c13 100644 --- a/src/wmfs.c +++ b/src/wmfs.c @@ -40,22 +40,22 @@ errorhandler(Display *d, XErrorEvent *event) /* Check if there are another WM running */ if(BadAccess == event->error_code - && DefaultRootWindow(dpy) == event->resourceid) + && ROOT == event->resourceid) { fprintf(stderr, "WMFS Error: Another Window Manager is already running.\n"); exit(EXIT_FAILURE); } /* Ignore focus change error for unmapped client */ - /* Too lemmy to add Xproto.h so: + /* Too lazy to add Xproto.h so: * 42 = X_SetInputFocus * 28 = X_GrabButton */ if((c = client_gb_win(event->resourceid))) if(event->error_code == BadWindow - || (event->error_code == BadMatch && event->request_code == 42) - || event->request_code == 28) - return 0; + || event->request_code == 42 + || event->request_code == 28) + return 0; XGetErrorText(d, event->error_code, mess, 128); @@ -95,9 +95,11 @@ quit(void) client_unmanage(c); } - for(i = 0; i < screen_count(); ++i) - free(tags[i]); - free(tags); + + if(tags) + free(tags); + free(seltag); + XftFontClose(dpy, font); XFreeCursor(dpy, cursor[CurNormal]); XFreeCursor(dpy, cursor[CurMove]); @@ -105,7 +107,6 @@ quit(void) infobar_destroy(); free(sgeo); free(infobar); - free(seltag); free(keys); free(func_list); @@ -121,9 +122,12 @@ quit(void) if(conf.launcher) free(conf.launcher); free(conf.ntag); - free(conf.titlebar.mouse); - free(conf.client.mouse); - free(conf.root.mouse); + if(conf.titlebar.nmouse) + free(conf.titlebar.mouse); + if(conf.client.nmouse) + free(conf.client.mouse); + if(conf.root.nmouse) + free(conf.root.mouse); /* }}} */ XSync(dpy, False); diff --git a/src/wmfs.h b/src/wmfs.h index 209bf4c..5b9922b 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -219,6 +220,7 @@ ulong color_enlight(ulong col); void *emalloc(uint element, uint size); ulong getcolor(char *color); void setwinstate(Window win, long state); +char* _strdup(char const *str); /* Conf usage {{{ */ void* name_to_func(char *name, func_name_list_t *l); ulong char_to_modkey(char *name, key_name_list_t key_l[]); @@ -251,16 +253,16 @@ void uicb_screen_prev(uicb_t cmd); /* layout.c */ void arrange(int screen); -void freelayout(void); +void freelayout(int screen); void layoutswitch(Bool b); -void maxlayout(void); -Client *nexttiled(Client *c); +void maxlayout(int screen); +Client *nexttiled(int screen, Client *c); /* tile {{{ */ - void grid(void); - void tile(void); - void tile_left(void); - void tile_top(void); - void tile_bottom(void); + void grid(int screen); + void tile(int screen); + void tile_left(int screen); + void tile_top(int screen); + void tile_bottom(int screen); /* }}} */ void uicb_tile_switch(uicb_t); void uicb_togglemax(uicb_t);