Exemple #1
0
/*
** GLimp_Shutdown
**
** This routine does all OS specific shutdown procedures for the OpenGL
** subsystem.  Under OpenGL this means NULLing out the current DC and
** HGLRC, deleting the rendering context, and releasing the DC acquired
** for the window.  The state structure is also nulled out.
**
*/
void GLimp_Shutdown( void )
{
	if (!ctx || !dpy)
		return;
	IN_DeactivateMouse();
	XAutoRepeatOn(dpy);
	if (dpy) {
		if (ctx)
			qglXDestroyContext(dpy, ctx);
		if (win)
			XDestroyWindow(dpy, win);
		if (vidmode_active)
			XF86VidModeSwitchToMode(dpy, scrnum, vidmodes[0]);
		XCloseDisplay(dpy);
	}
	vidmode_active = qfalse;
	dpy = NULL;
	win = 0;
	ctx = NULL;

	memset( &glConfig, 0, sizeof( glConfig ) );
	memset( &glState, 0, sizeof( glState ) );

	QGL_Shutdown();
}
Exemple #2
0
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();
}
Exemple #3
0
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);
}
Exemple #4
0
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);
}
Exemple #5
0
void UXViewport::Iconify()
{
	guard(UXViewport::Iconify);

	if (Iconified)
		return;
		
	Iconified = true;

	// Pause the game if applicable.
	if( GIsRunning )
		Exec( TEXT("SETPAUSE 1"), *this );

	// Release the mouse.
	SetMouseCapture( 0, 0, 0 );
	SetDrag( 0 );

	// Reset the input buffer.
	Input->ResetInput();

	// End fullscreen.
	if( BlitFlags & BLIT_Fullscreen )
		EndFullscreen();
	GetOuterUClient()->MakeCurrent( NULL );

	// Turn auto repeat back on.
	XAutoRepeatOn( XDisplay );

	// Iconify the window.
	XIconifyWindow( XDisplay, XWindow, DefaultScreen(XDisplay) );	
	unguard;
}
Exemple #6
0
void UXViewport::ReleaseInputs()
{
	guard(UXViewport::ReleaseInputs);

	// Restore DGA mode.
	if (UseDGA)
	{
		UseDGA = false;
		XF86DGADirectVideo(XDisplay, DefaultScreen(XDisplay), 0);
	}

	// Restore acceleration.
	XChangePointerControl(XDisplay, True, True, MouseAccel_N, MouseAccel_D, MouseThreshold);
	
	// Restore pointer and keyboard.
	XUngrabPointer( XDisplay, CurrentTime );
	XUngrabKeyboard( XDisplay, CurrentTime );

	// Restore cursor.
	XUndefineCursor( XDisplay, XWindow );

	// Restore Keyboard AutoRepeat
	if(	RestoreAutoRepeat )
	{
		RestoreAutoRepeat = false;
		XAutoRepeatOn( XDisplay );
	}

	unguard;
}
Exemple #7
0
void traite_signal( int s )
{
    printf( "SIG %d\n", s );
    infinie = False;
    int i;

    	if ( (use_key.key != NULL) || (mod_key.key != NULL) )
    		{
    // Réactivation de l'autorepetition du clavier
    		XAutoRepeatOn(display);
    		XFlush(display);
    		usleep(100000);
    		}

    for(i=0; i < nb_scheme_KR; i++)
    {

        free( scheme_KR[i].scheme);
    }
    if (scheme_KR != NULL)
        free(scheme_KR);

    for(i=0; i < nb_scheme_KP; i++)
    {

        free( scheme_KP[i].scheme);
    }
    if (scheme_KP != NULL)
        free(scheme_KP);

    for(i=0; grab_button.nombre > i ; i++)
    {
//		XUngrabButton (display, grab_button.boutons[i], AnyModifier, DefaultRootWindow(display));
    }
    if (grab_button.boutons != NULL)
        free(grab_button.boutons);

    if (grab_button_sup.boutons != NULL)
        free(grab_button_sup.boutons);

    if (use_key.key != NULL)
        free(use_key.key);
    for(i=0; mod_key.nombre > i ; i++)
    {
        if (mod_key.key[i].grab != NULL)
            free(mod_key.key[i].grab);
    }
    if (mod_key.key != NULL)
        free(mod_key.key);
    if (suite != NULL)
        free(suite);
    if (cpy != NULL)
        free(cpy);

//close connection to server
//	XCloseDisplay(display);
    if (debug)
        printf("FIN inner_main\n");
    exit(1);
}
Exemple #8
0
//
// 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);
    }
}
Exemple #9
0
static int MySysErrorHandler (Display * display)
{
    perror ("X11-Error");
    fflush (stderr);

    XAutoRepeatOn(display);
    XCloseDisplay(display);
    exit(0);
}
void KeyboardAutoRepeatOn(void)
{
#if defined(TARGET_SDL)
  SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY / 2,
		      SDL_DEFAULT_REPEAT_INTERVAL / 2);
  SDL_EnableUNICODE(1);
