diff --git a/CMakeLists.txt b/CMakeLists.txt index 285f1ec..7fac149 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,7 @@ set(wmfs_src src/screen.c src/tag.c src/util.c + src/viwmfs.c src/wmfs.c) # Set the executable from the wmfs_src diff --git a/src/structs.h b/src/structs.h index c36356a..921c043 100644 --- a/src/structs.h +++ b/src/structs.h @@ -388,4 +388,10 @@ typedef struct uint button; } name_to_uint_t; +typedef struct +{ + char *cmd; + char *uicb; +} vicmd_to_uicb; + #endif /* STRUCTS_H */ diff --git a/src/viwmfs.c b/src/viwmfs.c new file mode 100644 index 0000000..e295300 --- /dev/null +++ b/src/viwmfs.c @@ -0,0 +1,96 @@ +/* +* viwmfs.c +* Copyright © 2008, 2009 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 "wmfs.h" + +vicmd_to_uicb vicmd[] = +{ + {"r", "reload"}, + {"q", "quit"}, + {"t", "tag"}, + {"tn", "tag_next"}, + {"tp", "tag_prev"}, + {"ln", "layout_next"}, + {"lp", "layout_prev"}, + {"s", "screen_select"}, + {"screen", "screen_select"}, + {"sn", "screen_next"}, + {"sp", "screen_prev"}, + {"cc", "client_kill"}, + {"ct", "tag_transfert"}, + {"client_transfert", "tag_transfert"}, + {"cn", "client_next"}, + {"cp", "client_prev"}, + {"csn", "client_swap_next"}, + {"csp", "client_swap_prev"}, + {"tm", "toggle_max"}, + {"tf", "toggle_free"}, +}; + +void +viwmfs(char *str) +{ + int i; + char *cmd; + Bool e; + + if(!str) + return; + + if(*str == ':') + { + ++str; + + cmd = _strdup(str); + for(i = 0; cmd[i] != ' ' && cmd[i] != '\0'; ++i); + cmd[i] = '\0'; + + for(i = 0; i < LEN(vicmd); ++i) + if(!strncmp(cmd, vicmd[i].cmd, strlen(cmd))) + { + exec_uicb_function(vicmd[i].uicb, str + strlen(cmd)); + e = True; + break; + } + + if(!e) + { + cmd = _strdup(str); + for(i = 0; cmd[i] != ' '; ++i); + cmd[i] = '\0'; + + exec_uicb_function(cmd, str + i); + } + } + + return; +} diff --git a/src/wmfs.c b/src/wmfs.c index af815ef..5586033 100644 --- a/src/wmfs.c +++ b/src/wmfs.c @@ -352,11 +352,11 @@ main(int argc, char **argv) argv_global = _strdup(argv[0]); sprintf(conf.confpath, "%s/"DEF_CONF, getenv("HOME")); - while((i = getopt(argc, argv, "hvic:s:g:C:")) != -1) + while((i = getopt(argc, argv, "hvic:s:g:C:V:")) != -1) { /* For options who need WMFS running */ - if((i == 'c' || i == 's' || i == 'g') + if((i == 'c' || i == 's' || i == 'g' || i == 'V') && !(dpy = XOpenDisplay(NULL))) { fprintf(stderr, "WMFS: cannot open X server.\n"); @@ -367,11 +367,12 @@ main(int argc, char **argv) { case 'h': default: - printf("usage: %s [-ihv] [-C ] [-c ] [-g ] [-s ]\n" + printf("usage: %s [-ihv] [-C ] [-c ] [-g ] [-s ] [-V Load a configuration file\n" " -c Execute an uicb function to control WMFS\n" " -g Show information about wmfs status\n" " -s Set the bar(s) statustext\n" + " -V Manage WMFS with vi-like command\n" " -h Show this page\n" " -i Show informations\n" " -v Show WMFS version\n", argv[0]); @@ -413,6 +414,11 @@ main(int argc, char **argv) XCloseDisplay(dpy); exit(EXIT_SUCCESS); break; + case 'V': + viwmfs(optarg); + XCloseDisplay(dpy); + exit(EXIT_SUCCESS); + break; } } diff --git a/src/wmfs.h b/src/wmfs.h index 02cc261..143b77b 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -317,6 +317,9 @@ void getinfo_mwfact(void); void getinfo_nmaster(void); void getinfo(char *info); +/* viwmfs.c */ +void viwmfs(char *str); + /* wmfs.c */ int errorhandler(Display *d, XErrorEvent *event); int errorhandlerdummy(Display *d, XErrorEvent *event); diff --git a/wmfs.1 b/wmfs.1 index 9dac1e8..4388cec 100644 --- a/wmfs.1 +++ b/wmfs.1 @@ -13,7 +13,7 @@ .SH "NAME" wmfs \- Window Manager From Scratch .SH "SYNOPSIS" -\fBwmfs\fR [\fB\-ihv\fR] [\fB\-C \fR] [\fB\-c \fR] [\fB\-g \fR] [\fB\-s \fR] +\fBwmfs\fR [\fB\-ihv\fR] [\fB\-C \fR] [\fB\-c \fR] [\fB\-g \fR] [\fB\-s \fR] [\fB\-V \fR] .sp .SH "DESCRIPTION" \fBWMFS\fR is a basic, lightweight and dynamic tiling windows manager for X\&. @@ -40,6 +40,11 @@ Show information about wmfs status\&. Set the bar(s) statustext\&. .RE .PP +\fB\-V \fR +.RS 4 +Manage WMFS with vi-like command\&. +.RE +.PP \fB\-v\fR .RS 4 Print version information to standard output, then exit\&.