diff -ubNr --exclude-from=/home/azzit/diffrc/ion.conf ion-devel-20020130-grab/Makefile ion-devel-20020130/Makefile --- ion-devel-20020130-grab/Makefile Wed Jan 30 22:49:28 2002 +++ ion-devel-20020130/Makefile Sat Feb 16 02:51:52 2002 @@ -7,7 +7,7 @@ ###################################### -SUBDIRS=libtu wmcore query src +SUBDIRS=libtu wmcore query commandmode src INSTALL_SUBDIRS=src TARGETS=man/ion.1x diff -ubNr --exclude-from=/home/azzit/diffrc/ion.conf ion-devel-20020130-grab/commandmode/Makefile ion-devel-20020130/commandmode/Makefile --- ion-devel-20020130-grab/commandmode/Makefile Thu Jan 1 01:00:00 1970 +++ ion-devel-20020130/commandmode/Makefile Sat Feb 16 02:15:13 2002 @@ -0,0 +1,31 @@ +## +## commandmode Makefile +## + +# System-specific configuration is in system.mk +include ../system.mk + +###################################### + +LIBS += -L../libtu -ltu -lm $(X11_LIBS) -lX11 +INCLUDES += -I../libtu/include $(X11_INCLUDES) -I.. +DEFINES += -DETCDIR=\"$(ETCDIR)\" + +CFLAGS += $(XOPEN_SOURCE) $(MODULE_SUPPORT) +LDFLAGS += $(MODULE_SUPPORT_LDFLAGS) + +OBJS= command.o main.o + +TARGETS=commandmode.a + +###################################### + +include ../rules.mk + +###################################### + +commandmode.a: $(OBJS) + $(AR) $(ARFLAGS) $@ $+ + $(RANLIB) $@ + +_install: diff -ubNr --exclude-from=/home/azzit/diffrc/ion.conf ion-devel-20020130-grab/commandmode/command.c ion-devel-20020130/commandmode/command.c --- ion-devel-20020130-grab/commandmode/command.c Thu Jan 1 01:00:00 1970 +++ ion-devel-20020130/commandmode/command.c Sat Feb 16 06:26:21 2002 @@ -0,0 +1,186 @@ +/* + * ion/command.c + * + * Copyright (c) Lukas Schroeder 2002 + * See the included file LICENSE for details. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +/*{{{ Prototypes */ + +static bool commandmode_keyboard_handler(WThing *thing, XEvent *ev); + +/*}}}*/ + +/* {{{ Definitions and friends */ + +extern WBindmap *commandmode_bindmap; +static bool commandmode_active=FALSE; + + +/*}}}*/ + +/*{{{ auxiliary functions */ + + +static WThing *get_current_from_thing(WThing *thing) +{ + WScreen *scr; + scr=SCREEN_OF(thing); + if(!scr->current_sub) + return NULL; + return (WThing*)workspace_find_current((WWorkspace*)scr->current_sub); +} + +/*}}}*/ + + +/*{{{ init/deinit,enter/leave */ + +void commandmode_enter(WThing *thing) +{ + WScreen *scr; + WThing *wwin; + + if(commandmode_active==TRUE){ + fprintf(stderr, "%s() commandmode already active!\n", __FUNCTION__); + return; + } + + if(wglobal.input_mode!=INPUT_NORMAL){ + fprintf(stderr, "%s() can only enter commandmode from normal input mode!\n", __FUNCTION__); + return; + } + + if(!WTHING_IS(thing, WWindow)) + thing=get_current_from_thing(thing); + + commandmode_active=TRUE; + grab_establish(thing, commandmode_keyboard_handler, FocusChangeMask|KeyReleaseMask); + + wglobal.input_mode=INPUT_NORMAL; +} + +void commandmode_leave(WThing *thing) +{ + if(commandmode_active){ + commandmode_active=FALSE; + grab_remove(commandmode_keyboard_handler); + } +} + +/*}}}*/ + + +/*{{{ event handling */ + +static void commandmode_keypress_handler(WThing *thing, XKeyEvent *ev) +{ + WScreen *scr; + WBinding *binding=NULL; + bool topmap=TRUE; + bool toplvl=FALSE; + + if(ev->type==KeyRelease) + return; + + /* + * when holding a grab ev->window will be the window holding the pointer + * (X's PointerRoot focus mode); this can either be a window + * handled by the window manager or a Window of an application, and "thing" + * will just be too old an information if e.g. the focus changed while + * holding the command-mode grab + * so, to get the right context for call_binding() we'll do a lookup to find + * the current WWindow... + */ + + thing=get_current_from_thing(thing); + if(!thing || !WTHING_IS(thing, WWindow)) + return; + + toplvl=WTHING_IS(thing, WFrame); + + binding=lookup_binding(commandmode_bindmap, ACT_KEYPRESS, ev->state, ev->keycode); + + if(!binding){ + if(ismod(ev->keycode)) + return; + } + + if(binding!=NULL && binding->submap!=NULL){ + /* we dont allow submap grabs in commandmode; (yet?) */ + return; + } + + if(binding){ + /* Get the screen now for waitrel grab - the thing might + * have been destroyed when call_binding returns. + */ + scr=SCREEN_OF(thing); + call_binding(binding, thing); + } +} + +static Bool commandmode_event_scanner(Display *dpy, XEvent *ev, char *args) +{ + switch(ev->type){ + case FocusIn: + case FocusOut: + return (ev->xfocus.mode==NotifyUngrab); + break; + case EnterNotify: + return (ev->xcrossing.mode==NotifyUngrab); + break; + default: + break; + } + return False; +} + +static bool commandmode_keyboard_handler(WThing *thing, XEvent *ev) +{ + /* we get called with commandmode_active==TRUE, if there was + another GrabHandler active at commandmode_leave() time */ + if(commandmode_active==FALSE) + return TRUE; + + assert(ev->type!=KeyRelease); + if(ev->type==KeyPress){ + commandmode_keypress_handler(thing, &ev->xkey); + } + + if(!commandmode_active){ + /* prevent FocusIn, FocusOut, EnterNotify events at command-mode-leave time; + * not doing so would result in flipping the focus to the window containing + * the pointer (X's PointerRoot mode, when grab's are held). + */ + XEvent tmp; + XSync(wglobal.dpy, False); + while(XCheckIfEvent(wglobal.dpy, &tmp, commandmode_event_scanner, NULL)); + + /* enforce refocus on the "current thing"; this is necessary to get + * the focussing of WClientWin's right when the commandmode was used to + * "switch_tab" only and the clients received their FocusOut. + */ + thing=get_current_from_thing(thing); + if(thing && WTHING_IS(thing, WWindow)) + set_focus((WRegion*)thing); + } + return !commandmode_active; +} + +/*}}}*/ diff -ubNr --exclude-from=/home/azzit/diffrc/ion.conf ion-devel-20020130-grab/commandmode/command.h ion-devel-20020130/commandmode/command.h --- ion-devel-20020130-grab/commandmode/command.h Thu Jan 1 01:00:00 1970 +++ ion-devel-20020130/commandmode/command.h Sat Feb 16 03:15:24 2002 @@ -0,0 +1,18 @@ +/* + * commandmode/command.h + * + * Copyright (c) Lukas Schroeder 2002. + * See the included file LICENSE for details. + */ + +#ifndef COMMANDMODE_COMMAND_H +#define COMMANDMODE_COMMAND_H + + + +void commandmode_enter(WThing *thing); +void commandmode_leave(WThing *thing); + + +#endif + diff -ubNr --exclude-from=/home/azzit/diffrc/ion.conf ion-devel-20020130-grab/commandmode/main.c ion-devel-20020130/commandmode/main.c --- ion-devel-20020130-grab/commandmode/main.c Thu Jan 1 01:00:00 1970 +++ ion-devel-20020130/commandmode/main.c Sat Feb 16 04:28:19 2002 @@ -0,0 +1,79 @@ +/* + * ion/main.c + * + * Copyright (c) Lukas Schroeder 2002 + * See the included file LICENSE for details. + */ + +#include +#include +#include +#include +#include +#include + +#include "command.h" + +/*{{{ Definitions */ + +WBindmap *commandmode_bindmap=NULL; + +/*}}}*/ + + +/*{{{ Config */ + +static WFunction commandmode_main_funtab[]={ + FN_VOID(generic, WFrame, "commandmode_enter", commandmode_enter), + FN_VOID(generic, WFrame, "commandmode_leave", commandmode_leave), + END_FUNTAB +}; + + +static bool commandmode_begin_bindings(Tokenizer *tokz, int n, Token *toks) +{ + return wmcore_begin_bindings(commandmode_bindmap, &ion_main_funclist, NULL); +} + + +static ConfOpt query_opts[]={ + {"bindings", NULL, commandmode_begin_bindings, wmcore_binding_opts}, + END_CONFOPTS +}; + + +/*}}}*/ + + +/*{{{ Init & deinit */ + +void commandmode_deinit(); + + +bool commandmode_init() +{ + bool ret; + + commandmode_bindmap=create_bindmap(); + if(commandmode_bindmap==NULL) + return FALSE; + + ret=add_to_funclist(&ion_main_funclist, commandmode_main_funtab); + + if(ret) + ret=read_config_for("commandmode", query_opts); + + if(!ret) + commandmode_deinit(); + + return ret; +} + +void commandmode_deinit() +{ + destroy_bindmap(commandmode_bindmap); + commandmode_bindmap=NULL; +} + +/*}}}*/ + diff -ubNr --exclude-from=/home/azzit/diffrc/ion.conf ion-devel-20020130-grab/commandmode/main.h ion-devel-20020130/commandmode/main.h --- ion-devel-20020130-grab/commandmode/main.h Thu Jan 1 01:00:00 1970 +++ ion-devel-20020130/commandmode/main.h Sat Feb 16 03:20:39 2002 @@ -0,0 +1,14 @@ +/* + * commandmode/main.h + * + * Copyright (c) Lukas Schroeder 2002. + * See the included file LICENSE for details. + */ + +#ifndef COMMANDMODE_MAIN_H +#define COMMANDMODE_MAIN_H + +extern bool commandmode_init(); +extern void commandmode_deinit(); + +#endif /* COMMANDMODE_MAIN_H */ diff -ubNr --exclude-from=/home/azzit/diffrc/ion.conf ion-devel-20020130-grab/query/fwarn.c ion-devel-20020130/query/fwarn.c --- ion-devel-20020130-grab/query/fwarn.c Sat Dec 29 20:04:33 2001 +++ ion-devel-20020130/query/fwarn.c Sat Feb 16 06:15:45 2002 @@ -10,6 +10,7 @@ #include #include #include "wmessage.h" +#include "query.h" void fwarn(WFrame *frame, const char *p) @@ -33,6 +34,12 @@ } map_region((WRegion*)wmsg); + + /* this grab will be destroyed at the same time destroy_thing is called for this wedln. + * the watch system will do it. no need to catch the finish or cancel ways out. + */ + grab_establish((WThing*)wmsg, query_keyboard_handler, FocusChangeMask|KeyReleaseMask); + if(REGION_IS_ACTIVE(frame)){ set_focus((WRegion*)wmsg); diff -ubNr --exclude-from=/home/azzit/diffrc/ion.conf ion-devel-20020130-grab/query/query.c ion-devel-20020130/query/query.c --- ion-devel-20020130-grab/query/query.c Sat Jan 26 21:14:16 2002 +++ ion-devel-20020130/query/query.c Sat Feb 16 06:25:59 2002 @@ -15,11 +15,13 @@ #include #include #include +#include #include #include #include #include #include "query.h" +#include "inputp.h" #include "wedln.h" #include "complete_file.h" #include "wmessage.h" @@ -27,6 +29,51 @@ #define FWARN(ARGS) fwarn_free((WFrame*)thing, errmsg ARGS) +/*{{{ Definitions */ + + + +/*}}}*/ + +/*{{{ grab handler */ + +bool query_keyboard_handler(WThing *thing, XEvent *xev) +{ + XKeyEvent *ev = &xev->xkey; + WScreen *scr; + WBinding *binding=NULL; + bool topmap=TRUE; + bool toplvl=FALSE; + + if(!thing || (!WTHING_IS(thing, WEdln) && !WTHING_IS(thing, WMessage))) + return FALSE; + + binding=lookup_binding(query_bindmap, ACT_KEYPRESS, ev->state, ev->keycode); + + if(!binding){ + if(ismod(ev->keycode)) + return FALSE; + } + + if(binding!=NULL && binding->submap!=NULL){ + /* we dont allow submap grabs in query-mode! */ + return FALSE; + } + + if(binding){ + /* Get the screen now for waitrel grab - the thing might + * have been destroyed when call_binding returns. + */ + scr=SCREEN_OF(thing); + call_binding(binding, thing); + }else if(WTHING_IS(thing, WEdln)){ + insstr_from_event((WWindow*)thing, ev); + } + return FALSE; +} + +/*}}}*/ + /*{{{ Generic */ @@ -48,8 +95,13 @@ wedln=(WEdln*)frame_attach_input_new(frame, (WRegionCreateFn*)create_wedln, (void*)&fnp); - if(wedln!=NULL) + if(wedln!=NULL){ map_region((WRegion*)wedln); + /* this grab will be destroyed at the same time destroy_thing is called for this wedln. + * the watch system will do it. no need to catch the finish or cancel ways out. + */ + grab_establish((WThing*)wedln, query_keyboard_handler, FocusChangeMask|KeyReleaseMask); + } if(REGION_IS_ACTIVE(frame)){ set_focus((WRegion*)wedln); diff -ubNr --exclude-from=/home/azzit/diffrc/ion.conf ion-devel-20020130-grab/query/query.h ion-devel-20020130/query/query.h --- ion-devel-20020130-grab/query/query.h Sat Dec 29 20:04:34 2001 +++ ion-devel-20020130/query/query.h Sat Feb 16 05:19:00 2002 @@ -11,6 +11,8 @@ #include #include +bool query_keyboard_handler(WThing *thing, XEvent *ev); + extern void query_exec(WFrame *frame); extern void query_runwith(WFrame *frame, char *cmd, char *prompt); extern void query_runfile(WFrame *frame, char *cmd, char *prompt); diff -ubNr --exclude-from=/home/azzit/diffrc/ion.conf ion-devel-20020130-grab/query/wedln.c ion-devel-20020130/query/wedln.c --- ion-devel-20020130-grab/query/wedln.c Sat Dec 29 20:04:34 2001 +++ ion-devel-20020130/query/wedln.c Sat Feb 16 05:39:36 2002 @@ -17,6 +17,7 @@ #include "edln.h" #include "wedln.h" #include "inputp.h" +#include "query.h" #define TEXT_AREA_HEIGHT(GRDATA) \ diff -ubNr --exclude-from=/home/azzit/diffrc/ion.conf ion-devel-20020130-grab/src/Makefile ion-devel-20020130/src/Makefile --- ion-devel-20020130-grab/src/Makefile Wed Jan 30 22:49:28 2002 +++ ion-devel-20020130/src/Makefile Sat Feb 16 02:14:47 2002 @@ -19,7 +19,7 @@ funtab.o main.o placement.o resize.o split.o splitframe.o \ winprops.o workspace.o confws.o commandsq.o -EXT_OBJS= ../query/query.a ../wmcore/wmcore.a +EXT_OBJS= ../query/query.a ../commandmode/commandmode.a ../wmcore/wmcore.a TARGETS=ion diff -ubNr --exclude-from=/home/azzit/diffrc/ion.conf ion-devel-20020130-grab/src/main.c ion-devel-20020130/src/main.c --- ion-devel-20020130-grab/src/main.c Sat Jan 19 20:21:49 2002 +++ ion-devel-20020130/src/main.c Sat Feb 16 03:20:51 2002 @@ -19,6 +19,7 @@ #include #include #include +#include #include "conf.h" #include "funtab.h" #include "../version.h" @@ -108,6 +109,7 @@ init_funclists(); init_hooks(); query_init(); + commandmode_init(); if(!ion_read_config(cfgfile)) goto configfail; diff -ubNr --exclude-from=/home/azzit/diffrc/ion.conf ion-devel-20020130-grab/wmcore/key.c ion-devel-20020130/wmcore/key.c --- ion-devel-20020130-grab/wmcore/key.c Sat Feb 16 00:07:50 2002 +++ ion-devel-20020130/wmcore/key.c Sat Feb 16 05:24:29 2002 @@ -8,17 +8,17 @@ #include #include "common.h" -#include "key.h" #include "binding.h" #include "global.h" #include "event.h" #include "cursor.h" #include "objp.h" +#include "key.h" static void waitrelease(WScreen *screen); -static void insstr(WWindow *wwin, XKeyEvent *ev) +void insstr_from_event(WWindow *wwin, XKeyEvent *ev) { static XComposeStatus cs={NULL, 0}; char buf[16]={0,}; @@ -164,7 +164,7 @@ if(binding!=NULL) dispatch_binding(reg, binding, ev); else if(topmap){ - insstr((WWindow*)reg, ev); + insstr_from_event((WWindow*)reg, ev); } } diff -ubNr --exclude-from=/home/azzit/diffrc/ion.conf ion-devel-20020130-grab/wmcore/key.h ion-devel-20020130/wmcore/key.h --- ion-devel-20020130-grab/wmcore/key.h Sat Dec 29 20:04:39 2001 +++ ion-devel-20020130/wmcore/key.h Sat Feb 16 04:59:37 2002 @@ -13,5 +13,6 @@ #include "common.h" extern void handle_keypress(XKeyEvent *ev); +extern void insstr_from_event(WWindow *wwin, XKeyEvent *ev); #endif /* WMCORE_KEY_H */