#else
  if (display)
    XAutoRepeatOn(display);
#endif
}
Exemple #11
0
void SetAutoRepeat(bool autorep)
{
#if 0 // TODO OSX similar logic for OSX
    if (toggleAutoRepeat)
    {
        if (autorep)
            XAutoRepeatOn(GSdsp);
        else
            XAutoRepeatOff(GSdsp);
    }
#endif
}
Exemple #12
0
void SetAutoRepeat(bool autorep)
{
 #ifdef __linux__
    if (toggleAutoRepeat)
    {
        if (autorep)
            XAutoRepeatOn(GSdsp);
        else
            XAutoRepeatOff(GSdsp);
    }
#endif
}
Exemple #13
0
void SetAutoRepeat(bool autorep)
{
#if defined(__unix__)
    if (toggleAutoRepeat)
    {
        if (autorep)
            XAutoRepeatOn(GSdsp);
        else
            XAutoRepeatOff(GSdsp);
    }
#endif
}
Exemple #14
0
/*
 * Close the display etc.
 */
void Platform_specific_cleanup(void)
{
    /* Here we restore the mouse to its former self */
    /* the option may have been toggled in game to  */
    /* off so we cant trust that                    */

    if (dpy != NULL) {
	if (pre_exists)
	    XChangePointerControl(dpy, True, True, pre_acc_num,
				  pre_acc_denom, pre_threshold);
	XAutoRepeatOn(dpy);
	Colors_cleanup();
	XCloseDisplay(dpy);
	dpy = NULL;
	if (kdpy) {
	    XAutoRepeatOn(kdpy);
	    XCloseDisplay(kdpy);
	    kdpy = NULL;
	}
    }
    Widget_cleanup();
}
Exemple #15
0
void x11_internal_window_resize(hwrbitmap window, int w, int h) {
  XWindowChanges wc;
  XEvent ev;
  struct x11bitmap *xb = XB(window)->frontbuffer ? XB(window)->frontbuffer : XB(window);
  Atom a;

  /* Can't have a zero size, X will throw an error */
  if (!w) w = 1;
  if (!h) h = 1;
  
  /* Resize the window */
  wc.width = w;
  wc.height = h;
  XConfigureWindow(x11_display, xb->d, CWWidth | CWHeight, &wc);

  if (!xb->is_mapped) {
    /* Map the window, waiting for the MapNotify event */
    XSelectInput(x11_display, xb->d, StructureNotifyMask);  
    XMapWindow(x11_display, xb->d);
    do {
      XNextEvent(x11_display, &ev);
    } while (ev.type != MapNotify);
    xb->is_mapped = 1;
  }

  /* Set input event mask */
  XSelectInput(x11_display, xb->d,
	       KeyPressMask | KeyReleaseMask | ExposureMask | ButtonMotionMask |
	       ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask);
  XAutoRepeatOn(x11_display);

  /* Set WM protocols - we just need close events */
  a = XInternAtom(x11_display, "WM_DELETE_WINDOW", False);
  XSetWMProtocols(x11_display, xb->d, &a, 1);

  /* Do we need to grab the pointer? */
  if (xb->window_flags & PG_WINDOW_GRAB)
    XGrabPointer(x11_display, xb->d, False, EnterWindowMask | LeaveWindowMask |
		 PointerMotionMask | ButtonMotionMask | ButtonPressMask |
		 ButtonReleaseMask | Button1MotionMask | Button2MotionMask |
		 Button3MotionMask, GrabModeAsync, GrabModeAsync, None,
		 None, CurrentTime);

  x11_acknowledge_resize(window,w,h);
}
Exemple #16
0
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;

}
Exemple #17
0
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);
    }
}
Exemple #18
0
void killsystem(void)
{
    int i;

    if ((allocpal)&&(sdepth!=1))
        XFreeColors(display,colormap,pixels,NBCOLORS,0);

    XUnmapWindow(display,window);
    XDestroyWindow(display,window);
    XFreeGC(display,gc);
    if (sdepth!=1) XFreeColormap(display,xcolormap);
    for(i=0; i<(NBCOLORS+2); i++) XFreeGC(display,gctab[i]);
    for(i=0; i<9; i++) XFreePixmap(display,graypixmap[i]);
    XFreePixmap(display,ecran[0]);
    XFreePixmap(display,ecran[1]);
    XAutoRepeatOn(display);
    XCloseDisplay(display);
    exit(0);
}
void OnLibraryLoad() {
	// Tell X Threads are OK.
	XInitThreads();

	#ifdef XT
	XtToolkitInitialize();
	app_context = XtCreateApplicationContext();
	#endif

	// Open local display.
	disp = XOpenDisplay(XDisplayName(NULL));
	#ifdef DEBUG
	if (disp != NULL) {
		fprintf(stdout, "OnLibraryLoad(): XOpenDisplay successful.\n");
	}
	else {
		fprintf(stderr, "OnLibraryLoad(): XOpenDisplay failure!\n");
	}
	#endif

	Bool isAutoRepeat = False;
	#ifdef XKB
	// Enable detectable autorepeat.
	XkbSetDetectableAutoRepeat(disp, True, &isAutoRepeat);
	#else
	XAutoRepeatOn(disp);

	XKeyboardState kb_state;
	XGetKeyboardControl(disp, &kb_state);

	isAutoRepeat = (kb_state.global_auto_repeat == AutoRepeatModeOn);
	#endif

	#ifdef DEBUG
	if (isAutoRepeat) {
		fprintf(stdout, "OnLibraryLoad(): Successfully enabled detectable autorepeat.\n");
	}
	else {
		fprintf(stderr, "OnLibraryLoad(): Could not enable detectable auto-repeat!\n");
	}
	#endif
}
Exemple #20
0
void graphics_leave (void)
{
    if (! x11_init_ok)
	return;

    graphics_subshutdown ();

    if (autorepeatoff)
	XAutoRepeatOn (display);

    XFlush (display);
    XSync (display, 0);

    XFreeColormap (display, cmap);
    XFreeColormap (display, cmap2);

    XCloseDisplay (display);

    dumpcustom ();
}
Exemple #21
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;
}
Exemple #22
0
/*+++++++++++++++++++++++++++++++++++++++*/
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;
}
Exemple #23
0
void S9xTextMode ()
{
	if (!is_graphics)
		return;

	if (ourdisp == NULL)
		return;


	XF86DGADirectVideo (ourdisp, ourscreen, 0);
#ifdef USE_XF86VIDMODE
	if (orig_mode != mod320x240) {
		XF86VidModeSwitchToMode (ourdisp, ourscreen, orig_mode);
	}
#endif
	XAutoRepeatOn (ourdisp);

	XUngrabKeyboard (ourdisp, CurrentTime);
	XUngrabPointer (ourdisp, CurrentTime);
	XSelectInput (ourdisp, inputwin, 0);
	XSync (ourdisp, True);

	is_graphics = FALSE;
}
void X11Device::shutdown() {
    X11Session *session = static_cast<X11Session *>(getSession());
    Log(EDebug, "Shutting down X11 device");
    Device::shutdown();
    setVisible(false);
    XDestroyWindow(session->m_display, m_window);
    XFree(m_visinfo);

    if (m_fullscreen) {
        /* Switch back to the previous screen resolution */
        XF86VidModeSwitchToMode(session->m_display, session->m_screen, &m_previousMode);
        XF86VidModeSetViewPort(session->m_display, session->m_screen, 0, 0);
    }

    /* In case auto_repeat was left on */
    XKeyboardState xkbs;
    XAutoRepeatOn(session->m_display);
    XGetKeyboardControl(session->m_display, &xkbs);

    if (!xkbs.global_auto_repeat)
        Log(EWarn, "Unable to restore the keyboard auto-repeat flag");

    m_initialized = false;
}
Exemple #25
0
void gdk_key_repeat_restore (void) {
  if (autorepeat)
    XAutoRepeatOn (gdk_display);
  else
    XAutoRepeatOff (gdk_display);
}
Exemple #26
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);
}
Exemple #27
0
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), &gtkwindow);
    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;
}
Exemple #28
0
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;
	}
