static void apply_changes_on_x(const char *current, const String *previous) { if(repeat_press_value) XAutoRepeatOn(fl_display); else XAutoRepeatOff(fl_display); /* do not do anything if selected layout is the same as previous */ if(!previous || *previous != current) { /* * believe me, it is easier to call this command than to reimplmement a mess for * uploading keyboard layout on X server! */ String setxkbmap = file_path("setxkbmap"); if(setxkbmap.empty()) { alert(_("Unable to find 'setxkbmap' tool.\n\nThis tool is used as helper tool for " "easier keyboard setup and is standard tool shipped with every X package. " "Please install it first and run this program again.")); } else { int ret = run_sync("%s %s", setxkbmap.c_str(), current); /* do not show dialog since we can fail if config has bad entry when called from apply_chages_from_config() */ if(ret != 0) E_WARNING(E_STRLOC ": 'setxkbmap %s' failed with %i\n", current, ret); } } /* force panel applet to re-read config file to see if flag should be displayed or not */ foreign_callback_call(PANEL_APPLET_ID); }
void VirtualConsole::setMode(Mode mode) { Display* display; display = XOpenDisplay(NULL); ASSERT(display != NULL); /* Set auto repeat off when in "Operate" mode and on * again when vc is put to "Design" mode. */ if (mode == Design) { m_mode = Design; m_menuBar->setItemChecked(ID_VC_MODE_DESIGN, true); m_menuBar->setItemChecked(ID_VC_MODE_OPERATE, false); m_menuBar->setItemEnabled(ID_VC_ADD, true); setCaption("Virtual Console - Design Mode"); XAutoRepeatOn(display); } else { m_mode = Operate; m_menuBar->setItemChecked(ID_VC_MODE_DESIGN, false); m_menuBar->setItemChecked(ID_VC_MODE_OPERATE, true); m_menuBar->setItemEnabled(ID_VC_ADD, false); setCaption("Virtual Console - Operate Mode"); XAutoRepeatOff(display); } XCloseDisplay(display); }
void S9xGraphicsMode () { if (is_graphics) return; XSelectInput (ourdisp, inputwin, KeyPressMask | KeyReleaseMask); XSetInputFocus (ourdisp, inputwin, RevertToNone, CurrentTime); XGrabKeyboard (ourdisp, inputwin, True, GrabModeAsync, GrabModeAsync, CurrentTime); XGrabPointer (ourdisp, inputwin, True, 0, GrabModeAsync, GrabModeAsync, inputwin, None, CurrentTime); XFlush(ourdisp); XAutoRepeatOff (ourdisp); #ifdef USE_XF86VIDMODE if (orig_mode != mod320x240) { XF86VidModeSwitchToMode (ourdisp,ourscreen, mod320x240); } XFlush (ourdisp); XF86VidModeSetViewPort (ourdisp, ourscreen, 0, 0); XFlush (ourdisp); #endif XF86DGADirectVideo (ourdisp, ourscreen, XF86DGADirectGraphics); memset ((void *) ourvideo.vidMemBegin, 0, ourvideo.width * 240 * ourvideo.screendepth); is_graphics = TRUE; XFlush (ourdisp); }
// // Check to see if we have grabbed the mouse or not and deal with it // appropriately // static void CheckMouseState(void) { if (x_focus && _windowed_mouse.value && !x_grabbed) { x_grabbed = true; printf("fooling with mouse!\n"); if (XGetPointerControl( x_disp, &x_mouse_num, &x_mouse_denom, &x_mouse_thresh )) printf( "XGetPointerControl failed!\n" ); //printf( "mouse %d/%d thresh %d\n", x_mouse_num, x_mouse_denom, x_mouse_thresh ); // make input rawer XAutoRepeatOff(x_disp); XGrabKeyboard(x_disp, x_win, True, GrabModeAsync, GrabModeAsync, CurrentTime); XGrabPointer(x_disp, x_win, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); // if (XChangePointerControl( x_disp, True, True, 1, MOUSE_SCALE, x_mouse_thresh )) // printf( "XChangePointerControl failed!\n" ); IN_CenterMouse(); // safe initial values x_root = x_root_old = vid.width >> 1; y_root = y_root_old = vid.height >> 1; } else if (x_grabbed && (!_windowed_mouse.value || !x_focus)) {
void IN_Frame (void) { if ( cls.keyCatchers || cls.state != CA_ACTIVE ) { // temporarily deactivate if not in the game and // running on the desktop // voodoo always counts as full screen if (Cvar_VariableValue ("r_fullscreen") == 0 && strcmp( Cvar_VariableString("r_glDriver"), _3DFX_DRIVER_NAME ) ) { IN_DeactivateMouse (); return; } if (dpy && !autorepeaton) { XAutoRepeatOn(dpy); autorepeaton = qtrue; } } else if (dpy && autorepeaton) { XAutoRepeatOff(dpy); autorepeaton = qfalse; } IN_ActivateMouse(); // post events to the system que IN_MouseMove(); }
void Window::OnFocusIn(void) { //FIXME: Hay que volver a obtener el ratón // Guardamos el estado del teclado para poder restaurarlo XGetKeyboardControl(this->dpy, &deskKeyboardState); // Y quitamos el auto_repeat XAutoRepeatOff(this->dpy); };
// // Set the mode (Design/Operate) // void VirtualConsole::slotModeChanged() { QString config; // // Key repeat // _app->settings()->get(KEY_VIRTUAL_CONSOLE_KEYREPEAT, config); if (config == Settings::trueValue()) { Display* display; display = XOpenDisplay(NULL); ASSERT(display != NULL); if (_app->mode() == App::Design) { XAutoRepeatOn(display); } else { XAutoRepeatOff(display); } XCloseDisplay(display); } // // Grab keyboard // _app->settings()->get(KEY_VIRTUAL_CONSOLE_GRABKB, config); if (config == Settings::trueValue()) { if (_app->mode() == App::Design) { releaseKeyboard(); } else { grabKeyboard(); } } if (_app->mode() == App::Operate) { // Don't allow editing in operate mode m_editMenu->setEnabled(false); m_addMenu->setEnabled(false); m_toolsMenu->setItemEnabled(KVCMenuToolsSettings, false); } else { // Allow editing in design mode m_editMenu->setEnabled(true); m_addMenu->setEnabled(true); m_toolsMenu->setItemEnabled(KVCMenuToolsSettings, true); } }
void KeyboardAutoRepeatOff(void) { #if defined(TARGET_SDL) SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL); SDL_EnableUNICODE(0); #else if (display) XAutoRepeatOff(display); #endif }
void SetAutoRepeat(bool autorep) { #if 0 // TODO OSX similar logic for OSX if (toggleAutoRepeat) { if (autorep) XAutoRepeatOn(GSdsp); else XAutoRepeatOff(GSdsp); } #endif }
void SetAutoRepeat(bool autorep) { #ifdef __linux__ if (toggleAutoRepeat) { if (autorep) XAutoRepeatOn(GSdsp); else XAutoRepeatOff(GSdsp); } #endif }
void SetAutoRepeat(bool autorep) { #if defined(__unix__) if (toggleAutoRepeat) { if (autorep) XAutoRepeatOn(GSdsp); else XAutoRepeatOff(GSdsp); } #endif }
/* init_X opens the display and sets up all the color stuff */ void init_X() { display = XOpenDisplay(NULL); if (display == NULL) { fprintf(stderr, "Jetpack : Cannot connect to X Server %s\n", XDisplayName(NULL)); exit(1); } /* @JTL: Disable auto-repeat, because we only want a key event to be * registered once. */ XAutoRepeatOff(display); rootwindow = DefaultRootWindow(display); screen = DefaultScreen(display); colormap = DefaultColormap(display, screen); depth = DefaultDepth(display, screen); set_up_colors(); set_up_contexts(); }
static void meta_input_settings_x11_set_keyboard_repeat (MetaInputSettings *settings, gboolean enabled, guint delay, guint interval) { MetaBackend *backend = meta_get_backend (); Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend)); if (enabled) { XAutoRepeatOn (xdisplay); XkbSetAutoRepeatRate (xdisplay, XkbUseCoreKbd, delay, interval); } else { XAutoRepeatOff (xdisplay); } }
int main(int argv, char* argc[]){ XInfo* xinfo = new XInfo(argv, argc); //start game with coulmns in middle of screen int currentX = xinfo->windowWidth / 2; std::list<Column*>* columns = new std::list<Column*>(); //construct level for(int i = 0; i < 500; i++){ Column* col = new Column(currentX, *xinfo); columns->push_back(col); currentX += col->getWidth(); } Helicopter* airWolf = new Helicopter(*xinfo, *columns); Painter* mario = new Painter(*columns, *airWolf); EventHandler* God = new EventHandler(*mario, *columns, *airWolf); //turn auto repeat off to avoid auto-repeat lag XAutoRepeatOff(xinfo->display); //intro screen mario->specialScreen(*xinfo, PAUSE); God->deal(*xinfo); XAutoRepeatOn(xinfo->display); XFlush(xinfo->display); sleep(10); XCloseDisplay(xinfo->display); //clean up delete columns; delete airWolf; //other classes are not complicated //let default destructors handle things return 0; }
// Returns false if completely handled within this function and no further analyze is necessary. bool PlatformAnalyzeKeyEvent(keyEvent &evt) { #if 0 // TODO OSX similar logic for OSX KeySym key = (KeySym)evt.key; switch (evt.evt) { case KeyPress: // Shift F12 is not yet use by pcsx2. So keep it to grab/ungrab input // I found it very handy vs the automatic fullscreen detection // 1/ Does not need to detect full-screen // 2/ Can use a debugger in full-screen // 3/ Can grab input in window without the need of a pixelated full-screen if (key == XK_Shift_R || key == XK_Shift_L) s_Shift = true; if (key == XK_F12 && s_Shift) { if(!s_grab_input) { s_grab_input = true; XGrabPointer(GSdsp, GSwin, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, GSwin, None, CurrentTime); XGrabKeyboard(GSdsp, GSwin, True, GrabModeAsync, GrabModeAsync, CurrentTime); } else { s_grab_input = false; XUngrabPointer(GSdsp, CurrentTime); XUngrabKeyboard(GSdsp, CurrentTime); } } break; case KeyRelease: if (key == XK_Shift_R || key == XK_Shift_L) s_Shift = false; break; case FocusIn: XAutoRepeatOff(GSdsp); break; case FocusOut: XAutoRepeatOn(GSdsp); break; } #endif return true; }
/*+++++++++++++++++++++++++++++++++++++++*/ static void autoRepeatToggleCB( Widget w, XtPointer client_data, XtPointer call_data ) { /* set auto repeat to new value */ if (((XmToggleButtonCallbackStruct *)call_data)->set) { XAutoRepeatOn(style.display); kbd.new_autoRepeat = AutoRepeatModeOn; } else { XAutoRepeatOff(style.display); kbd.new_autoRepeat = AutoRepeatModeOff; } kbd.systemDefaultFlag = False; }
void gdk_key_repeat_restore (void) { if (autorepeat) XAutoRepeatOn (gdk_display); else XAutoRepeatOff (gdk_display); }
void AnalyzeKeyEvent(int pad, keyEvent &evt) { KeySym key = (KeySym)evt.key; int index = get_keyboard_key(pad, key); switch (evt.evt) { case KeyPress: // Shift F12 is not yet use by pcsx2. So keep it to grab/ungrab input // I found it very handy vs the automatic fullscreen detection // 1/ Does not need to detect full-screen // 2/ Can use a debugger in full-screen // 3/ Can grab input in window without the need of a pixelated full-screen if (key == XK_Shift_R || key == XK_Shift_L) s_Shift = true; if (key == XK_F12 && s_Shift) { if(!s_grab_input) { s_grab_input = true; XGrabPointer(GSdsp, GSwin, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, GSwin, None, CurrentTime); XGrabKeyboard(GSdsp, GSwin, True, GrabModeAsync, GrabModeAsync, CurrentTime); } else { s_grab_input = false; XUngrabPointer(GSdsp, CurrentTime); XUngrabKeyboard(GSdsp, CurrentTime); } } // Analog controls. if (IsAnalogKey(index)) { switch (index) { case PAD_R_LEFT: case PAD_R_UP: case PAD_L_LEFT: case PAD_L_UP: key_status->press(pad, index, -MAX_ANALOG_VALUE); break; case PAD_R_RIGHT: case PAD_R_DOWN: case PAD_L_RIGHT: case PAD_L_DOWN: key_status->press(pad, index, MAX_ANALOG_VALUE); break; } } else if (index != -1) key_status->press(pad, index); //PAD_LOG("Key pressed:%d\n", index); event.evt = KEYPRESS; event.key = key; break; case KeyRelease: if (key == XK_Shift_R || key == XK_Shift_L) s_Shift = false; if (index != -1) key_status->release(pad, index); event.evt = KEYRELEASE; event.key = key; break; case FocusIn: XAutoRepeatOff(GSdsp); break; case FocusOut: XAutoRepeatOn(GSdsp); break; case ButtonPress: if (index != -1) key_status->press(pad, index); break; case ButtonRelease: if (index != -1) key_status->release(pad, index); break; case MotionNotify: // FIXME: How to handle when the mouse does not move, no event generated!!! // 1/ small move == no move. Cons : can not do small movement // 2/ use a watchdog timer thread // 3/ ??? idea welcome ;) if (conf->options & ((PADOPTION_MOUSE_L|PADOPTION_MOUSE_R) << 16 * pad )) { unsigned int pad_x; unsigned int pad_y; // Note when both PADOPTION_MOUSE_R and PADOPTION_MOUSE_L are set, take only the right one if (conf->options & (PADOPTION_MOUSE_R << 16 * pad)) { pad_x = PAD_R_RIGHT; pad_y = PAD_R_UP; } else { pad_x = PAD_L_RIGHT; pad_y = PAD_L_UP; } unsigned x = evt.key & 0xFFFF; unsigned int value = (s_previous_mouse_x > x) ? s_previous_mouse_x - x : x - s_previous_mouse_x; value *= conf->sensibility; if (x == 0) key_status->press(pad, pad_x, -MAX_ANALOG_VALUE); else if (x == 0xFFFF) key_status->press(pad, pad_x, MAX_ANALOG_VALUE); else if (x < (s_previous_mouse_x -2)) key_status->press(pad, pad_x, -value); else if (x > (s_previous_mouse_x +2)) key_status->press(pad, pad_x, value); else key_status->release(pad, pad_x); unsigned y = evt.key >> 16; value = (s_previous_mouse_y > y) ? s_previous_mouse_y - y : y - s_previous_mouse_y; value *= conf->sensibility; if (y == 0) key_status->press(pad, pad_y, -MAX_ANALOG_VALUE); else if (y == 0xFFFF) key_status->press(pad, pad_y, MAX_ANALOG_VALUE); else if (y < (s_previous_mouse_y -2)) key_status->press(pad, pad_y, -value); else if (y > (s_previous_mouse_y +2)) key_status->press(pad, pad_y, value); else key_status->release(pad, pad_y); s_previous_mouse_x = x; s_previous_mouse_y = y; } break; }
/* * Creates the playing windows. * Returns 0 on success, -1 on error. */ int Init_playing_windows(void) { unsigned w, h; Pixmap pix; GC cursorGC; if (!topWindow) { if (Init_top()) return -1; } Scale_dashes(); draw_width = top_width - (256 + 2); draw_height = top_height; drawWindow = XCreateSimpleWindow(dpy, topWindow, 258, 0, draw_width, draw_height, 0, 0, colors[BLACK].pixel); radarWindow = XCreateSimpleWindow(dpy, topWindow, 0, 0, 256, RadarHeight, 0, 0, colors[BLACK].pixel); radar_score_mapped = true; /* Create buttons */ #define BUTTON_WIDTH 84 ButtonHeight = buttonFont->ascent + buttonFont->descent + 2*BTN_BORDER; button_form = Widget_create_form(0, topWindow, 0, (int)RadarHeight, 256, ButtonHeight + 2, 0); Widget_create_activate(button_form, 0 + 0*BUTTON_WIDTH, 0, BUTTON_WIDTH, ButtonHeight, 1, "QUIT", Quit_callback, NULL); Widget_create_activate(button_form, 1 + 1*BUTTON_WIDTH, 0, BUTTON_WIDTH, ButtonHeight, 1, "ABOUT", About_callback, NULL); menu_button = Widget_create_menu(button_form, 2 + 2*BUTTON_WIDTH, 0, BUTTON_WIDTH, ButtonHeight, 1, "MENU"); Widget_add_pulldown_entry(menu_button, "KEYS", Keys_callback, NULL); Widget_add_pulldown_entry(menu_button, "CONFIG", Config_callback, NULL); Widget_add_pulldown_entry(menu_button, "COLORS", Colors_callback, NULL); Widget_add_pulldown_entry(menu_button, "SCORE", Score_callback, NULL); Widget_add_pulldown_entry(menu_button, "PLAYER", Player_callback, NULL); Widget_add_pulldown_entry(menu_button, "MOTD", Motd_callback, NULL); Widget_map_sub(button_form); /* Create score list window */ players_width = RadarWidth; players_height = top_height - (RadarHeight + ButtonHeight + 2); playersWindow = XCreateSimpleWindow(dpy, topWindow, 0, (int)RadarHeight + ButtonHeight + 2, players_width, players_height, 0, 0, colors[windowColor].pixel); /* * Selecting the events we can handle. */ XSelectInput(dpy, radarWindow, ExposureMask); XSelectInput(dpy, playersWindow, ExposureMask); XSelectInput(dpy, drawWindow, ButtonPressMask | ButtonReleaseMask); /* * Initialize misc. pixmaps if we're not color switching. * (This could be in dbuff_init_buffer completely IMHO, -- Metalite) */ switch (dbuf_state->type) { case PIXMAP_COPY: radarPixmap = XCreatePixmap(dpy, radarWindow, 256, RadarHeight, dispDepth); radarPixmap2 = XCreatePixmap(dpy, radarWindow, 256, RadarHeight, dispDepth); drawPixmap = XCreatePixmap(dpy, drawWindow, draw_width, draw_height, dispDepth); break; case MULTIBUFFER: radarPixmap = XCreatePixmap(dpy, radarWindow, 256, RadarHeight, dispDepth); radarPixmap2 = XCreatePixmap(dpy, radarWindow, 256, RadarHeight, dispDepth); dbuff_init_buffer(dbuf_state); break; case COLOR_SWITCH: radarPixmap2 = radarWindow; radarPixmap = radarWindow; drawPixmap = drawWindow; Paint_sliding_radar(); break; default: assert(0 && "Init_playing_windows: unknown dbuf state type."); break; } XAutoRepeatOff(dpy); /* We don't want any autofire, yet! */ if (kdpy) XAutoRepeatOff(kdpy); /* * Define a blank cursor for use with pointer control */ XQueryBestCursor(dpy, drawWindow, 1, 1, &w, &h); pix = XCreatePixmap(dpy, drawWindow, w, h, 1); cursorGC = XCreateGC(dpy, pix, 0, NULL); XSetForeground(dpy, cursorGC, 0); XFillRectangle(dpy, pix, cursorGC, 0, 0, w, h); XFreeGC(dpy, cursorGC); pointerControlCursor = XCreatePixmapCursor(dpy, pix, pix, &colors[BLACK], &colors[BLACK], 0, 0); XFreePixmap(dpy, pix); /* * Maps the windows, makes the visible. Voila! */ XMapSubwindows(dpy, topWindow); XMapWindow(dpy, topWindow); XSync(dpy, False); if (kdpy) { XMapWindow(kdpy, keyboardWindow); XSync(kdpy, False); } Init_spark_colors(); return 0; }
int main (int argc, char **argv) { char *displayname = NULL; char *geom = NULL; char *tablefilename = NULL; int i; XSizeHints hints; int borderwidth = 2; XSetWindowAttributes attr; XWindowAttributes wattr; unsigned long mask = 0L; int done; char *name = "X11 Keycode to Rawkey table generation tool"; Bool reverse = False; unsigned long back, fore; struct _asktable *ask; w = 0; ProgramName = argv[0]; for (i = 1; i < argc; i++) { char *arg = argv[i]; if (arg[0] == '-') { switch (arg[1]) { case 'd': /* -display host:dpy */ if (++i >= argc) usage (); displayname = argv[i]; continue; case 'g': /* -geometry geom */ if (++i >= argc) usage (); geom = argv[i]; continue; case 'o': /* table file name */ if (++i >= argc) usage (); tablefilename = argv[i]; continue; default: usage (); } /* end switch on - */ } else usage (); } /* end for over argc */ if (!tablefilename) { fprintf (stderr, "%s: output filename missing\n", ProgramName); exit(1); } memset(table, 0xFF, 256); dpy = XOpenDisplay (displayname); if (!dpy) { fprintf (stderr, "%s: unable to open display '%s'\n", ProgramName, XDisplayName (displayname)); exit (1); } XSetIOErrorHandler (MySysErrorHandler); XAutoRepeatOff(dpy); screen = DefaultScreen (dpy); /* select for all events */ attr.event_mask = KeyPressMask; set_sizehints (&hints, OUTER_WINDOW_MIN_WIDTH, OUTER_WINDOW_MIN_HEIGHT, OUTER_WINDOW_DEF_WIDTH, OUTER_WINDOW_DEF_HEIGHT, OUTER_WINDOW_DEF_X, OUTER_WINDOW_DEF_Y, geom); if (reverse) { back = BlackPixel(dpy,screen); fore = WhitePixel(dpy,screen); } else { back = WhitePixel(dpy,screen); fore = BlackPixel(dpy,screen); } attr.background_pixel = back; attr.border_pixel = fore; mask |= (CWBackPixel | CWBorderPixel | CWEventMask); w = XCreateWindow (dpy, RootWindow (dpy, screen), hints.x, hints.y, hints.width, hints.height, borderwidth, 0, InputOutput, (Visual *)CopyFromParent, mask, &attr); XSetStandardProperties (dpy, w, name, NULL, (Pixmap) 0, argv, argc, &hints); gc = XCreateGC (dpy, w, 0, 0); XMapWindow (dpy, w); XStoreName(dpy, w, name); XFlush(dpy); sleep(3); for(ask = asktable; ask->title; ask++) { doaskuser(ask->title, ask->rawkeystart, ask->numkeys, ask->nokey_ks); } fh = fopen(tablefilename,"wb"); if (!fh) { fprintf (stderr, "%s: unable to open \"%s\" in write mode\n", ProgramName, tablefilename); exit(1); } i = fwrite(table, 1, 256, fh); if (i != 256) { fprintf (stderr, "%s: writing to \"%s\" failed\n", ProgramName, tablefilename); exit(1); } fclose(fh);fh = 0; XAutoRepeatOn(dpy); XCloseDisplay (dpy); exit (0); }
void UXViewport::Tick() { guard(UXViewport::Tick); UXClient* Client = GetOuterUXClient(); if (!XWindow) return; // Keyboard. EInputKey Key; KeySym LowerCase, UpperCase; // Mouse movement management. UBOOL MouseMoved; INT BaseX = SizeX/2; INT BaseY = SizeY/2; INT DX = 0, DY = 0; XEvent Event; while( XPending(XDisplay) ) { XNextEvent(XDisplay, &Event); switch( Event.type ) { case CreateNotify: // Window has been created. ViewportStatus = X_ViewportNormal; // Make this viewport current and update its title bar. GetOuterUClient()->MakeCurrent( this ); break; case DestroyNotify: // Window has been destroyed. if( BlitFlags & BLIT_Fullscreen ) EndFullscreen(); if( ViewportStatus == X_ViewportNormal ) { // Closed normally. ViewportStatus = X_ViewportClosing; delete this; } break; case Expose: // Redraw the window. break; case KeyPress: // Reset timer. RepeatTimer = appSeconds(); LastKey = True; // Get key code. Key = (EInputKey) XKeycodeToKeysym( XDisplay, Event.xkey.keycode, 0 ); XConvertCase( Key, &LowerCase, &UpperCase ); Key = (EInputKey) UpperCase; // Check the Keysym map. if (KeysymMap[Key] != 0) Key = (EInputKey) KeysymMap[Key]; // Send key to input system. CauseInputEvent( Key, IST_Press ); // Emulate WM_CHAR. // Check for shift modifier. if (Event.xkey.state & ShiftMask) { Key = (EInputKey) UpperCase; if (ShiftMaskMap[Key] != 0) Key = (EInputKey) ShiftMaskMap[Key]; } else Key = (EInputKey) LowerCase; if (Key == XK_BackSpace) Key = IK_Backspace; if (Key == XK_Tab) Key = IK_Tab; if (Key == XK_Return) Key = IK_Enter; if (WMCharMap[Key] == 1) { KeyRepeatMap[Key] = 1; Client->Engine->Key( this, Key ); } break; case KeyRelease: // Get key code. Key = (EInputKey) XKeycodeToKeysym( XDisplay, Event.xkey.keycode, 0 ); XConvertCase( Key, &LowerCase, &UpperCase ); Key = (EInputKey) UpperCase; // Check the Keysym map. if (KeysymMap[Key] != 0) Key = (EInputKey) KeysymMap[Key]; // Send key to input system. CauseInputEvent( Key, IST_Release ); // Release all types of this key. if (Key == XK_BackSpace) Key = IK_Backspace; if (Key == XK_Tab) Key = IK_Tab; if (Key == XK_Return) Key = IK_Enter; KeyRepeatMap[Key] = 0; KeyRepeatMap[ShiftMaskMap[Key]] = 0; KeyRepeatMap[ShiftMaskMap[(EInputKey) LowerCase]] = 0; KeyRepeatMap[(EInputKey) LowerCase] = 0; break; case ButtonPress: switch (Event.xbutton.button) { case 1: Key = IK_LeftMouse; break; case 2: Key = IK_MiddleMouse; break; case 3: Key = IK_RightMouse; break; case 4: Key = IK_MouseWheelUp; break; case 5: Key = IK_MouseWheelDown; break; } // Send to input system. CauseInputEvent( Key, IST_Press ); break; case ButtonRelease: switch (Event.xbutton.button) { case 1: Key = IK_LeftMouse; break; case 2: Key = IK_MiddleMouse; break; case 3: Key = IK_RightMouse; break; case 4: Key = IK_MouseWheelUp; break; case 5: Key = IK_MouseWheelDown; break; } // Send to input system. CauseInputEvent( Key, IST_Release ); break; case MotionNotify: MouseMoved = True; if (UseDGA) { if (abs(Event.xmotion.x_root) > 1) DX += Event.xmotion.x_root * 2; else DX += Event.xmotion.x_root; if (abs(Event.xmotion.y_root) > 1) DY += Event.xmotion.y_root * 2; else DY += Event.xmotion.y_root; } else { DX += Event.xmotion.x - BaseX; DY += Event.xmotion.y - BaseY; BaseX = Event.xmotion.x; BaseY = Event.xmotion.y; } break; case ResizeRequest: // Eventually resize and setres. break; case MapNotify: if (Iconified) { guard(Uniconify); Iconified = false; // Unpause the game if applicable. Exec( TEXT("SETPAUSE 0"), *this ); // Reset the input buffer. Input->ResetInput(); // Snag the mouse again. SetMouseCapture( 1, 1, 0 ); // Make this viewport current. GetOuterUClient()->MakeCurrent( this ); // Turn off that damn auto repeat. XAutoRepeatOff( XDisplay ); // Return to fullscreen. if( BlitFlags & BLIT_Fullscreen ) TryRenderDevice( TEXT("ini:Engine.Engine.GameRenderDevice"), INDEX_NONE, INDEX_NONE, ColorBytes, 1 ); unguard; } break; case UnmapNotify: if (!Iconified) Iconify(); break; case FocusIn: break; case FocusOut: Iconify(); break; } } if (Iconified) return; // Deliver mouse behavior to the engine. if (MouseMoved) { if (!UseDGA) { XWarpPointer(XDisplay, None, XWindow, 0, 0, 0, 0, SizeX/2, SizeY/2); // Clear out the warp. XEvent MouseEvent; while( XCheckWindowEvent(XDisplay, XWindow, ButtonMotionMask | PointerMotionMask, &MouseEvent) ) { // Do Nothing. } } // Send to input subsystem. if( DX ) CauseInputEvent( IK_MouseX, IST_Axis, +DX ); if( DY ) CauseInputEvent( IK_MouseY, IST_Axis, -DY ); } // Send WM_CHAR for down keys. if ( LastKey && (appSeconds() - RepeatTimer < 0.5) ) return; LastKey = False; if ( appSeconds() - RepeatTimer < 0.1 ) return; RepeatTimer = appSeconds(); for (INT i=0; i<256; i++) if (KeyRepeatMap[i] != 0) { if (i == IK_Backspace) { CauseInputEvent( i, IST_Press ); CauseInputEvent( i, IST_Release ); } else Client->Engine->Key( this, (EInputKey) i ); } unguard; }
gint main (gint argc, gchar *argv[]) { Window root; //gettext bindtextdomain( "gamine", LOCALDIR ); textdomain( "gamine" ); gamine_t cb; GtkWidget *window; GdkWindow *gdkwindow; GtkWindow *gtkwindow; GdkScreen *screen; GdkPixbuf *cursor_pixbuf; GdkPixbuf *icon_pixbuf; GdkCursor *cursor; GdkColor bg_color; gchar *cursorfile; gchar *iconfile; cb.is_cairo = FALSE; gtk_init (&argc, &argv); gst_init (&argc, &argv); gconf_init(argc, argv, NULL); gst_play_background (cb.bus, "BachJSBrandenburgConcertNo2inFMajorBWV1047mvmt1.ogg", TRUE); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); /* Create the drawing area and configuration */ cb.da = gtk_drawing_area_new (); bg_color.red = 65535; bg_color.green = 65535; bg_color.blue = 65535; gtk_widget_modify_bg (cb.da, GTK_STATE_NORMAL, &bg_color); gtk_container_add (GTK_CONTAINER (window), cb.da); cb.gc = gconf_client_get_default(); gtkwindow = GTK_WINDOW(window); gtk_window_set_title (gtkwindow, "Gamine"); gtk_window_set_wmclass(gtkwindow, "gamine", "Gamine"); gtk_container_set_border_width (GTK_CONTAINER (gtkwindow), 0); /* Event signals */ g_signal_connect (gtkwindow, "destroy", G_CALLBACK (gtk_main_quit), >kwindow); g_signal_connect (G_OBJECT (cb.da), "expose-event", G_CALLBACK (display_help), &cb); g_signal_connect (cb.da, "motion_notify_event", G_CALLBACK (draw_line), &cb); g_signal_connect (cb.da, "button_press_event", G_CALLBACK (draw_star), &cb); g_signal_connect (gtkwindow, "key-press-event", G_CALLBACK (gamine_on_key), &cb); gtk_widget_set_events (cb.da, gtk_widget_get_events (cb.da) | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK); /* Set fullscreen, grab mouse/keyboard, ...*/ gtk_widget_show_all (GTK_WIDGET(gtkwindow)); gdkwindow = GDK_WINDOW(GTK_WIDGET(gtkwindow)->window); screen = gtk_widget_get_screen (cb.da); gtk_window_present (gtkwindow); gtk_window_stick(gtkwindow); //gtk_window_set_keep_above (gtkwindow), True); //gtk_window_set_transient_for (gtkwindow, NULL); //set fullscreen gdk_window_fullscreen (gdkwindow); gtk_window_fullscreen (gtkwindow); gdk_window_raise (gdkwindow); //set full screen without window manager XMoveResizeWindow(GDK_WINDOW_XDISPLAY(gdkwindow), GDK_WINDOW_XID(gdkwindow), 0, 0, gdk_screen_get_width (screen), gdk_screen_get_height (screen)); root = DefaultRootWindow(GDK_WINDOW_XDISPLAY (gdkwindow)); XGrabPointer(GDK_WINDOW_XDISPLAY (gdkwindow), root, True, PointerMotionMask, GrabModeAsync, GrabModeAsync, root, None, CurrentTime); XGrabKeyboard(GDK_WINDOW_XDISPLAY (gdkwindow), root, True, GrabModeAsync, GrabModeAsync, CurrentTime); //remove keyboard repeat XAutoRepeatOff(GDK_WINDOW_XDISPLAY (gdkwindow)); gtk_window_has_toplevel_focus (gtkwindow); /*cursor*/ cursorfile = g_build_filename(DATADIR, "pencil.png", NULL); if (!g_file_test (cursorfile, G_FILE_TEST_EXISTS)) { printf(gettext("*** error: %s does not exists***\n"), cursorfile); } else { cursor_pixbuf = gdk_pixbuf_new_from_file(cursorfile, NULL); cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), cursor_pixbuf, 0, 38); gdk_window_set_cursor(gdkwindow, cursor); gdk_cursor_unref(cursor); gdk_pixbuf_unref(cursor_pixbuf); } g_free(cursorfile); /*Set icon*/ iconfile = g_build_filename(DATADIR, "gamine.png", NULL); if (!g_file_test (iconfile, G_FILE_TEST_EXISTS)) printf(gettext("*** error: %s does not exists***\n"), iconfile); else { icon_pixbuf = gdk_pixbuf_new_from_file(iconfile, NULL); gtk_window_set_icon (gtkwindow, icon_pixbuf); gdk_pixbuf_unref (icon_pixbuf); } g_free(iconfile); load_conf(&cb); gtk_main (); //set keyboard repeat XAutoRepeatOn(GDK_WINDOW_XDISPLAY (gdkwindow)); XCloseDisplay(GDK_WINDOW_XDISPLAY (gdkwindow)); return 0; }
void UXViewport::CaptureInputs() { guard(UXViewport::CaptureInputs); // Check keyboard state. XKeyboardState KeyState; XGetKeyboardControl(XDisplay, &KeyState); if( KeyState.global_auto_repeat == AutoRepeatModeOn ) { RestoreAutoRepeat = true; XAutoRepeatOff( XDisplay ); } // Examine root window. Window RootRoot; int r_x, r_y; unsigned int r_width, r_height, r_border, r_depth; XGetGeometry( XDisplay, DefaultRootWindow(XDisplay), &RootRoot, &r_x, &r_y, &r_width, &r_height, &r_border, &r_depth ); XWarpPointer(XDisplay, None, XWindow, 0, 0, 0, 0, r_width/2, r_height/2); XSync(XDisplay, False); //XDefineCursor(XDisplay, XWindow, GetNullCursor()); // Capture the pointer. XGrabPointer(XDisplay, XWindow, False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ButtonMotionMask, GrabModeAsync, GrabModeAsync, XWindow, None, CurrentTime ); // Control acceleration. XChangePointerControl(XDisplay, True, True, 2, 1, 0); XSync(XDisplay, False); // Query DGA capabilities. UXClient* C = GetOuterUXClient(); if (C->DGAMouseEnabled) { INT VersionMajor, VersionMinor; if (!XF86DGAQueryVersion(XDisplay, &VersionMajor, &VersionMinor)) { debugf( TEXT("XF86DGA disabled.") ); UseDGA = false; } else { debugf( TEXT("XF86DGA enabled.") ); UseDGA = true; XF86DGADirectVideo(XDisplay, DefaultScreen(XDisplay), XF86DGADirectMouse); XWarpPointer(XDisplay, None, XWindow, 0, 0, 0, 0, 0, 0); } } else UseDGA = false; XGrabKeyboard(XDisplay, XWindow, False, GrabModeAsync, GrabModeAsync, CurrentTime); XSync(XDisplay, False); unguard; }
void X11Device::processEvent(const XEvent &event) { DeviceEvent deviceEvent(ENoEvent); X11Session *session = static_cast<X11Session *>(getSession()); if (m_callbacks.size() == 0) return; switch (event.type) { case ClientMessage: /* The window close button pressed */ if ((event.xclient.format == 32) && ((unsigned) event.xclient.data.l[0] == m_deleteWindow)) { deviceEvent.setType(EQuitEvent); } break; case FocusIn: /* Deactivate auto-repeat */ XAutoRepeatOff(session->m_display); deviceEvent.setType(EGainFocusEvent); m_modifierState = 0; m_buttonState = 0; break; case FocusOut: /* Reactivate auto-repeat */ XAutoRepeatOn(session->m_display); deviceEvent.setType(ELoseFocusEvent); m_modifierState = 0; m_buttonState = 0; break; case ButtonPress: deviceEvent.setType(EMouseButtonDownEvent); translateMouse(event, deviceEvent); m_buttonState |= deviceEvent.getMouseButton(); break; case ButtonRelease: deviceEvent.setType(EMouseButtonUpEvent); translateMouse(event, deviceEvent); m_buttonState &= ~deviceEvent.getMouseButton(); break; case MotionNotify: { deviceEvent.setType(m_buttonState == 0 ? EMouseMotionEvent : EMouseDragEvent); translateMouse(event, deviceEvent); deviceEvent.setMouseButton(m_buttonState); if (m_grab) warpMouse(Point2i(getSize().x / 2, getSize().y/2)); int xpos = deviceEvent.getMousePosition().x; int ypos = deviceEvent.getMousePosition().y; if (xpos > m_size.x || xpos < 0 || ypos > m_size.y || ypos < 0) return; } break; case KeyPress: if (translateKeyboard(event, deviceEvent)) { deviceEvent.setType(EKeyDownEvent); int special = deviceEvent.getKeyboardSpecial(); /* Update the current modifier state */ if (special == EKeyLShift || special == EKeyRShift) { m_modifierState |= EShiftModifier; } else if (special == EKeyLAlt || special == EKeyRAlt) { m_modifierState |= EAltModifier; } else if (special == EKeyLControl || special == EKeyRControl) { m_modifierState |= EControlModifier; } deviceEvent.setKeyboardModifiers(m_modifierState); } break; case KeyRelease: if (translateKeyboard(event, deviceEvent)) { deviceEvent.setType(EKeyUpEvent); int special = deviceEvent.getKeyboardSpecial(); /* Update the current modifier state */ if (special == EKeyLShift || special == EKeyRShift) { m_modifierState = m_modifierState & (~EShiftModifier); } else if (special == EKeyLAlt || special == EKeyRAlt) { m_modifierState = m_modifierState & (~EAltModifier); } else if (special == EKeyLControl || special == EKeyRControl) { m_modifierState = m_modifierState & (~EControlModifier); } deviceEvent.setKeyboardModifiers(m_modifierState); } break; case MapNotify: case UnmapNotify: m_modifierState = 0; break; case ConfigureNotify: { Vector2i size(event.xconfigure.width, event.xconfigure.height); if (m_size != size) { m_size = size; deviceEvent.setType(EResizeEvent); } } break; case ReparentNotify: case Expose: break; default: Log(EWarn, "Unknown event %i received", event.type); } if (deviceEvent.getType() != ENoEvent) fireDeviceEvent(deviceEvent); }
/* * inner_main * */ void inner_main() { if (debug) printf("DEBUT inner_main\n"); int i; int j; int nbpressed = 0; int queue =0 ; Window focus; int revert; libXRecPlay_t_EventReturn retour; XEvent e; nbchar = 0; lensuite = 3; suite = malloc(sizeof(char) * lensuite ); if (suite == NULL) exit(1); suite[0]='\0'; cpy = malloc(sizeof(char) * lensuite ); if (cpy == NULL) exit(1); cpy[0]='\0'; //open connection with the server display=XOpenDisplay(NULL); if(display==NULL) { fprintf(stderr,"Cannot open display\n"); exit(1); } if (!libXRecPlay_init(display) ) { fprintf(stderr,"Cannot init libXRecPlay\n"); exit(1); } //GUILE get_rc_guile_file(); if ( (use_key.key != NULL) || (mod_key.key != NULL) ) { // Désactivation de l'autorepetition du clavier XAutoRepeatOff(display); sleep(1); } grab_button_sup.nombre = 12; grab_button_sup.boutons = malloc( 12 *sizeof(int)); if (grab_button_sup.boutons == NULL) exit(1); int cpt=1; int grab_test; for (i=1; grab_button_sup.nombre > i - cpt ; ++i) { grab_test=True; for (j=0; grab_button.nombre > j; ++j) { if ( i == grab_button.boutons[j] ) { ++cpt; grab_test = False; break; } } if (grab_test) { grab_button_sup.boutons[i - cpt]=i; } } grab_button_sup.nombre = 13 - cpt ; if (debug) { printf("grab_button_sup = "); for(i=0; grab_button_sup.nombre > i ;++i) { printf("%i ",grab_button_sup.boutons[i]); } printf("|\n"); } if (test) printf("mode test\n"); if (verbose) { for(i=0; grab_button.nombre > i ; i++) { printf("(grab-button %i)\n",grab_button.boutons[i]); } for(i=0; i < use_key.nombre; i++) { printf("(use-key \"%s\")\n",XKeysymToString( XKeycodeToKeysym( display, use_key.key[i], 0)) ); } for(i=0; i < mod_key.nombre; i++) { printf("(mod-key \"%s\")\n",XKeysymToString( XKeycodeToKeysym( display, mod_key.key[i].key, 0)) ); for(j=0; mod_key.key[i].nbgrab > j ; j++) { printf(" (mod-grab-button \"%s\" %i)\n", XKeysymToString( XKeycodeToKeysym( display, mod_key.key[i].key, 0)), mod_key.key[i].grab[j]); } } } // début de la boucle evenementiel infinie while(infinie) { retour = libXRecPlay_GetEvent (display,&e); if ( retour == Event ) { if (debug) { printf("fenetre = %i, event == %i ,detail = %i\n",e.xkey.window, e.xkey.type, e.xkey.keycode); } fenetre_client = e.xany.window; if(e.xany.type == KeyPress) { if (debug) printf("\nDEBUT Event KeyPress\n"); // nbpressed++; for(i=0; i < mod_key.nombre; i++) { if ( e.xkey.keycode == mod_key.key[i].key ) { // nbpressed++; // nbpressed--; strcpy(cpy,suite); mod_key.key[i].pressed=True; f_suite ( True ); for(j=0; mod_key.key[i].nbgrab > j ; j++) { //XGrabButton (display, mod_key.key[i].grab[j], AnyModifier, DefaultRootWindow(display), False, ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None); XEvent send; send.xbutton.type = ButtonPress; send.xbutton.button = mod_key.key[i].grab[j]; libXRecPlay_AddEvent( display, e.xany.window, send, True ); } } } for(i=0; i < use_key.nombre; i++) { if ( e.xkey.keycode == use_key.key[i] ) { nbchar = snprintf(cpy, lensuite, "%s%s ", suite, XKeysymToString( XKeycodeToKeysym( display, e.xkey.keycode, 0))); if ( resize() ) nbchar = snprintf(cpy, lensuite, "%s%s ", suite, XKeysymToString( XKeycodeToKeysym( display, e.xkey.keycode, 0))); f_suite ( True ); } } if (debug) printf("FIN Event KeyPress\n\n"); } if(e.xany.type == KeyRelease) { if (debug) printf("DEBUT Event KeyRelease\n"); for(i=0; i < mod_key.nombre; i++) { if ( e.xkey.keycode == mod_key.key[i].key ) { strcpy(cpy,suite); f_suite ( False ); mod_key.key[i].pressed=False; suite[0]='\0'; cpy[0]='\0'; for(j=0; mod_key.key[i].nbgrab > j ; j++) { // XUngrabButton (display, mod_key.key[i].grab[j], AnyModifier, DefaultRootWindow(display)); XEvent send; send.xbutton.type = ButtonPress; send.xbutton.button = mod_key.key[i].grab[j]; libXRecPlay_RemEvent( display, e.xany.window, send, True ); } } } for(i=0; i < use_key.nombre; i++) { if ( e.xkey.keycode == use_key.key[i] ) { strcpy(cpy,suite); if (debug) printf("suite = %s\n",suite); f_suite ( False ); suite[0]='\0'; cpy[0]='\0'; } } if (debug) printf("FIN Event KeyRelease\n\n"); } if(e.xany.type==ButtonPress) { if (debug) printf("\nDEBUT Event ButtonPress\n"); for(i=0; grab_button.nombre > i ; i++) { if (grab_button.boutons[i] == e.xbutton.button ) { for(j=0; grab_button_sup.nombre > j ; ++j) { XEvent send; send.xbutton.type = ButtonPress; send.xbutton.button = grab_button_sup.boutons[j]; libXRecPlay_AddEvent( display, fenetre_client, send, True ); } break; } } nbchar = snprintf(cpy,lensuite,"%s%i ",suite,e.xbutton.button); if ( resize() ) nbchar = snprintf(cpy,lensuite,"%s%i ",suite,e.xbutton.button); if (debug) printf("suite = |%s|\n",cpy); f_suite ( True ); if (debug) printf("FIN Event ButtonPress\n\n"); } if(e.xany.type==ButtonRelease) { if (debug) printf("\nDEBUT Event ButtonPress\n"); for(i=0; grab_button.nombre > i ; ++i) { if (grab_button.boutons[i] == e.xbutton.button ) { for(j=0; grab_button_sup.nombre > j ; ++j) { XEvent send; send.xbutton.type = ButtonPress; send.xbutton.button = grab_button_sup.boutons[j]; libXRecPlay_RemEvent( display, fenetre_client, send, True); } break; } } strcpy(cpy,suite); if (debug) printf("suite = |%s|\n",suite); f_suite ( False ); suite[0]='\0'; cpy[0]='\0'; if (debug) printf("FIN Event ButtonPress\n\n"); } } else if ( retour == Client ); { if (e.xany.type == CreateNotify ) { fenetre_client = e.xany.window; for(i=0; grab_button.nombre > i ; i++) { XEvent send; send.xbutton.type = ButtonPress; send.xbutton.button = grab_button.boutons[i]; libXRecPlay_AddEvent( display, e.xany.window, send, True ); } for(i=0; use_key.nombre > i ; i++) { XEvent send; send.xbutton.type = KeyPress; send.xbutton.button = use_key.key[i]; libXRecPlay_AddEvent( display, e.xany.window, send, False ); } for(i=0; mod_key.nombre > i ; i++) { XEvent send; send.xbutton.type = KeyPress; send.xbutton.button = mod_key.key[i].key; libXRecPlay_AddEvent( display, e.xany.window, send, False ); } } else if (e.xany.type == DestroyNotify && e.xany.window == fenetre_client ) { fenetre_client = None; } } //fin de la boucle infini } for(i=0; i < nb_scheme_KR; i++) { free( scheme_KR[i].scheme); } free(scheme_KR); for(i=0; i < nb_scheme_KP; i++) { free( scheme_KP[i].scheme); } free(scheme_KP); // Réactivation de l'autorepetition du clavier // XAutoRepeatOn(display); //close connection to server XCloseDisplay(display); }
int initsystem(void) /* retourne 1 si initialisation reussie */ { int i; int windowW; int windowH; XSetWindowAttributes xswa; XGCValues xgcv; XSizeHints xsh; windowW=WIDTH*RATIO; windowH=HEIGHT*RATIO; display=XOpenDisplay(0); if (!display) return(0); else { mousek=0; XAutoRepeatOff(display); timestart=last=systime(); screen=XDefaultScreenOfDisplay(display); rdepth=sdepth=XDefaultDepthOfScreen(screen); if (emulmono) sdepth=1; XSynchronize(display,0); black=XBlackPixelOfScreen(screen); white=XWhitePixelOfScreen(screen); colormap=XDefaultColormapOfScreen(screen); visual=XDefaultVisualOfScreen(screen); xswa.event_mask=VisibilityChangeMask; xswa.background_pixel=black; xswa.border_pixel=white; xswa.override_redirect=0; xswa.backing_store=Always; xswa.bit_gravity=StaticGravity; xswa.win_gravity=CenterGravity; window=XCreateWindow(display,XRootWindowOfScreen(screen), randval(50),randval(100),windowW,windowH,0, XDefaultDepthOfScreen(screen),InputOutput, XDefaultVisualOfScreen(screen), CWWinGravity|CWBitGravity|CWBackingStore|CWEventMask| CWBackPixel|CWOverrideRedirect|CWBorderPixel,&xswa); if (sdepth!=1) xcolormap=XCreateColormap(display,window, visual,AllocAll); xgcv.foreground = white; xgcv.background = black; gc=XCreateGC(display,window,GCForeground | GCBackground,&xgcv); XSetGraphicsExposures(display,gc,False); /* CAPITAL!!! : evite d'accumuler sans cesse des expose events */ xsh.x=0; xsh.y=0; xsh.width=windowW; xsh.height=windowH; xsh.min_width=windowW; xsh.max_width=windowW; xsh.min_height=windowH; xsh.max_height=windowH; xsh.flags=PPosition|PSize|PMinSize|PMaxSize; XSetNormalHints(display, window, &xsh); XStoreName(display,window,""); XMapWindow(display, window); XSelectInput(display,window,PointerMotionMask|ButtonPressMask| ButtonReleaseMask|KeyPressMask|KeyReleaseMask); XFlush(display); XSync(display,0); for (i=0; i<(NBCOLORS+2); i++) { if (i&1) pixels[i]=white; else pixels[i]=black; if (i==NBCOLORS) pixels[i]=0; if (i==(NBCOLORS+1)) pixels[i]=(1<<rdepth)-1; xgcv.foreground=pixels[i]; xgcv.background=black; gctab[i]=XCreateGC(display,window, GCForeground|GCBackground,&xgcv); XSetFunction(display,gctab[i],GXcopy); XSetFillStyle(display,gctab[i],FillSolid); } ecran[0]=XCreatePixmap(display,window,windowW,windowH,rdepth); ecran[1]=XCreatePixmap(display,window,windowW,windowH,rdepth); for(i=0; i<9; i++) graypixmap[i]=XCreatePixmapFromBitmapData(display,window, &graypat[i][0],8,8,white,black,rdepth); setpalette(egapal); cls(); swap(); cls(); empty(); waitdelay(500); return(1); } }
void handle_events (void) { for (;;) { XEvent event; #if 0 if (! XCheckMaskEvent (display, eventmask, &event)) break; #endif if (! XPending (display)) break; XNextEvent (display, &event); switch (event.type) { case KeyPress: case KeyRelease: { int state = (event.type == KeyPress); if (currprefs.map_raw_keys) { unsigned int keycode = ((XKeyEvent *)&event)->keycode; unsigned int ievent; if ((ievent = match_hotkey_sequence (keycode, state))) handle_hotkey_event (ievent, state); else inputdevice_translatekeycode (0, keycode, state); } else { KeySym keysym; int index = 0; int ievent, amiga_keycode; do { keysym = XLookupKeysym ((XKeyEvent *)&event, index); if ((ievent = match_hotkey_sequence (keysym, state))) { handle_hotkey_event (ievent, state); break; } else if ((amiga_keycode = xkeysym2amiga (keysym)) >= 0) { inputdevice_do_keyboard (amiga_keycode, state); break; } index++; } while (keysym != NoSymbol); } break; } case ButtonPress: case ButtonRelease: { int state = (event.type == ButtonPress); int buttonno = -1; switch ((int)((XButtonEvent *)&event)->button) { case 1: buttonno = 0; break; case 2: buttonno = 2; break; case 3: buttonno = 1; break; /* buttons 4 and 5 report mousewheel events */ case 4: if (state) record_key (0x7a << 1); break; case 5: if (state) record_key (0x7b << 1); break; } if (buttonno >=0) setmousebuttonstate(0, buttonno, state); break; } case MotionNotify: if (dgamode) { int tx = ((XMotionEvent *)&event)->x_root; int ty = ((XMotionEvent *)&event)->y_root; setmousestate (0, 0, tx, 0); setmousestate (0, 1, ty, 0); } else if (grabbed) { int realmove = 0; int tx, ty,ttx,tty; tx = ((XMotionEvent *)&event)->x; ty = ((XMotionEvent *)&event)->y; if (! event.xmotion.send_event) { setmousestate( 0,0,tx-oldx,0); setmousestate( 0,1,ty-oldy,0); realmove = 1; #undef ABS #define ABS(a) (((a)<0) ? -(a) : (a) ) if (ABS(current_width / 2 - tx) > 3 * current_width / 8 || ABS(current_height / 2 - ty) > 3 * current_height / 8) { #undef ABS XEvent event; ttx = current_width / 2; tty = current_height / 2; event.type = MotionNotify; event.xmotion.display = display; event.xmotion.window = mywin; event.xmotion.x = ttx; event.xmotion.y = tty; XSendEvent (display, mywin, False, PointerMotionMask, &event); XWarpPointer (display, None, mywin, 0, 0, 0, 0, ttx, tty); } } else { tx=event.xmotion.x; ty=event.xmotion.y; } oldx = tx; oldy = ty; } else if (inwindow) { int tx = ((XMotionEvent *)&event)->x; int ty = ((XMotionEvent *)&event)->y; setmousestate(0,0,tx,1); setmousestate(0,1,ty,1); if (! cursorOn && !currprefs.hide_cursor) { XDefineCursor(display, mywin, xhairCursor); cursorOn = 1; } gettimeofday(&lastMotionTime, NULL); } break; case EnterNotify: { int tx = ((XCrossingEvent *)&event)->x; int ty = ((XCrossingEvent *)&event)->y; setmousestate(0,0,tx,1); setmousestate(0,1,ty,1); } inwindow = 1; break; case LeaveNotify: inwindow = 0; break; case FocusIn: if (! autorepeatoff) XAutoRepeatOff (display); autorepeatoff = 1; break; case FocusOut: if (autorepeatoff) XAutoRepeatOn (display); autorepeatoff = 0; inputdevice_release_all_keys (); break; case Expose: refresh_necessary = 1; break; case ClientMessage: if (((Atom)event.xclient.data.l[0]) == delete_win) { uae_stop (); } break; } } #if defined PICASSO96 if (! dgamode) { if (screen_is_picasso && refresh_necessary) { DO_PUTIMAGE (pic_dinfo.ximg, 0, 0, 0, 0, picasso_vidinfo.width, picasso_vidinfo.height); XFlush (display); refresh_necessary = 0; memset (picasso_invalid_lines, 0, sizeof picasso_invalid_lines); } else if (screen_is_picasso && picasso_has_invalid_lines) { int i; int strt = -1; picasso_invalid_lines[picasso_vidinfo.height] = 0; for (i = picasso_invalid_start; i < picasso_invalid_stop + 2; i++) { if (picasso_invalid_lines[i]) { picasso_invalid_lines[i] = 0; if (strt != -1) continue; strt = i; } else { if (strt == -1) continue; DO_PUTIMAGE (pic_dinfo.ximg, 0, strt, 0, strt, picasso_vidinfo.width, i - strt); strt = -1; } } XFlush (display); if (strt != -1) abort (); } } picasso_has_invalid_lines = 0; picasso_invalid_start = picasso_vidinfo.height + 1; picasso_invalid_stop = -1; #endif if (! dgamode) { if (! screen_is_picasso && refresh_necessary) { DO_PUTIMAGE (ami_dinfo.ximg, 0, 0, 0, 0, current_width, current_height); refresh_necessary = 0; } if (cursorOn && !currprefs.hide_cursor) { struct timeval now; int diff; gettimeofday(&now, NULL); diff = (now.tv_sec - lastMotionTime.tv_sec) * 1000000 + (now.tv_usec - lastMotionTime.tv_usec); if (diff > 1000000) { XDefineCursor (display, mywin, blankCursor); cursorOn = 0; } } } }