Search
lxdream.org :: lxdream/src/gtkui/gtkui.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gtkui/gtkui.c
changeset 630:50addb748df5
prev622:3554650afb26
next658:f5926310bfbe
author nkeynes
date Fri Mar 28 12:32:25 2008 +0000 (12 years ago)
permissions -rw-r--r--
last change Merge lxdream-render branch (643:670) to trunk
view annotate diff log raw
     1 /**
     2  * $Id$
     3  *
     4  * Core GTK-based user interface
     5  *
     6  * Copyright (c) 2005 Nathan Keynes.
     7  *
     8  * This program is free software; you can redistribute it and/or modify
     9  * it under the terms of the GNU General Public License as published by
    10  * the Free Software Foundation; either version 2 of the License, or
    11  * (at your option) any later version.
    12  *
    13  * This program is distributed in the hope that it will be useful,
    14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  * GNU General Public License for more details.
    17  */
    19 #include "lxdream.h"
    20 #include <sys/time.h>
    21 #include <time.h>
    22 #include <glib/gi18n.h>
    23 #include <gtk/gtkversion.h>
    24 #include "dreamcast.h"
    25 #include "display.h"
    26 #include "gdrom/gdrom.h"
    27 #include "gtkui/gtkui.h"
    29 /* Base GUI clock is 10ms */
    30 #define GUI_TICK_PERIOD 10000000
    32 void gtk_gui_start( void );
    33 void gtk_gui_stop( void );
    34 void gtk_gui_alloc_resources ( void );
    35 uint32_t gtk_gui_run_slice( uint32_t nanosecs );
    37 struct dreamcast_module gtk_gui_module = { "gui", NULL,
    38 					   gtk_gui_update, 
    39 					   gtk_gui_start, 
    40 					   gtk_gui_run_slice, 
    41 					   gtk_gui_stop, 
    42 					   NULL, NULL };
    44 /**
    45  * Single-instance windows (at most one)
    46  */
    47 static main_window_t main_win = NULL;
    48 static debug_window_t debug_win = NULL;
    49 static mmio_window_t mmio_win = NULL;
    51 /**
    52  * UIManager and action helpers
    53  */
    54 static GtkUIManager *global_ui_manager;
    55 static GtkActionGroup *global_action_group;
    57 /**
    58  * Count of running nanoseconds - used to cut back on the GUI runtime
    59  */
    60 static uint32_t gtk_gui_nanos = 0;
    61 static uint32_t gtk_gui_ticks = 0;
    62 static struct timeval gtk_gui_lasttv;
    64 static gboolean gtk_gui_init_ok = FALSE;
    66 #define ENABLE_ACTION(win,name) SET_ACTION_ENABLED(win,name,TRUE)
    67 #define DISABLE_ACTION(win,name) SET_ACTION_ENABLED(win,name,FALSE)
    69 // UI Actions
    70 static const GtkActionEntry ui_actions[] = {
    71     { "FileMenu", NULL, N_("_File") },
    72     { "SettingsMenu", NULL, N_("_Settings") },
    73     { "HelpMenu", NULL, N_("_Help") },
    74     { "LoadBinary", NULL, N_("Load _Binary..."), NULL, N_("Load and run a program binary"), G_CALLBACK(load_binary_action_callback) },
    75     { "Reset", GTK_STOCK_REFRESH, N_("_Reset"), "<control>R", N_("Reset dreamcast"), G_CALLBACK(reset_action_callback) },
    76     { "Pause", GTK_STOCK_MEDIA_PAUSE, N_("_Pause"), NULL, N_("Pause dreamcast"), G_CALLBACK(pause_action_callback) },
    77     { "Run", GTK_STOCK_MEDIA_PLAY, N_("Resume"), NULL, N_("Resume"), G_CALLBACK(resume_action_callback) },
    78     { "LoadState", GTK_STOCK_REVERT_TO_SAVED, N_("_Load state..."), "F4", N_("Load an lxdream save state"), G_CALLBACK(load_state_action_callback) },
    79     { "SaveState", GTK_STOCK_SAVE_AS, N_("_Save state..."), "F3", N_("Create an lxdream save state"), G_CALLBACK(save_state_action_callback) },
    80     { "Exit", GTK_STOCK_QUIT, N_("E_xit"), NULL, N_("Exit lxdream"), G_CALLBACK(exit_action_callback) },
    81     { "GdromSettings", NULL, N_("_GD-Rom...") },
    82     { "GdromUnmount", NULL, N_("_Empty") },
    83     { "GdromMount", GTK_STOCK_CDROM, N_("_Open Image..."), "<control>O", N_("Mount a cdrom disc"), G_CALLBACK(mount_action_callback) },
    84     { "PathSettings", NULL, N_("_Paths..."), NULL, N_("Configure files and paths"), G_CALLBACK(path_settings_callback) }, 
    85     { "AudioSettings", NULL, N_("_Audio..."), NULL, N_("Configure audio output"), G_CALLBACK(audio_settings_callback) },
    86     { "ControllerSettings", NULL, N_("_Controllers..."), NULL, N_("Configure controllers"), G_CALLBACK(maple_settings_callback) },
    87     { "NetworkSettings", NULL, N_("_Network..."), NULL, N_("Configure network settings"), G_CALLBACK(network_settings_callback) },
    88     { "VideoSettings", NULL, N_("_Video..."), NULL,N_( "Configure video output"), G_CALLBACK(video_settings_callback) },
    89     { "About", GTK_STOCK_ABOUT, N_("_About..."), NULL, N_("About lxdream"), G_CALLBACK(about_action_callback) },
    90     { "DebugMenu", NULL, N_("_Debug") },
    91     { "Debugger", NULL, N_("_Debugger"), NULL, N_("Open debugger window"), G_CALLBACK(debugger_action_callback) },
    92     { "DebugMem", NULL, N_("View _Memory"), NULL, N_("View memory dump"), G_CALLBACK(debug_memory_action_callback) },
    93     { "DebugMmio", NULL, N_("View IO _Registers"), NULL, N_("View MMIO Registers"), G_CALLBACK(debug_mmio_action_callback) },
    94     { "SaveScene", NULL, N_("_Save Scene"), NULL, N_("Save next rendered scene"), G_CALLBACK(save_scene_action_callback) },
    95     { "SingleStep", GTK_STOCK_REDO, N_("_Single Step"), NULL, N_("Single step"), G_CALLBACK(debug_step_action_callback) },
    96     { "RunTo", GTK_STOCK_GOTO_LAST, N_("Run _To"), NULL, N_("Run to"), G_CALLBACK( debug_runto_action_callback) },
    97     { "SetBreakpoint", GTK_STOCK_CLOSE, N_("_Breakpoint"), NULL, N_("Toggle breakpoint"), G_CALLBACK( debug_breakpoint_action_callback) }
    98 };
    99 static const GtkToggleActionEntry ui_toggle_actions[] = {
   100     { "FullScreen", NULL, "_Full Screen", "<alt>Return", "Toggle full screen video", G_CALLBACK(fullscreen_toggle_callback), 0 },
   101 };
   103 // Menus and toolbars
   104 static const char *ui_description =
   105     "<ui>"
   106     " <menubar name='MainMenu'>"
   107     "  <menu action='FileMenu'>"
   108     "   <menuitem action='LoadBinary'/>"
   109     "   <menuitem action='GdromSettings'/>"
   110     "   <separator/>"
   111     "   <menuitem action='Reset'/>"
   112     "   <menuitem action='Pause'/>"
   113     "   <menuitem action='Run'/>"
   114     "   <menuitem action='Debugger'/>"
   115     "   <separator/>"
   116     "   <menuitem action='LoadState'/>"
   117     "   <menuitem action='SaveState'/>"
   118     "   <separator/>"
   119     "   <menuitem action='Exit'/>"
   120     "  </menu>"
   121     "  <menu action='SettingsMenu'>"
   122     "   <menuitem action='PathSettings'/>"
   123     "   <menuitem action='AudioSettings'/>"
   124     "   <menuitem action='ControllerSettings'/>"
   125     "   <menuitem action='NetworkSettings'/>"
   126     "   <menuitem action='VideoSettings'/>"
   127     "   <separator/>"
   128     "   <menuitem action='FullScreen'/>"
   129     "  </menu>"
   130     "  <menu action='HelpMenu'>"
   131     "   <menuitem action='About'/>"
   132     "  </menu>"
   133     " </menubar>"
   134     " <toolbar name='MainToolbar'>"
   135     "  <toolitem action='GdromMount'/>"
   136     "  <toolitem action='Reset'/>"
   137     "  <toolitem action='Pause'/>"
   138     "  <toolitem action='Run'/>"
   139     "  <separator/>"
   140     "  <toolitem action='LoadState'/>"
   141     "  <toolitem action='SaveState'/>"
   142     " </toolbar>"
   143     " <menubar name='DebugMenu'>"
   144     "  <menu action='FileMenu'>"
   145     "   <menuitem action='GdromSettings'/>"
   146     "   <separator/>"
   147     "   <menuitem action='Reset'/>"
   148     "   <separator/>"
   149     "   <menuitem action='LoadState'/>"
   150     "   <menuitem action='SaveState'/>"
   151     "   <separator/>"
   152     "   <menuitem action='Exit'/>"
   153     "  </menu>"
   154     "  <menu action='DebugMenu'>"
   155     "   <menuitem action='DebugMem'/>"
   156     "   <menuitem action='DebugMmio'/>"
   157     "   <menuitem action='SaveScene'/>"
   158     "   <separator/>"
   159     "   <menuitem action='SetBreakpoint'/>"
   160     "   <menuitem action='Pause'/>"
   161     "   <menuitem action='SingleStep'/>"
   162     "   <menuitem action='RunTo'/>"
   163     "   <menuitem action='Run'/>"
   164     "  </menu>"
   165     "  <menu action='SettingsMenu'>"
   166     "   <menuitem action='PathSettings'/>"
   167     "   <menuitem action='AudioSettings'/>"
   168     "   <menuitem action='ControllerSettings'/>"
   169     "   <menuitem action='NetworkSettings'/>"
   170     "   <menuitem action='VideoSettings'/>"
   171     "   <separator/>"
   172     "   <menuitem action='FullScreen'/>"
   173     "  </menu>"
   174     "  <menu action='HelpMenu'>"
   175     "   <menuitem action='About'/>"
   176     "  </menu>"
   177     " </menubar>"
   178     " <toolbar name='DebugToolbar'>"
   179     "  <toolitem action='GdromMount'/>"
   180     "  <toolitem action='Reset'/>"
   181     "  <toolitem action='Pause'/>"
   182     "  <separator/>"
   183     "  <toolitem action='SingleStep'/>"
   184     "  <toolitem action='RunTo'/>"
   185     "  <toolitem action='Run'/>"
   186     "  <toolitem action='SetBreakpoint'/>"
   187     "  <separator/>"
   188     "  <toolitem action='LoadState'/>"
   189     "  <toolitem action='SaveState'/>"
   190     " </toolbar>"
   191     "</ui>";
   193 gboolean gui_parse_cmdline( int *argc, char **argv[] )
   194 {
   195     gtk_gui_init_ok = gtk_init_check( argc, argv );
   196     return gtk_gui_init_ok;
   197 }
   199 gboolean gui_init( gboolean withDebug )
   200 {
   201     if( gtk_gui_init_ok ) {
   202 	GError *error = NULL;
   203 	dreamcast_register_module( &gtk_gui_module );
   204 	gtk_gui_alloc_resources();
   206 	global_action_group = gtk_action_group_new("MenuActions");
   207 	gtk_action_group_set_translation_domain( global_action_group, NULL );
   208 	gtk_action_group_add_actions( global_action_group, ui_actions, G_N_ELEMENTS(ui_actions), NULL );
   209 	gtk_action_group_add_toggle_actions( global_action_group, ui_toggle_actions, G_N_ELEMENTS(ui_toggle_actions), NULL );
   210 	gtk_gui_enable_action("AudioSettings", FALSE);
   211 	gtk_gui_enable_action("NetworkSettings", FALSE);
   212 	gtk_gui_enable_action("VideoSettings", FALSE);
   214 	global_ui_manager = gtk_ui_manager_new();
   215 	gtk_ui_manager_set_add_tearoffs(global_ui_manager, TRUE);
   216 	gtk_ui_manager_insert_action_group( global_ui_manager, global_action_group, 0 );
   218 	if (!gtk_ui_manager_add_ui_from_string (global_ui_manager, ui_description, -1, &error)) {
   219 	    g_message ("building menus failed: %s", error->message);
   220 	    g_error_free (error);
   221 	    exit(1);
   222 	}
   223 	GtkAccelGroup *accel_group = gtk_ui_manager_get_accel_group (global_ui_manager);
   224 	GtkWidget *menubar = gtk_ui_manager_get_widget(global_ui_manager, "/MainMenu");
   225 	GtkWidget *toolbar = gtk_ui_manager_get_widget(global_ui_manager, "/MainToolbar");
   227 	GtkWidget *gdrommenuitem = gtk_ui_manager_get_widget(global_ui_manager, "/MainMenu/FileMenu/GdromSettings");
   228 	gdrom_menu_init();
   229 	GtkWidget *gdrommenu = gdrom_menu_new();
   230 	gtk_menu_item_set_submenu( GTK_MENU_ITEM(gdrommenuitem), gdrommenu );
   231 	main_win = main_window_new( APP_NAME " " APP_VERSION, menubar, toolbar, accel_group  );
   232 	main_window_set_use_grab(main_win, TRUE);
   233 	if( withDebug ) {
   234 	    gtk_gui_show_debugger();
   235 	}
   237 	return TRUE;
   238     } else {
   239 	return FALSE;
   240     }
   241 }
   243 void gui_main_loop(void)
   244 {
   245     gtk_gui_update();
   246     gtk_main();
   247 }
   249 void gui_update_state(void)
   250 {
   251     gtk_gui_update();
   252 }
   254 gboolean gui_error_dialog( const char *msg, ... )
   255 {
   256     if( main_win != NULL ) {
   257 	va_list args;
   258 	GtkWidget *dialog = 
   259 	    gtk_message_dialog_new( main_window_get_frame(main_win), GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
   260 				    GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, NULL );
   261 	va_start(args, msg);
   262 	gchar *markup = g_markup_vprintf_escaped( msg, args );
   263 	va_end( args );
   264 	gtk_message_dialog_set_markup( GTK_MESSAGE_DIALOG(dialog), markup );
   265 	g_free(markup);
   266 	gtk_dialog_run(GTK_DIALOG(dialog));
   267 	gtk_widget_destroy(dialog);
   268 	return TRUE;
   269     }
   270     return FALSE;
   271 }
   273 void gui_update_io_activity( io_activity_type io, gboolean active )
   274 {
   276 }
   278 void gtk_gui_show_debugger()
   279 {
   280     if( debug_win ) {
   281 	debug_window_show(debug_win, TRUE);
   282     } else {
   283 	GtkAccelGroup *accel_group = gtk_ui_manager_get_accel_group (global_ui_manager);
   284 	GtkWidget *menubar = gtk_ui_manager_get_widget(global_ui_manager, "/DebugMenu");
   285 	GtkWidget *toolbar = gtk_ui_manager_get_widget(global_ui_manager, "/DebugToolbar");
   286 	GtkWidget *gdrommenuitem = gtk_ui_manager_get_widget(global_ui_manager, "/DebugMenu/FileMenu/GdromSettings");
   287 	GtkWidget *gdrommenu = gdrom_menu_new();
   288 	gtk_menu_item_set_submenu( GTK_MENU_ITEM(gdrommenuitem), gdrommenu );
   289 	gchar *title = g_strdup_printf( APP_NAME " " APP_VERSION " :: %s", _("Debugger"));
   290 	debug_win = debug_window_new( title, menubar, toolbar, accel_group  );
   291 	g_free(title);
   292     }
   293 }
   295 void gtk_gui_show_mmio()
   296 {
   297     if( mmio_win ) {
   298 	mmio_window_show(mmio_win, TRUE);
   299     } else {
   300 	gchar *title = g_strdup_printf( APP_NAME " " APP_VERSION " :: %s", _("MMIO Registers"));
   301 	mmio_win = mmio_window_new( title );
   302 	g_free(title);
   303     }
   304 }
   307 main_window_t gtk_gui_get_main()
   308 {
   309     return main_win;
   310 }
   312 debug_window_t gtk_gui_get_debugger()
   313 {
   314     return debug_win;
   315 }
   317 mmio_window_t gtk_gui_get_mmio()
   318 {
   319     return mmio_win;
   320 }
   322 GtkWidget *gtk_gui_get_renderarea()
   323 {
   324     if( main_win == NULL ) {
   325 	return NULL;
   326     } else {
   327 	return main_window_get_renderarea(main_win);
   328     }
   329 }
   331 /**
   332  * Hook called when DC starts running. Just disables the run/step buttons
   333  * and enables the stop button.
   334  */
   335 void gtk_gui_start( void )
   336 {
   337     main_window_set_running( main_win, TRUE );
   338     if( debug_win != NULL ) {
   339 	debug_window_set_running( debug_win, TRUE );
   340     }
   341     gtk_gui_nanos = 0;
   342     gettimeofday(&gtk_gui_lasttv,NULL);
   343 }
   345 /**
   346  * Hook called when DC stops running. Enables the run/step buttons
   347  * and disables the stop button.
   348  */
   349 void gtk_gui_stop( void )
   350 {
   351     main_window_set_running( main_win, FALSE );
   352     gtk_gui_update();
   353 }
   355 void gtk_gui_update( void )
   356 {
   357     if( global_action_group ) {
   358 	gtk_gui_enable_action("Run", dreamcast_can_run() && !dreamcast_is_running() );
   359 	gtk_gui_enable_action("Pause", dreamcast_is_running() );
   360     }
   361     if( debug_win ) {
   362 	debug_window_set_running( debug_win, FALSE );
   363 	debug_window_update(debug_win);
   364     }
   365     if( mmio_win ) {
   366 	mmio_window_update(mmio_win);
   367     }
   368     dump_window_update_all();
   369 }
   371 /**
   372  * Module run-slice. Run the event loop 100 times/second (doesn't really need to be
   373  * any more often than this), and update the speed display 10 times/second. 
   374  *
   375  * Also detect if we're running too fast here and yield for a bit
   376  */
   377 uint32_t gtk_gui_run_slice( uint32_t nanosecs ) 
   378 {
   379     gtk_gui_nanos += nanosecs;
   380     if( gtk_gui_nanos > GUI_TICK_PERIOD ) { /* 10 ms */
   381 	gtk_gui_nanos -= GUI_TICK_PERIOD;
   382 	gtk_gui_ticks ++;
   383 	uint32_t current_period = gtk_gui_ticks * GUI_TICK_PERIOD;
   385 	// Run the event loop
   386 	while( gtk_events_pending() )
   387 	    gtk_main_iteration();	
   389 	struct timeval tv;
   390 	gettimeofday(&tv,NULL);
   391 	uint32_t ns = ((tv.tv_sec - gtk_gui_lasttv.tv_sec) * 1000000000) + 
   392 	    (tv.tv_usec - gtk_gui_lasttv.tv_usec)*1000;
   393 	if( (ns * 1.05) < current_period ) {
   394 	    // We've gotten ahead - sleep for a little bit
   395 	    struct timespec tv;
   396 	    tv.tv_sec = 0;
   397 	    tv.tv_nsec = current_period - ns;
   398 	    nanosleep(&tv, &tv);
   399 	}
   401 	/* Update the display every 10 ticks (ie 10 times a second) and 
   402 	 * save the current tv value */
   403 	if( gtk_gui_ticks > 10 ) {
   404 	    gtk_gui_ticks -= 10;
   406 	    double speed = (float)( (double)current_period * 100.0 / ns );
   407 	    gtk_gui_lasttv.tv_sec = tv.tv_sec;
   408 	    gtk_gui_lasttv.tv_usec = tv.tv_usec;
   409 	    main_window_set_speed( main_win, speed );
   410 	}
   411     }
   412     return nanosecs;
   413 }
   416 PangoFontDescription *gui_fixed_font;
   417 GdkColor gui_colour_normal, gui_colour_changed, gui_colour_error;
   418 GdkColor gui_colour_warn, gui_colour_pc, gui_colour_debug;
   419 GdkColor gui_colour_trace, gui_colour_break, gui_colour_temp_break;
   420 GdkColor gui_colour_white;
   422 void gtk_gui_alloc_resources() {
   423     GdkColormap *map;
   425     gui_colour_normal.red = gui_colour_normal.green = gui_colour_normal.blue = 0;
   426     gui_colour_changed.red = gui_colour_changed.green = 64*256;
   427     gui_colour_changed.blue = 154*256;
   428     gui_colour_error.red = 65535;
   429     gui_colour_error.green = gui_colour_error.blue = 64*256;
   430     gui_colour_pc.red = 32*256;
   431     gui_colour_pc.green = 170*256;
   432     gui_colour_pc.blue = 52*256;
   433     gui_colour_warn = gui_colour_changed;
   434     gui_colour_trace.red = 156*256;
   435     gui_colour_trace.green = 78*256;
   436     gui_colour_trace.blue = 201*256;
   437     gui_colour_debug = gui_colour_pc;
   438     gui_colour_break.red = 65535;
   439     gui_colour_break.green = gui_colour_break.blue = 192*256;
   440     gui_colour_temp_break.red = gui_colour_temp_break.green = 128*256;
   441     gui_colour_temp_break.blue = 32*256;
   442     gui_colour_white.red = gui_colour_white.green = gui_colour_white.blue = 65535;
   444     map = gdk_colormap_new(gdk_visual_get_best(), TRUE);
   445     gdk_colormap_alloc_color(map, &gui_colour_normal, TRUE, TRUE);
   446     gdk_colormap_alloc_color(map, &gui_colour_changed, TRUE, TRUE);
   447     gdk_colormap_alloc_color(map, &gui_colour_error, TRUE, TRUE);
   448     gdk_colormap_alloc_color(map, &gui_colour_warn, TRUE, TRUE);
   449     gdk_colormap_alloc_color(map, &gui_colour_pc, TRUE, TRUE);
   450     gdk_colormap_alloc_color(map, &gui_colour_debug, TRUE, TRUE);
   451     gdk_colormap_alloc_color(map, &gui_colour_trace, TRUE, TRUE);
   452     gdk_colormap_alloc_color(map, &gui_colour_break, TRUE, TRUE);
   453     gdk_colormap_alloc_color(map, &gui_colour_temp_break, TRUE, TRUE);
   454     gdk_colormap_alloc_color(map, &gui_colour_white, TRUE, TRUE);
   455     gui_fixed_font = pango_font_description_from_string("Courier 10");
   456 }
   458 gint gtk_gui_run_property_dialog( const gchar *title, GtkWidget *panel, gtk_dialog_done_fn fn )
   459 {
   460     GtkWidget *dialog =
   461 	gtk_dialog_new_with_buttons(title, main_window_get_frame(main_win), 
   462 				    GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
   463 				    GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
   464 				    GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
   465 				    NULL);
   466     gint result;
   467     gtk_widget_show_all(panel);
   468     gtk_container_add( GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), panel );
   469     result = gtk_dialog_run( GTK_DIALOG(dialog) );
   470     if( fn != NULL ) {
   471 	fn(panel, result == GTK_RESPONSE_ACCEPT);
   472     }
   473     gtk_widget_destroy( dialog );
   474     return result;
   475 }
   477 void gtk_gui_enable_action( const gchar *action, gboolean enable )
   478 {
   479     gtk_action_set_sensitive( gtk_action_group_get_action( global_action_group, action), enable);
   480 }
   482 static void delete_frame_buffer( guchar *pixels, gpointer buffer )
   483 {
   484     if( buffer != NULL ) {
   485 	g_free(buffer);
   486     }
   487 }
   489 GdkPixbuf *gdk_pixbuf_new_from_frame_buffer( frame_buffer_t buffer )
   490 {
   491     return gdk_pixbuf_new_from_data( (unsigned char *)buffer->data, 
   492 				     GDK_COLORSPACE_RGB,
   493 				     (buffer->colour_format == COLFMT_BGRA8888),
   494 				     8,
   495 				     buffer->width,
   496 				     buffer->height,
   497 				     buffer->rowstride,
   498 				     delete_frame_buffer,
   499 				     buffer );
   500 }
   502 /**
   503  * Extract the keyval of the key event if no modifier keys were pressed -
   504  * in other words get the keyval of the key by itself. The other way around
   505  * would be to use the hardware keysyms directly rather than the keyvals,
   506  * but the mapping looks to be messier.
   507  */
   508 uint16_t gtk_get_unmodified_keyval( GdkEventKey *event )
   509 {
   510     GdkKeymap *keymap = gdk_keymap_get_default();
   511     guint keyval;
   513     gdk_keymap_translate_keyboard_state( keymap, event->hardware_keycode, 0, 0, &keyval, 
   514 					 NULL, NULL, NULL );
   515     return keyval;
   516 }
   518 gchar *get_absolute_path( const gchar *in_path )
   519 {
   520     char tmp[PATH_MAX];
   521     if( in_path == NULL ) {
   522 	return NULL;
   523     }
   524     if( in_path[0] == '/' || in_path[0] == 0 ) {
   525 	return g_strdup(in_path);
   526     } else {
   527 	getcwd(tmp, sizeof(tmp));
   528 	return g_strdup_printf("%s%c%s", tmp, G_DIR_SEPARATOR, in_path);
   529     }
   530 }
   532 /************* X11-specificness **********/
   533 #include <gdk/gdkx.h>
   535 guint gdk_keycode_to_modifier( GdkDisplay *display, guint keycode )
   536 {
   537   int i;
   538   int result = 0;
   539   Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
   540   XModifierKeymap *keymap = XGetModifierMapping( xdisplay );
   541   for( i=0; i<8*keymap->max_keypermod; i++ ) {
   542     if( keymap->modifiermap[i] == keycode ) {
   543       result = 1 << (i/keymap->max_keypermod);
   544       break;
   545     }
   546   }
   547   XFreeModifiermap(keymap);
   548   return result;
   549 }
   551 #if !(GTK_CHECK_VERSION(2,8,0))
   552 /* gdk_display_warp_pointer was added in GTK 2.8. If we're using an earlier
   553  * version, include the code here. (Can't just set the dependency on 2.8 as
   554  * it still hasn't been ported to OSX...) Original copyright statement belo
   555  */
   557 /* GDK - The GIMP Drawing Kit
   558  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
   559  *
   560  * This library is free software; you can redistribute it and/or
   561  * modify it under the terms of the GNU Lesser General Public
   562  * License as published by the Free Software Foundation; either
   563  * version 2 of the License, or (at your option) any later version.
   564  *
   565  * This library is distributed in the hope that it will be useful,
   566  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   567  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   568  * Lesser General Public License for more details.
   569  *
   570  * You should have received a copy of the GNU Lesser General Public
   571  * License along with this library; if not, write to the
   572  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   573  * Boston, MA 02111-1307, USA.
   574  */
   576 /*
   577  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
   578  * file for a list of people on the GTK+ Team.  See the ChangeLog
   579  * files for a list of changes.  These files are distributed with
   580  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
   581  */
   582 void gdk_display_warp_pointer (GdkDisplay *display,
   583                           GdkScreen  *screen,
   584                           gint        x,
   585                           gint        y)
   586 {
   587   Display *xdisplay;
   588   Window dest;
   590   xdisplay = GDK_DISPLAY_XDISPLAY (display);
   591   dest = GDK_WINDOW_XWINDOW (gdk_screen_get_root_window (screen));
   593   XWarpPointer (xdisplay, None, dest, 0, 0, 0, 0, x, y);  
   594 }
   596 #endif
.