Exemple #29
0
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;
	    }
	}
    }
}
Exemple #30
0
/**
 * initialises the display
 * @param x the x coordinate of the display
 * @param y the y coordinate of the display
 * @param width the width of the display
 * @param height the height of the display
 * @return false if an error occurred while setting up the display section
 */
bool lino_display_init(unit x, unit y, unit w, unit h, void *data)
{
	PRINT1("%s: Initializing display...\n", __func__);

	xw.visible = false;

	/* open display */
	if (!(xw.display = XOpenDisplay(NULL)))
		return false;

	/* initialize xw structure with default values */
	xw.pixelsize = 4;
	xw.screensize = w * h * xw.pixelsize;
	xw.width = w;
	xw.height = h;
	xw.screennum = DefaultScreen(xw.display);
	xw.depth = DefaultDepth(xw.display, xw.screennum);
	xw.screenptr = DefaultScreenOfDisplay(xw.display);
	xw.visual = DefaultVisualOfScreen(xw.screenptr);
	xw.phys_width = DisplayWidth(xw.display, xw.screennum);
	xw.phys_height = DisplayHeight(xw.display, xw.screennum);

	/* initialize workspace parameters */
	pUIWorkspace[mm_DisplayWidth] = w;
	pUIWorkspace[mm_DisplayHeight] = h;
	pUIWorkspace[mm_DisplayPhysicalWidth] = xw.phys_width;
	pUIWorkspace[mm_DisplayPhysicalHeight] = xw.phys_height;
	pUIWorkspace[mm_DisplayStatus] = ACTIVE;

	/* only 24 bits screens are supported */
	if (xw.depth != 24)
		return false;

	/* create the window */
	xw.window = XCreateWindow(xw.display,
				  RootWindowOfScreen(xw.screenptr),
				  0 /* x */ , 0 /* y */ ,
				  256 /* w */ , 192 /* h */ ,
				  0, xw.depth, InputOutput, xw.visual, 0, NULL);
	if (!xw.window)
		return false;

	/* initialize graphic context */
	xw.gc = XCreateGC(xw.display, xw.window, 0, NULL);
	if (!xw.gc)
		return false;

	/* create image to hold background */
	xw.ximage = XCreateImage(xw.display, xw.visual, xw.depth, ZPixmap,
				 0, data, xw.width, xw.height,
				 32, xw.width * xw.pixelsize);
	if (!xw.ximage)
		return false;

	/* We change the title of the window (default:Untitled) */
	XStoreName(xw.display, xw.window, (char *) &IParagraph->appname);

	/* set autorepeat for keyboard input */
	XAutoRepeatOn(xw.display);

	/* initialize events */
	XSelectInput(xw.display, xw.window,
		     ExposureMask | KeyPressMask | KeyReleaseMask
		     | ButtonPressMask | ButtonReleaseMask);

	/* Set the size of the window */
	lino_display_resize(w, h);

	/* set the position of the window */
	lino_display_move(x, y);

	PRINT1("%s: Initializing display done.\n", __func__);
	return true;
}