|
[PATCH 3/11] send keyevents with icesh: msg#00016window-managers.icewm.devel
you can now send key events to windows with icesh --- diff -urp old/src/icesh.cc new/src/icesh.cc --- old/src/icesh.cc 2006-09-10 18:12:10.000000000 +0200 +++ new/src/icesh.cc 2006-11-08 17:24:37.792070662 +0100 @@ -459,6 +459,91 @@ Status setTrayHint(Window window, long t return XSendEvent(display, root, False, SubstructureNotifyMask, (XEvent *) &xev); } +bool parseKey(const char *arg, KeySym *key, unsigned int *mod) { + const char *orig_arg = arg; + + *mod = 0; + for (;;) { + if (strncmp("Alt+", arg, 4) == 0) { + *mod |= Mod1Mask; + arg += 4; + } else if (strncmp("Ctrl+", arg, 5) == 0) { + *mod |= ControlMask; + arg += 5; + } else if (strncmp("Shift+", arg, 6) == 0) { + *mod |= ShiftMask; + arg += 6; + } else if (strncmp("Meta+", arg, 5) == 0) { + *mod |= Mod2Mask; + arg += 5; + } else if (strncmp("Super+", arg, 6) == 0) { + *mod |= Mod3Mask; + arg += 6; + } else if (strncmp("Hyper+", arg, 6) == 0) { + *mod |= Mod4Mask; + arg += 6; + } else + break; + } + if (strcmp(arg, "") == 0) { + *key = NoSymbol; + return true; + } else if (strcmp(arg, "Esc") == 0) + *key = XK_Escape; + else if (strcmp(arg, "Enter") == 0) + *key = XK_Return; + else if (strcmp(arg, "Space") == 0) + *key = ' '; + else if (strcmp(arg, "BackSp") == 0) + *key = XK_BackSpace; + else if (strcmp(arg, "Del") == 0) + *key = XK_Delete; + else if (strlen(arg) == 1 && arg[0] >= 'A' && arg[0] <= 'Z') { + char s[2]; + s[0] = arg[0] - 'A' + 'a'; + s[1] = 0; + *key = XStringToKeysym(s); + } else { + *key = XStringToKeysym(arg); + } + + if (*key == NoSymbol) { + msg(_("Unknown key name %s in %s"), arg, orig_arg); + return false; + } + return true; +} + +Status sendKeyEvent(Window window, const char *key) { + XKeyEvent event; + KeySym sym = NoSymbol; + unsigned int mod = 0; + KeyCode code; + + if (!parseKey(key, &sym, &mod)) + MSG(("parseKey error")); + + code = XKeysymToKeycode(display, sym); + + event.display = display; + event.window = window; + event.root = root; + event.subwindow = None; + event.time = CurrentTime; + event.x = 1; + event.y = 1; + event.x_root = 1; + event.y_root = 1; + event.same_screen = True; + event.send_event = True; + + event.type = KeyPress; + event.keycode = code; + event.state = mod; + + return XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *)&event); +} + /******************************************************************************/ Window getClientWindow(Window window) @@ -541,43 +626,47 @@ Window pickWindow (void) { /******************************************************************************/ static void printUsage() { - printf(_("\ -Usage: %s [OPTIONS] ACTIONS\n\ -\n\ -Options:\n\ - -display DISPLAY Connects to the X server specified by DISPLAY.\n\ - Default: $DISPLAY or :0.0 when not set.\n\ - -window WINDOW_ID Specifies the window to manipulate. Special\n\ - identifiers are `root' for the root window and\n\ - `focus' for the currently focused window.\n\ - -class WM_CLASS Window management class of the window(s) to\n\ - manipulate. If WM_CLASS contains a period, only\n\ - windows with exactly the same WM_CLASS property\n\ - are matched. If there is no period, windows of\n\ - the same class and windows of the same instance\n\ - (aka. `-name') are selected.\n\ -\n\ -Actions:\n\ - setIconTitle TITLE Set the icon title.\n\ - setWindowTitle TITLE Set the window title.\n\ - setGeometry geometry Set the window geometry\n\ - setState MASK STATE Set the GNOME window state to STATE.\n\ - Only the bits selected by MASK are affected.\n\ - STATE and MASK are expressions of the domain\n\ - `GNOME window state'.\n\ - toggleState STATE Toggle the GNOME window state bits specified by\n\ - the STATE expression.\n\ - setHints HINTS Set the GNOME window hints to HINTS.\n\ - setLayer LAYER Moves the window to another GNOME window layer.\n\ - setWorkspace WORKSPACE Moves the window to another workspace. Select\n\ - the root window to change the current workspace.\n\ - listWorkspaces Lists the names of all workspaces.\n\ - setTrayOption TRAYOPTION Set the IceWM tray option hint.\n\ -\n\ -Expressions:\n\ - Expressions are list of symbols of one domain concatenated by `+' or `|':\n\ -\n\ - EXPRESSION ::= SYMBOL | EXPRESSION ( `+' | `|' ) SYMBOL\n\n"), + printf(_( +"Usage: %s [OPTIONS] ACTIONS\n" +"\n" +"Options:\n" +" -display DISPLAY Connects to the X server specified by DISPLAY.\n" +" Default: $DISPLAY or :0.0 when not set.\n" +" -window WINDOW_ID Specifies the window to manipulate. Special\n" +" identifiers are `root' for the root window and\n" +" `focus' for the currently focused window.\n" +" -class WM_CLASS Window management class of the window(s) to\n" +" manipulate. If WM_CLASS contains a period, only\n" +" windows with exactly the same WM_CLASS property\n" +" are matched. If there is no period, windows of\n" +" the same class and windows of the same instance\n" +" (aka. `-name') are selected.\n" +#ifdef DEBUG +" -debug show debug info\n" +#endif +"\n" +"Actions:\n" +" setIconTitle TITLE Set the icon title.\n" +" setWindowTitle TITLE Set the window title.\n" +" setGeometry geometry Set the window geometry\n" +" setState MASK STATE Set the GNOME window state to STATE.\n" +" Only the bits selected by MASK are affected.\n" +" STATE and MASK are expressions of the domain\n" +" `GNOME window state'.\n" +" toggleState STATE Toggle the GNOME window state bits specified by\n" +" the STATE expression.\n" +" setHints HINTS Set the GNOME window hints to HINTS.\n" +" setLayer LAYER Moves the window to another GNOME window layer.\n" +" setWorkspace WORKSPACE Moves the window to another workspace. Select\n" +" the root window to change the current workspace.\n" +" listWorkspaces Lists the names of all workspaces.\n" +" setTrayOption TRAYOPTION Set the IceWM tray option hint.\n" +" sendKeyEvent KEYCOMBINATION Send KEYCOMBINATION to window.\n" +"\n" +"Expressions:\n" +" Expressions are list of symbols of one domain concatenated by `+' or `|':\n" +"\n" +" EXPRESSION ::= SYMBOL | EXPRESSION ( `+' | `|' ) SYMBOL\n\n"), ApplicationName); states.listSymbols(_("GNOME window state")); @@ -747,8 +836,10 @@ int main(int argc, char **argv) { if (windowList[i] != None && XGetClassHint(display, windowList[i], &classhint)) { if (wmclass) { - if (strcmp(classhint.res_name, wmname) || - strcmp(classhint.res_class, wmclass)) + if ((strcmp(classhint.res_name, wmname) || + strcmp(classhint.res_class, wmclass)) && + (strcmp(classhint.res_name, wmclass) || + strcmp(classhint.res_class, wmname))) windowList[i] = None; } else { if (strcmp(classhint.res_name, wmname) && @@ -770,6 +861,9 @@ int main(int argc, char **argv) { MSG(("windowCount: %d", windowCount)); + if (windowCount == 0) + return 1; + /******************************************************************************/ while (argp < argv + argc) { @@ -885,6 +979,12 @@ int main(int argc, char **argv) { MSG(("setTrayOption: %d", trayopt)); FOREACH_WINDOW(window) setTrayHint(*window, trayopt); + } else if (!strcmp(action, "sendKeyEvent")) { + CHECK_ARGUMENT_COUNT (1) + + MSG(("sendKeyEvent: `%s'", *argp)); + FOREACH_WINDOW(window) sendKeyEvent(*window, *argp); + argp++; } else { msg(_("Unknown action: `%s'"), action); THROW(1); ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | [PATCH 2/11]: 00016, Bert Wesarg |
|---|---|
| Next by Date: | [PATCH 4/11] improve genpref output: 00016, Bert Wesarg |
| Previous by Thread: | [PATCH 2/11]i: 00016, Bert Wesarg |
| Next by Thread: | [PATCH 4/11] improve genpref output: 00016, Bert Wesarg |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |