diff --git a/CMakeLists.txt b/CMakeLists.txt index 1789cea..a24c117 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,9 +24,13 @@ project(${PROJECT_NAME} C) # Definition of the wmfs source set(wmfs_src + src/confparse/util.c + src/confparse/confparse.c src/barwin.c src/client.c +# src/config_new.c src/config.c + src/ src/draw.c src/event.c src/ewmh.c diff --git a/src/config_new.c b/src/config_new.c index a4e6120..f42b901 100644 --- a/src/config_new.c +++ b/src/config_new.c @@ -30,55 +30,70 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "config_struct.h" +#include "wmfs.h" -void -conf_init_func_list(void) +func_name_list_t tmp_func_list[] = { - int i; + {"spawn", uicb_spawn }, + {"client_kill", uicb_client_kill }, + {"client_prev", uicb_client_prev }, + {"client_next", uicb_client_next }, + {"client_swap_next", uicb_client_swap_next }, + {"client_swap_prev", uicb_client_swap_prev }, + {"client_screen_next", uicb_client_screen_next }, + {"client_screen_prev", uicb_client_screen_prev }, + {"toggle_max", uicb_togglemax }, + {"layout_next", uicb_layout_next }, + {"layout_prev", uicb_layout_prev }, + {"tag", uicb_tag }, + {"tag_next", uicb_tag_next }, + {"tag_prev", uicb_tag_prev }, + {"tag_transfert", uicb_tagtransfert }, + {"set_mwfact", uicb_set_mwfact }, + {"set_nmaster", uicb_set_nmaster }, + {"quit", uicb_quit }, + {"toggle_infobar_position", uicb_infobar_togglepos }, + {"toggle_resizehint", uicb_toggle_resizehint }, + {"mouse_move", uicb_mouse_move }, + {"mouse_resize", uicb_mouse_resize }, + {"client_raise", uicb_client_raise }, + {"toggle_free", uicb_togglefree }, + {"screen_select", uicb_screen_select }, + {"screen_next", uicb_screen_next }, + {"screen_prev", uicb_screen_prev }, + {"reload", uicb_reload }, + {"launcher", uicb_launcher }, + {"set_layout", uicb_set_layout }, + {"menu", uicb_menu } +}; - func_name_list_t tmp_list[] = - { - {"spawn", uicb_spawn }, - {"client_kill", uicb_client_kill }, - {"client_prev", uicb_client_prev }, - {"client_next", uicb_client_next }, - {"client_swap_next", uicb_client_swap_next }, - {"client_swap_prev", uicb_client_swap_prev }, - {"client_screen_next", uicb_client_screen_next }, - {"client_screen_prev", uicb_client_screen_prev }, - {"toggle_max", uicb_togglemax }, - {"layout_next", uicb_layout_next }, - {"layout_prev", uicb_layout_prev }, - {"tag", uicb_tag }, - {"tag_next", uicb_tag_next }, - {"tag_prev", uicb_tag_prev }, - {"tag_transfert", uicb_tagtransfert }, - {"set_mwfact", uicb_set_mwfact }, - {"set_nmaster", uicb_set_nmaster }, - {"quit", uicb_quit }, - {"toggle_infobar_position", uicb_infobar_togglepos }, - {"toggle_resizehint", uicb_toggle_resizehint }, - {"mouse_move", uicb_mouse_move }, - {"mouse_resize", uicb_mouse_resize }, - {"client_raise", uicb_client_raise }, - {"toggle_free", uicb_togglefree }, - {"screen_select", uicb_screen_select }, - {"screen_next", uicb_screen_next }, - {"screen_prev", uicb_screen_prev }, - {"reload", uicb_reload }, - {"launcher", uicb_launcher }, - {"set_layout", uicb_set_layout }, - {"menu", uicb_menu } - }; +key_name_list_t key_list[] = +{ + {"Control", ControlMask }, + {"Shift", ShiftMask }, + {"Lock", LockMask }, + {"Alt", Mod1Mask }, + {"Mod2", Mod2Mask }, + {"Mod3", Mod3Mask }, + {"Mod4", Mod4Mask }, + {"Super", Mod4Mask }, + {"Mod5", Mod5Mask }, + {NULL, NoSymbol } +}; - func_list = emalloc(LEN(tmp_list), sizeof(func_name_list_t)); - - for(i = 0; i < LEN(tmp_list); ++i) - func_list[i] = tmp_list[i]; - - return; -} +name_to_uint_t mouse_button_list[] = +{ + {"Button1", Button1 }, + {"Button2", Button2 }, + {"Button3", Button3 }, + {"Button4", Button4 }, + {"Button5", Button5 }, + {"1", Button1 }, + {"2", Button2 }, + {"3", Button3 }, + {"4", Button4 }, + {"5", Button5 }, +}; void mouse_section(MouseBinding mb[], char *src, int ns) @@ -172,7 +187,6 @@ conf_client_section(char *src) if((conf.client.nmouse = get_size_sec(src, "mouse"))) { - printf("conf.client.nmouse = %d\n", conf.client.nmouse); conf.client.mouse = emalloc(conf.client.nmouse, sizeof(MouseBinding)); mouse_section(conf.client.mouse, src, conf.client.nmouse); } @@ -416,8 +430,8 @@ conf_menu_section(char *src) if(!(conf.menu[i].place_at_mouse = get_opt(tmp, "true", "place_at_mouse").bool)) { - conf.menu[i].x = get_opt(cfgtmp, "0", "x").num; - conf.menu[i].y = get_opt(cfgtmp, "0", "y").num; + conf.menu[i].x = get_opt(tmp, "0", "x").num; + conf.menu[i].y = get_opt(tmp, "0", "y").num; } conf.menu[i].colors.focus.bg = getcolor(get_opt(tmp, "#000000", "bg_focus").str); @@ -487,7 +501,7 @@ conf_keybind_section(char *src) if(keys[i].func == NULL) { - fprintf(stderr, "WMFS Configuration error: Unknow Function \"%s\"\n", get_opt(tmp, "", "func").str); + fprintf(stderr, "WMFS Configuration warning: Unknow Function \"%s\"\n", get_opt(tmp, "", "func").str); keys[i].func = uicb_spawn; } keys[i].cmd = (!get_opt(tmp, "", "cmd").str) ? NULL : get_opt(tmp, "", "cmd").str; @@ -502,22 +516,19 @@ conf_keybind_section(char *src) void init_conf(void) { - FILE *f; char *file; - if(!(f = fopen(conf.confpath, "r"))) + if(!(file = file_to_str(conf.confpath))) { fprintf(stderr, "WMFS: parsing configuration file (%s) failed\n", conf.confpath); sprintf(conf.confpath, "%s/wmfs/wmfsrc", XDG_CONFIG_DIR); fprintf(stderr, "Use the default configuration (%s).\n", conf.confpath); - f = fopen(conf.confpath, "r"); + file = file_to_str(conf.confpath); } - file = file_to_str(f); - - conf_init_func_list(); - - /* conf_alias_section(get_sec(file, "alias")); */ + /* Set func_list */ + func_list = emalloc(LEN(tmp_func_list), sizeof(func_name_list_t)); + memcpy(func_list, tmp_func_list, LEN(tmp_func_list) * sizeof(func_name_list_t)); conf_misc_section(get_sec(file, "misc")); conf_bar_section(get_sec(file, "bar")); diff --git a/src/confparse/confparse.c b/src/confparse/confparse.c index 3e67b8c..45384ee 100644 --- a/src/confparse/confparse.c +++ b/src/confparse/confparse.c @@ -33,21 +33,26 @@ #include "confparse.h" char* -file_to_str(FILE *f) +file_to_str(char *path) { - char c; - char *ret; - int i; + char *ret, *p; + int fd, i; + struct stat st; - for(i = 1; fgetc(f) != EOF; ++i); + if(!path || !(fd = open(path, O_RDONLY))) + return NULL; - ret = emalloc(i, sizeof(char)); + /* To get the file size */ + stat(path, &st); - rewind(f); + /* Bufferize file */ + ret = _strdup((char*)mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, fd, SEEK_SET)); - for(i = 0; (c = fgetc(f)) != EOF; ret[i++] = c); + /* Erase comment line from return value */ + for(i = 0; (p = strchr(erase_delim_content(ret + i), COMMENT_CHAR));) + for(i = st.st_size - strlen(p); ret[i] && ret[i] != '\n'; ret[i++] = ' '); - fclose(f); + fprintf(stderr, "WMFS Configuration info: '%s' read.\n", path); return ret; } @@ -108,7 +113,7 @@ get_nsec(char *src, char *name, int n) buf = erase_delim_content(src); buf2 = erase_sec_content(buf); - for(i = 0; i < n * 2 && (buf = strstr(buf, secn)); ++i, buf += strlen(secn)); + for(i = 0; i < (n * 2) && (buf = strstr(buf, secn)); ++i, buf += strlen(secn)); ret = get_sec(src + strlen(src) - strlen(buf), name); @@ -181,11 +186,11 @@ get_list_opt(char *src, char *def, char *name, int *n) if(!(p = get_opt(src, def, name).str)) return NULL; - for(i = 0; p[i] && (p[i] != '}' || is_in_delimiter(p, i)); ++i); + for(i = 0; p[i] && (p[i] != LIST_DEL_E || is_in_delimiter(p, i)); ++i); p[i + 1] = '\0'; - /* Syntax of list (val1, val2, ..., valx) */ - if(*p != '{' || *(p + strlen(p) - 1) != '}') + /* Syntax of list {val1, val2, ..., valx} */ + if(*p != LIST_DEL_S || *(p + strlen(p) - 1) != LIST_DEL_E) return NULL; /* Erase ( ) */ @@ -215,10 +220,8 @@ get_list_opt(char *src, char *def, char *name, int *n) } else { - ret = emalloc(1, sizeof(opt_type)); + ret = emalloc((*n = 1), sizeof(opt_type)); *ret = str_to_opt(clean_value(p)); - - *n = 1; } return ret; diff --git a/src/confparse/confparse.h b/src/confparse/confparse.h index 26d3cfc..988721f 100644 --- a/src/confparse/confparse.h +++ b/src/confparse/confparse.h @@ -33,15 +33,23 @@ #ifndef CONFPARSE_H #define CONFPARSE_H -#include -#include -#include +#include +#include +#include #include "../wmfs.h" +/* Section delimiter */ #define SEC_DEL_S '[' #define SEC_DEL_E ']' +/* List delimiter */ +#define LIST_DEL_S '{' +#define LIST_DEL_E '}' + +/* Comment character */ +#define COMMENT_CHAR '#' + typedef struct { long int num; @@ -59,7 +67,7 @@ opt_type str_to_opt(char *str); char *clean_value(char *str); /* confparse.c */ -char *file_to_str(FILE *f); +char *file_to_str(char *path); char *get_sec(char *src, char *name); char *get_nsec(char *src, char *name, int n); int get_size_sec(char *src, char *name); diff --git a/src/confparse/util.c b/src/confparse/util.c index b0ae5b0..37a87c3 100644 --- a/src/confparse/util.c +++ b/src/confparse/util.c @@ -38,15 +38,13 @@ erase_delim_content(char *buf) int i, j; char *str, c; - if(!buf) + if(!buf || !(str = _strdup(buf))) return NULL; - str = _strdup(buf); - for(i = 0; i < strlen(str); ++i) if((c = str[i]) == '"' || (c = str[i]) == '\'') { - for(str[(j = i)] = ' '; str[j] && str[j] != c; str[j++] = ' '); + for(*(str + (j = i)) = ' '; str[j] && str[j] != c; str[j++] = ' '); str[j] = ' '; } @@ -70,10 +68,9 @@ erase_sec_content(char *buf) int i, j; char *p, *str, *name, *ret; - if(!buf) + if(!buf || !(str = erase_delim_content(buf))) return NULL; - str = erase_delim_content(buf); ret = _strdup(buf); for(i = 1, name = _strdup(str + i); strchr(str + i, SEC_DEL_S); ++i, name = _strdup(str + i)) @@ -97,20 +94,15 @@ erase_sec_content(char *buf) char* opt_srch(char *buf, char *opt) { - char *p, c1, c2; + char *p; if(!buf || !opt) return NULL; if((p = strstr(erase_delim_content(buf), opt))) - { - c1 = *(p + strlen(opt)); - c2 = *(p - 1); - - if((c1 == ' ' || c1 == '=') - && (c2 == ' ' || c2 == '\n' || c2 == '\t' || !c2)) - return _strdup(buf + (strlen(buf) - strlen(p))); - } + if((*(p + strlen(opt)) == ' ' || *(p + strlen(opt)) == '=') + && (*(p - 1) == ' ' || *(p - 1) == '\n' || *(p - 1) == '\t' || !(*(p - 1)))) + return _strdup(buf + (strlen(buf) - strlen(p))); return NULL; } @@ -146,18 +138,15 @@ clean_value(char *str) int i; char c, *p; - if(!str) + if(!str || !(p = _strdup(str))) return NULL; - p = _strdup(str); - /* Remove useless spaces */ for(; *p == ' '; ++p); for(; *(p + strlen(p) - 1) == ' '; *(p + strlen(p) - 1) = '\0'); /* For string delimiter (" or ') */ - if(((c = *p) == '"' || (c = *p) == '\'') - && strchr(p + 1, c)) + if(((c = *p) == '"' || (c = *p) == '\'') && strchr(p + 1, c)) { for(++p, i = 0; p[i] && p[i] != c; ++i); p[i] = '\0'; diff --git a/src/wmfs.h b/src/wmfs.h index 5ccc081..a9c71d8 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -52,6 +52,7 @@ #include /* Local headers */ +#include "confparse/confparse.h" #include "config.h" #include "structs.h" @@ -195,15 +196,6 @@ void frame_moveresize(Client *c, XRectangle geo); void frame_update(Client *c); /* config.c */ -void conf_alias_section(cfg_t *cfg_a); -void conf_misc_section(cfg_t *cfg_m); -void conf_bar_section(cfg_t *cfg_b); -void conf_root_section(cfg_t *cfg_r); -void conf_client_section(cfg_t *cfg_c); -void conf_layout_section(cfg_t *cfg_l); -void conf_tag_section(cfg_t *cfg_t); -void conf_menu_section(cfg_t *cfg_m); -void conf_keybind_section(cfg_t *cfg_k); void init_conf(void); /* event.c */ diff --git a/wmfsrc_new b/wmfsrc_new new file mode 100644 index 0000000..130a8a0 --- /dev/null +++ b/wmfsrc_new @@ -0,0 +1,252 @@ +# +# This is the default wmfs config file, copy it to +# ~/.config/wmfs/wmfsrc and edit it. +# + +[misc] + font = "dejavu-10" + raisefocus = false + focus_follow_mouse = true +[misc] + +[bar] + bg = "#191919" + fg = "#D4D4D4" + border = true +[bar] + +[layouts] + fg = "#191919" + bg = "#7E89A2" + + # Border around the layout button. + border = true + + # Value menu or switch. + system = "menu" + + # Tiling layouts. + [layout] type = "tile_right" symbol = "RIGHT" [layout] + [layout] type = "tile_left" symbol = "LEFT" [layout] + [layout] type = "tile_top" symbol = "TOP" [layout] + [layout] type = "tile_bottom" symbol = "BOTTOM" [layout] + [layout] type = "tile_grid" symbol = "GRID" [layout] + [layout] type = "mirror_vertical" symbol = "MIRROR_V" [layout] + [layout] type = "mirror_horizontal" symbol = "MIRROR_H" [layout] + + # Other layouts. + [layout] type = "max" symbol = "MAX" [layout] + [layout] type = "free" symbol = "FREE" [layout] + +[layouts] + +[tags] + tag_round = false + occupied_bg = "#003366" + sel_fg = "#191919" + sel_bg = "#7E89A2" + + # Border around the tag buttons. + border = true + + [tag] + name = "one" + screen = 1 + mwfact = 0.65 + nmaster = 1 + layout = "tile_right" + resizehint = false + infobar_position = "top" + [tag] + + [tag] name = "two" clients = {"pwet,"}[tag] + [tag] name = "three" [tag] + [tag] name = "four" [tag] + [tag] name = "five" [tag] + [tag] name = "six" [tag] + [tag] name = "seven" [tag] + [tag] name = "eight" [tag] + [tag] name = "nine" [tag] +[tags] + +[root] + # Command you can execute to set the background. + background_command = "xsetroot -solid black" + + [mouse] button = "4" func = "tag_next" [mouse] + [mouse] button = "5" func = "tag_prev" [mouse] + [mouse] button = "3" func = "menu" cmd = "rootmenu" [mouse] +[root] + +[client] + border_height = 3 + border_shadow = true + border_normal = "#191919" + border_focus = "#003366" + resize_corner_normal = "#191919" + resize_corner_focus = "#003366" + + modifier = "Alt" + + [mouse] button = "1" func = "client_raise" [mouse] + [mouse] button = "1" func = "mouse_move" [mouse] + [mouse] button = "3" func = "client_raise" [mouse] + [mouse] button = "3" func = "mouse_resize" [mouse] + + # Remove this section to delete the titlebar. + [titlebar] + stipple = false + height = 12 + fg_normal = "#7E89A2" + fg_focus = "#9F9AB3" + + [mouse] button = "1" func = "client_raise" [mouse] + [mouse] button = "1" func = "mouse_move" [mouse] + [mouse] button = "3" func = "client_raise" [mouse] + [mouse] button = "3" func = "mouse_resize" [mouse] + + [button] + [mouse] button = "1" func = "client_kill" [mouse] + [mouse] button = "3" func = "menu" cmd = "clientmenu" [mouse] + + [line] coord = {1, 1, 4, 1} [line] + [line] coord = {1, 1, 1, 4} [line] + [line] coord = {1, 4, 4, 4} [line] + [button] + [titlebar] +[client] + +[menu] + # Default menu, binded on the root window, button 3. + [set_menu] + name = "rootmenu" + + # place_at_mouse = false + # x = 40 y = 50 + + fg_focus = "#191919" bg_focus = "#7E89A2" + fg_normal = "#9F9AB3" bg_normal = "#191919" + + [item] name = "Terminal" func = "spawn" cmd = term [item] + [item] name = "Next tag" func = "tag_next" [item] + [item] name = "Previous tag" func = "tag_prev" [item] + [item] name = "Next layout" func = "layout_next" [item] + [item] name = "Previous layout" func = "layout_prev" [item] + [item] name = "Toggle infobar" func = "toggle_infobar_position" [item] + [item] name = "Quit WMFS" func = "quit" [item] + [set_menu] + + [set_menu] + name = "clientmenu" + + fg_focus = "#D4D4D4" bg_focus = "#003366" + fg_normal = "#D4D4D4" bg_normal = "#191919" + + [item] name = "Close" func = "client_kill" [item] + [item] name = "Maximize" func = "toggle_max" [item] + [item] name = "Free" func = "toggle_free" [item] + [set_menu] +[menu] + +[launcher] + [set_launcher] + name = "launcher_exec" + prompt = "Exec: " + command = "exec" + [set_launcher] + + [set_launcher] + name = "launcher_ssh" + prompt = "ssh to: " + command = "urxvt -e ssh" + [set_launcher] +[launcher] + +[keys] + # Reload the configuration of wmfs. + [key] mod = {"Alt", "Control"} key = "r" func = "reload" [key] + + # Open a terminal. + [key] mod = {"Control"} key = "Return" func = "spawn" cmd = term [key] + + # Kill the selected client. + [key] mod = {"Alt"} key = "q" func = "client_kill" [key] + + # Quit wmfs. + [key] mod = {"Control", "Alt", "Shift"} key = "q" func = "quit" [key] + + # Swap current client with the next. + [key] mod = {"Alt"} key = "t" func = "client_swap_next" [key] + + # Swap current client with the previous. + [key] mod = {"Alt", "Shift"} key = "t" func = "client_swap_prev" [key] + + # Toggle maximum the selected client + [key] mod = {"Alt"} key = "m" func = "toggle_max" [key] + + # Toggle free the selected client. + [key] mod = {"Alt"} key = "f" func = "toggle_free" [key] + + # Toggle the position of the infobar. + [key] mod = {"Alt"} key = "b" func = "toggle_infobar_position" [key] + + # Toggle the resizehint of the current tag/screen + [key] mod = {"Shift", "Control"} key = "r" func = "toggle_resizehint" [key] + + # Select the next client. + [key] mod = {"Alt"} key = "Tab" func = "client_next" [key] + + # Select the previous client. + [key] mod = {"Alt","Shift"} key = "Tab" func = "client_prev" [key] + + # Select the next tag. + [key] mod = {"Control"} key = "Right" func = "tag_next" [key] + + # Select the previous tag. + [key] mod = {"Control"} key = "Left" func = "tag_prev" [key] + + # Set the next layout. + [key] mod = {"Alt"} key = "space" func = "layout_next" [key] + + # Set the previous layout. + [key] mod = {"Alt", "Shift"} key = "space" func = "layout_prev" [key] + + # Increase mwfact. + [key] mod = {"Alt"} key = "l" func = "set_mwfact" cmd = "+0.025" [key] + + # Decrease mwfact. + [key] mod = {"Alt"} key = "h" func = "set_mwfact" cmd = "-0.025" [key] + + # Increase nmaster. + [key] mod = {"Alt"} key = "d" func = "set_nmaster" cmd = "+1" [key] + + # Decease nmaster. + [key] mod = {"Alt", "Shift"} key = "d" func = "set_nmaster" cmd = "-1" [key] + + #Launchers. + [key] mod = {"Alt"} key = "p" func = "launcher" cmd = "launcher_exec" [key] + [key] mod = {"Alt", "Shift"} key = "p" func = "launcher" cmd = "launcher_ssh" [key] + + # Set the tag x. + [key] mod = {"Alt"} key = "F1" func = "tag" cmd = "1" [key] + [key] mod = {"Alt"} key = "F2" func = "tag" cmd = "2" [key] + [key] mod = {"Alt"} key = "F3" func = "tag" cmd = "3" [key] + [key] mod = {"Alt"} key = "F4" func = "tag" cmd = "4" [key] + [key] mod = {"Alt"} key = "F5" func = "tag" cmd = "5" [key] + [key] mod = {"Alt"} key = "F6" func = "tag" cmd = "6" [key] + [key] mod = {"Alt"} key = "F7" func = "tag" cmd = "7" [key] + [key] mod = {"Alt"} key = "F8" func = "tag" cmd = "8" [key] + [key] mod = {"Alt"} key = "F9" func = "tag" cmd = "9" [key] + + # Transfert selected client to x. + [key] mod = {"Alt", "Shift"} key = "F1" func = "tag_transfert" cmd ="1" [key] + [key] mod = {"Alt", "Shift"} key = "F2" func = "tag_transfert" cmd ="2" [key] + [key] mod = {"Alt", "Shift"} key = "F3" func = "tag_transfert" cmd ="3" [key] + [key] mod = {"Alt", "Shift"} key = "F4" func = "tag_transfert" cmd ="4" [key] + [key] mod = {"Alt", "Shift"} key = "F5" func = "tag_transfert" cmd ="5" [key] + [key] mod = {"Alt", "Shift"} key = "F6" func = "tag_transfert" cmd ="6" [key] + [key] mod = {"Alt", "Shift"} key = "F7" func = "tag_transfert" cmd ="7" [key] + [key] mod = {"Alt", "Shift"} key = "F8" func = "tag_transfert" cmd ="8" [key] + [key] mod = {"Alt", "Shift"} key = "F9" func = "tag_transfert" cmd ="9" [key] +[keys] +