Search
lxdream.org :: lxdream/src/gtkui/gtkui.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gtkui/gtkui.c
changeset 1040:9e3e41eab2db
prev1036:af7b0c5905dd
next1098:4f2750753a6c
author nkeynes
date Thu Jun 25 21:21:18 2009 +0000 (12 years ago)
permissions -rw-r--r--
last change Add quick state bits to the menus
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 <time.h>
    20 #include <stdlib.h>
    21 #include <unistd.h>
    22 #include <sys/time.h>
    23 #include <gtk/gtkversion.h>
    24 #include "lxdream.h"
    25 #include "dreamcast.h"
    26 #include "dream.h"
    27 #include "display.h"
    28 #include "gdrom/gdrom.h"
    29 #include "gtkui/gtkui.h"
    31 void gtk_gui_start( void );
    32 void gtk_gui_stop( void );
    33 void gtk_gui_alloc_resources ( void );
    34 uint32_t gtk_gui_run_slice( uint32_t nanosecs );
    36 struct dreamcast_module gtk_gui_module = { "gui", NULL,
    37         gtk_gui_update, 
    38         gtk_gui_start, 
    39         gtk_gui_run_slice, 
    40         gtk_gui_stop, 
    41         NULL, NULL };
    43 /**
    44  * Single-instance windows (at most one)
    45  */
    46 static main_window_t main_win = NULL;
    47 static debug_window_t debug_win = NULL;
    48 static mmio_window_t mmio_win = NULL;
    50 /**
    51  * UIManager and action helpers
    52  */
    53 static GtkUIManager *global_ui_manager;
    54 static GtkActionGroup *global_action_group;
    56 /**
    57  * Count of running nanoseconds - used to cut back on the GUI runtime
    58  */
    59 static uint32_t gtk_gui_nanos = 0;
    60 static uint32_t gtk_gui_ticks = 0;
    61 static struct timeval gtk_gui_lasttv;
    63 static gboolean gtk_gui_init_ok = FALSE;
    65 #define ENABLE_ACTION(win,name) SET_ACTION_ENABLED(win,name,TRUE)
    66 #define DISABLE_ACTION(win,name) SET_ACTION_ENABLED(win,name,FALSE)
    68 // UI Actions
    69 static const GtkActionEntry ui_actions[] = {
    70         { "FileMenu", NULL, N_("_File") },
    71         { "SettingsMenu", NULL, N_("_Settings") },
    72         { "HelpMenu", NULL, N_("_Help") },
    73         { "LoadBinary", NULL, N_("Load _Binary..."), NULL, N_("Load and run a program binary"), G_CALLBACK(load_binary_action_callback) },
    74         { "Reset", GTK_STOCK_REFRESH, N_("_Reset"), "<control>R", N_("Reset dreamcast"), G_CALLBACK(reset_action_callback) },
    75         { "Pause", GTK_STOCK_MEDIA_PAUSE, N_("_Pause"), NULL, N_("Pause dreamcast"), G_CALLBACK(pause_action_callback) },
    76         { "Run", GTK_STOCK_MEDIA_PLAY, N_("Resume"), NULL, N_("Resume"), G_CALLBACK(resume_action_callback) },
    77         { "LoadState", GTK_STOCK_REVERT_TO_SAVED, N_("L_oad State..."), "F4", N_("Load an lxdream save state"), G_CALLBACK(load_state_action_callback) },
    78         { "SaveState", GTK_STOCK_SAVE_AS, N_("S_ave State..."), "F3", N_("Create an lxdream save state"), G_CALLBACK(save_state_action_callback) },
    79         { "QuickLoad", NULL, N_("_Load Quick State"), "F6", N_("Load the current quick save state"), G_CALLBACK(quick_load_action_callback) },
    80         { "QuickSave", NULL, N_("_Save Quick State..."), "F5", N_("Save to the current quick save state"), G_CALLBACK(quick_save_action_callback) },
    81         { "QuickStateMenu", NULL, N_("Select _Quick State"), NULL, N_("Set quick save state") },
    82         { "Exit", GTK_STOCK_QUIT, N_("E_xit"), NULL, N_("Exit lxdream"), G_CALLBACK(exit_action_callback) },
    83         { "GdromSettings", NULL, N_("_GD-Rom") },
    84         { "GdromUnmount", NULL, N_("_Empty") },
    85         { "GdromMount", GTK_STOCK_CDROM, N_("_Open Image..."), "<control>O", N_("Mount a cdrom disc"), G_CALLBACK(mount_action_callback) },
    86         { "PathSettings", NULL, N_("_Paths..."), NULL, N_("Configure files and paths"), G_CALLBACK(path_settings_callback) }, 
    87         { "AudioSettings", NULL, N_("_Audio..."), NULL, N_("Configure audio output"), G_CALLBACK(audio_settings_callback) },
    88         { "ControllerSettings", NULL, N_("_Controllers..."), NULL, N_("Configure controllers"), G_CALLBACK(maple_settings_callback) },
    89         { "NetworkSettings", NULL, N_("_Network..."), NULL, N_("Configure network settings"), G_CALLBACK(network_settings_callback) },
    90         { "VideoSettings", NULL, N_("_Video..."), NULL,N_( "Configure video output"), G_CALLBACK(video_settings_callback) },
    91         { "HotkeySettings", NULL, N_("_Hotkeys..."), NULL,N_( "Configure hotkeys"), G_CALLBACK(hotkey_settings_callback) },
    92         { "About", GTK_STOCK_ABOUT, N_("_About..."), NULL, N_("About lxdream"), G_CALLBACK(about_action_callback) },
    93         { "DebugMenu", NULL, N_("_Debug") },
    94         { "Debugger", NULL, N_("_Debugger"), NULL, N_("Open debugger window"), G_CALLBACK(debugger_action_callback) },
    95         { "DebugMem", NULL, N_("View _Memory"), NULL, N_("View memory dump"), G_CALLBACK(debug_memory_action_callback) },
    96         { "DebugMmio", NULL, N_("View IO _Registers"), NULL, N_("View MMIO Registers"), G_CALLBACK(debug_mmio_action_callback) },
    97         { "SaveScene", NULL, N_("_Save Scene"), NULL, N_("Save next rendered scene"), G_CALLBACK(save_scene_action_callback) },
    98         { "SingleStep", GTK_STOCK_REDO, N_("_Single Step"), NULL, N_("Single step"), G_CALLBACK(debug_step_action_callback) },
    99         { "RunTo", GTK_STOCK_GOTO_LAST, N_("Run _To"), NULL, N_("Run to"), G_CALLBACK( debug_runto_action_callback) },
   100         { "SetBreakpoint", GTK_STOCK_CLOSE, N_("_Breakpoint"), NULL, N_("Toggle breakpoint"), G_CALLBACK( debug_breakpoint_action_callback) }
   101 };
   102 static const GtkToggleActionEntry ui_toggle_actions[] = {
   103         { "FullScreen", NULL, "_Full Screen", "<alt>Return", "Toggle full screen video", G_CALLBACK(fullscreen_toggle_callback), 0 },
   104 };
   105 static GtkRadioActionEntry ui_radio_actions[MAX_QUICK_STATE+1];
   107 // Menus and toolbars
   108 static const char *ui_description =
   109     "<ui>"
   110     " <menubar name='MainMenu'>"
   111     "  <menu action='FileMenu'>"
   112     "   <menuitem action='LoadBinary'/>"
   113     "   <menuitem action='GdromSettings'/>"
   114     "   <separator/>"
   115     "   <menuitem action='Reset'/>"
   116     "   <menuitem action='Pause'/>"
   117     "   <menuitem action='Run'/>"
   118     "   <menuitem action='Debugger'/>"
   119     "   <separator/>"
   120     "   <menuitem action='LoadState'/>"
   121     "   <menuitem action='SaveState'/>"
   122     "   <separator/>"
   123     "   <menuitem action='QuickLoad'/>"
   124     "   <menuitem action='QuickSave'/>"
   125     "   <menu action='QuickStateMenu'>"
   126     "    <menuitem action='QuickState0'/>"
   127     "    <menuitem action='QuickState1'/>"
   128     "    <menuitem action='QuickState2'/>"
   129     "    <menuitem action='QuickState3'/>"
   130     "    <menuitem action='QuickState4'/>"
   131     "    <menuitem action='QuickState5'/>"
   132     "    <menuitem action='QuickState6'/>"
   133     "    <menuitem action='QuickState7'/>"
   134     "    <menuitem action='QuickState8'/>"
   135     "    <menuitem action='QuickState9'/>"
   136     "   </menu>"
   137     "   <separator/>"
   138     "   <menuitem action='Exit'/>"
   139     "  </menu>"
   140     "  <menu action='SettingsMenu'>"
   141     "   <menuitem action='PathSettings'/>"
   142     "   <menuitem action='AudioSettings'/>"
   143     "   <menuitem action='ControllerSettings'/>"
   144     "   <menuitem action='NetworkSettings'/>"
   145     "   <menuitem action='VideoSettings'/>"
   146     "   <menuitem action='HotkeySettings'/>"
   147     "   <separator/>"
   148     "   <menuitem action='FullScreen'/>"
   149     "  </menu>"
   150     "  <menu action='HelpMenu'>"
   151     "   <menuitem action='About'/>"
   152     "  </menu>"
   153     " </menubar>"
   154     " <toolbar name='MainToolbar'>"
   155     "  <toolitem action='GdromMount'/>"
   156     "  <toolitem action='Reset'/>"
   157     "  <toolitem action='Pause'/>"
   158     "  <toolitem action='Run'/>"
   159     "  <separator/>"
   160     "  <toolitem action='LoadState'/>"
   161     "  <toolitem action='SaveState'/>"
   162     " </toolbar>"
   163     " <menubar name='DebugMenu'>"
   164     "  <menu action='FileMenu'>"
   165     "   <menuitem action='GdromSettings'/>"
   166     "   <separator/>"
   167     "   <menuitem action='Reset'/>"
   168     "   <separator/>"
   169     "   <menuitem action='LoadState'/>"
   170     "   <menuitem action='SaveState'/>"
   171     "   <separator/>"
   172     "   <menuitem action='QuickLoad'/>"
   173     "   <menuitem action='QuickSave'/>"
   174     "   <menu action='QuickStateMenu'>"
   175     "    <menuitem action='QuickState0'/>"
   176     "    <menuitem action='QuickState1'/>"
   177     "    <menuitem action='QuickState2'/>"
   178     "    <menuitem action='QuickState3'/>"
   179     "    <menuitem action='QuickState4'/>"
   180     "    <menuitem action='QuickState5'/>"
   181     "    <menuitem action='QuickState6'/>"
   182     "    <menuitem action='QuickState7'/>"
   183     "    <menuitem action='QuickState8'/>"
   184     "    <menuitem action='QuickState9'/>"
   185     "   </menu>"
   186     "   <separator/>"
   187     "   <menuitem action='Exit'/>"
   188     "  </menu>"
   189     "  <menu action='DebugMenu'>"
   190     "   <menuitem action='DebugMem'/>"
   191     "   <menuitem action='DebugMmio'/>"
   192     "   <menuitem action='SaveScene'/>"
   193     "   <separator/>"
   194     "   <menuitem action='SetBreakpoint'/>"
   195     "   <menuitem action='Pause'/>"
   196     "   <menuitem action='SingleStep'/>"
   197     "   <menuitem action='RunTo'/>"
   198     "   <menuitem action='Run'/>"
   199     "  </menu>"
   200     "  <menu action='SettingsMenu'>"
   201     "   <menuitem action='PathSettings'/>"
   202     "   <menuitem action='AudioSettings'/>"
   203     "   <menuitem action='ControllerSettings'/>"
   204     "   <menuitem action='NetworkSettings'/>"
   205     "   <menuitem action='VideoSettings'/>"
   206     "   <menuitem action='HotkeySettings'/>"
   207     "   <separator/>"
   208     "   <menuitem action='FullScreen'/>"
   209     "  </menu>"
   210     "  <menu action='HelpMenu'>"
   211     "   <menuitem action='About'/>"
   212     "  </menu>"
   213     " </menubar>"
   214     " <toolbar name='DebugToolbar'>"
   215     "  <toolitem action='GdromMount'/>"
   216     "  <toolitem action='Reset'/>"
   217     "  <toolitem action='Pause'/>"
   218     "  <separator/>"
   219     "  <toolitem action='SingleStep'/>"
   220     "  <toolitem action='RunTo'/>"
   221     "  <toolitem action='Run'/>"
   222     "  <toolitem action='SetBreakpoint'/>"
   223     "  <separator/>"
   224     "  <toolitem action='LoadState'/>"
   225     "  <toolitem action='SaveState'/>"
   226     " </toolbar>"
   227     "</ui>";
   229 gboolean gui_parse_cmdline( int *argc, char **argv[] )
   230 {
   231     gtk_gui_init_ok = gtk_init_check( argc, argv );
   232     return gtk_gui_init_ok;
   233 }
   235 gboolean gtk_gui_disc_changed( gdrom_disc_t disc, const gchar *disc_name, void *ptr )
   236 {
   237     main_window_update_title( main_win );
   238     return TRUE;
   239 }
   241 gboolean gui_init( gboolean withDebug, gboolean withFullscreen )
   242 {
   243     if( gtk_gui_init_ok ) {
   244         int i;
   245         GError *error = NULL;
   246         dreamcast_register_module( &gtk_gui_module );
   247         gtk_gui_alloc_resources();
   249         global_action_group = gtk_action_group_new("MenuActions");
   250         gtk_action_group_set_translation_domain( global_action_group, NULL );
   251         gtk_action_group_add_actions( global_action_group, ui_actions, G_N_ELEMENTS(ui_actions), NULL );
   252         gtk_action_group_add_toggle_actions( global_action_group, ui_toggle_actions, G_N_ELEMENTS(ui_toggle_actions), NULL );
   254         for( i=0; i<=MAX_QUICK_STATE; i++ ) {
   255             ui_radio_actions[i].name = g_strdup_printf("QuickState%d", i);
   256             ui_radio_actions[i].stock_id = NULL;
   257             ui_radio_actions[i].label = g_strdup_printf(_("State _%d"), i );
   258             ui_radio_actions[i].accelerator = NULL;
   259             ui_radio_actions[i].tooltip = g_strdup_printf(_("Use quick save state %d"),i);
   260             ui_radio_actions[i].value = i;
   261         }
   262         gtk_action_group_add_radio_actions( global_action_group, ui_radio_actions, G_N_ELEMENTS(ui_radio_actions), 
   263                                             dreamcast_get_quick_state(), G_CALLBACK(quick_state_action_callback), NULL );
   264         gtk_gui_enable_action("AudioSettings", FALSE);
   265         gtk_gui_enable_action("NetworkSettings", FALSE);
   266         gtk_gui_enable_action("VideoSettings", FALSE);
   268         global_ui_manager = gtk_ui_manager_new();
   269         gtk_ui_manager_set_add_tearoffs(global_ui_manager, TRUE);
   270         gtk_ui_manager_insert_action_group( global_ui_manager, global_action_group, 0 );
   272         if (!gtk_ui_manager_add_ui_from_string (global_ui_manager, ui_description, -1, &error)) {
   273             g_message ("building menus failed: %s", error->message);
   274             g_error_free (error);
   275             exit(1);
   276         }
   277         GtkAccelGroup *accel_group = gtk_ui_manager_get_accel_group (global_ui_manager);
   278         GtkWidget *menubar = gtk_ui_manager_get_widget(global_ui_manager, "/MainMenu");
   279         GtkWidget *toolbar = gtk_ui_manager_get_widget(global_ui_manager, "/MainToolbar");
   281         GtkWidget *gdrommenuitem = gtk_ui_manager_get_widget(global_ui_manager, "/MainMenu/FileMenu/GdromSettings");
   282         GtkWidget *gdrommenu = gdrom_menu_new();
   283         gtk_menu_item_set_submenu( GTK_MENU_ITEM(gdrommenuitem), gdrommenu );
   284         main_win = main_window_new( lxdream_package_name, menubar, toolbar, accel_group  );
   285         if( withDebug ) {
   286             gtk_gui_show_debugger();
   287         }
   289         if (withFullscreen) {
   290             main_window_set_fullscreen(main_win, TRUE);
   291             //manually call full-screen state code for non-compliant window managers
   292             main_window_show_gui(main_win, TRUE);
   293         }
   295         register_gdrom_disc_change_hook( gtk_gui_disc_changed, NULL );
   297         return TRUE;
   298     } else {
   299         return FALSE;
   300     }
   301 }
   303 void gui_main_loop( gboolean run )
   304 {
   305     gtk_gui_update();
   306     if( run ) {
   307         dreamcast_run();
   308         gtk_main();
   309     } else {
   310         gtk_main();
   311     }
   312 }
   314 void gui_update_state(void)
   315 {
   316     gtk_gui_update();
   317 }
   319 void gui_set_use_grab( gboolean flag )
   320 {
   321     if( main_win != NULL ) {
   322         main_window_set_use_grab(main_win, flag);
   323     }
   324 }
   326 gboolean gui_error_dialog( const char *msg, ... )
   327 {
   328     if( main_win != NULL ) {
   329         va_list args;
   330         GtkWidget *dialog = 
   331             gtk_message_dialog_new( main_window_get_frame(main_win), GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
   332                     GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, NULL );
   333         va_start(args, msg);
   334         gchar *markup = g_markup_vprintf_escaped( msg, args );
   335         va_end( args );
   336         gtk_message_dialog_set_markup( GTK_MESSAGE_DIALOG(dialog), markup );
   337         g_free(markup);
   338         gtk_dialog_run(GTK_DIALOG(dialog));
   339         gtk_widget_destroy(dialog);
   340         return TRUE;
   341     }
   342     return FALSE;
   343 }
   345 void gui_update_io_activity( io_activity_type io, gboolean active )
   346 {
   348 }
   350 static gboolean gtk_do_later_callback( gpointer ptr )
   351 {
   352     do_later_callback_t func = (do_later_callback_t)ptr;
   353     func();
   354     return FALSE;
   355 }
   357 void gui_do_later( do_later_callback_t func )
   358 {
   359     g_timeout_add_seconds(0, gtk_do_later_callback, func);
   360 }
   362 void gtk_gui_show_debugger()
   363 {
   364     if( debug_win ) {
   365         debug_window_show(debug_win, TRUE);
   366     } else {
   367         GtkAccelGroup *accel_group = gtk_ui_manager_get_accel_group (global_ui_manager);
   368         GtkWidget *menubar = gtk_ui_manager_get_widget(global_ui_manager, "/DebugMenu");
   369         GtkWidget *toolbar = gtk_ui_manager_get_widget(global_ui_manager, "/DebugToolbar");
   370         GtkWidget *gdrommenuitem = gtk_ui_manager_get_widget(global_ui_manager, "/DebugMenu/FileMenu/GdromSettings");
   371         GtkWidget *gdrommenu = gdrom_menu_new();
   372         gtk_menu_item_set_submenu( GTK_MENU_ITEM(gdrommenuitem), gdrommenu );
   373         gchar *title = g_strdup_printf( "%s :: %s", lxdream_package_name, _("Debugger"));
   374         debug_win = debug_window_new( title, menubar, toolbar, accel_group  );
   375         g_free(title);
   376     }
   377 }
   379 void gtk_gui_show_mmio()
   380 {
   381     if( mmio_win ) {
   382         mmio_window_show(mmio_win, TRUE);
   383     } else {
   384         gchar *title = g_strdup_printf( "%s :: %s", lxdream_package_name, _("MMIO Registers"));
   385         mmio_win = mmio_window_new( title );
   386         g_free(title);
   387     }
   388 }
   391 main_window_t gtk_gui_get_main()
   392 {
   393     return main_win;
   394 }
   396 debug_window_t gtk_gui_get_debugger()
   397 {
   398     return debug_win;
   399 }
   401 mmio_window_t gtk_gui_get_mmio()
   402 {
   403     return mmio_win;
   404 }
   406 /**
   407  * Hook called when DC starts running. Just disables the run/step buttons
   408  * and enables the stop button.
   409  */
   410 void gtk_gui_start( void )
   411 {
   412     main_window_set_running( main_win, TRUE );
   413     if( debug_win != NULL ) {
   414         debug_window_set_running( debug_win, TRUE );
   415     }
   416     gtk_gui_nanos = 0;
   417     gettimeofday(&gtk_gui_lasttv,NULL);
   418 }
   420 /**
   421  * Hook called when DC stops running. Enables the run/step buttons
   422  * and disables the stop button.
   423  */
   424 void gtk_gui_stop( void )
   425 {
   426     main_window_set_running( main_win, FALSE );
   427     gtk_gui_update();
   428 }
   430 void gtk_gui_update( void )
   431 {
   432     if( global_action_group ) {
   433         gtk_gui_enable_action("Run", !dreamcast_is_running() );
   434         gtk_gui_enable_action("Pause", dreamcast_is_running() );
   435     }
   436     if( debug_win ) {
   437         debug_window_set_running( debug_win, FALSE );
   438         debug_window_update(debug_win);
   439     }
   440     if( mmio_win ) {
   441         mmio_window_update(mmio_win);
   442     }
   443     dump_window_update_all();
   444 }
   446 /**
   447  * Module run-slice. Run the event loop 100 times/second (doesn't really need to be
   448  * any more often than this), and update the speed display 10 times/second. 
   449  *
   450  * Also detect if we're running too fast here and yield for a bit
   451  */
   452 uint32_t gtk_gui_run_slice( uint32_t nanosecs ) 
   453 {
   454     gtk_gui_nanos += nanosecs;
   455     if( gtk_gui_nanos > GUI_TICK_PERIOD ) { /* 10 ms */
   456         gtk_gui_nanos -= GUI_TICK_PERIOD;
   457         gtk_gui_ticks ++;
   458         uint32_t current_period = gtk_gui_ticks * GUI_TICK_PERIOD;
   460         // Run the event loop
   461         while( gtk_events_pending() )
   462             gtk_main_iteration();	
   464         struct timeval tv;
   465         gettimeofday(&tv,NULL);
   466         uint32_t ns = ((tv.tv_sec - gtk_gui_lasttv.tv_sec) * 1000000000) + 
   467         (tv.tv_usec - gtk_gui_lasttv.tv_usec)*1000;
   468         if( (ns * 1.05) < current_period ) {
   469             // We've gotten ahead - sleep for a little bit
   470             struct timespec tv;
   471             tv.tv_sec = 0;
   472             tv.tv_nsec = current_period - ns;
   473             nanosleep(&tv, &tv);
   474         }
   476         /* Update the display every 10 ticks (ie 10 times a second) and 
   477          * save the current tv value */
   478         if( gtk_gui_ticks > 10 ) {
   479             gtk_gui_ticks -= 10;
   481             double speed = (float)( (double)current_period * 100.0 / ns );
   482             gtk_gui_lasttv.tv_sec = tv.tv_sec;
   483             gtk_gui_lasttv.tv_usec = tv.tv_usec;
   484             main_window_set_speed( main_win, speed );
   485         }
   486     }
   487     return nanosecs;
   488 }
   491 PangoFontDescription *gui_fixed_font;
   492 GdkColor gui_colour_normal, gui_colour_changed, gui_colour_error;
   493 GdkColor gui_colour_warn, gui_colour_pc, gui_colour_debug;
   494 GdkColor gui_colour_trace, gui_colour_break, gui_colour_temp_break;
   495 GdkColor gui_colour_white;
   497 void gtk_gui_alloc_resources() {
   498     GdkColormap *map;
   500     gui_colour_normal.red = gui_colour_normal.green = gui_colour_normal.blue = 0;
   501     gui_colour_changed.red = gui_colour_changed.green = 64*256;
   502     gui_colour_changed.blue = 154*256;
   503     gui_colour_error.red = 65535;
   504     gui_colour_error.green = gui_colour_error.blue = 64*256;
   505     gui_colour_pc.red = 32*256;
   506     gui_colour_pc.green = 170*256;
   507     gui_colour_pc.blue = 52*256;
   508     gui_colour_warn = gui_colour_changed;
   509     gui_colour_trace.red = 156*256;
   510     gui_colour_trace.green = 78*256;
   511     gui_colour_trace.blue = 201*256;
   512     gui_colour_debug = gui_colour_pc;
   513     gui_colour_break.red = 65535;
   514     gui_colour_break.green = gui_colour_break.blue = 192*256;
   515     gui_colour_temp_break.red = gui_colour_temp_break.green = 128*256;
   516     gui_colour_temp_break.blue = 32*256;
   517     gui_colour_white.red = gui_colour_white.green = gui_colour_white.blue = 65535;
   519     map = gdk_colormap_new(gdk_visual_get_best(), TRUE);
   520     gdk_colormap_alloc_color(map, &gui_colour_normal, TRUE, TRUE);
   521     gdk_colormap_alloc_color(map, &gui_colour_changed, TRUE, TRUE);
   522     gdk_colormap_alloc_color(map, &gui_colour_error, TRUE, TRUE);
   523     gdk_colormap_alloc_color(map, &gui_colour_warn, TRUE, TRUE);
   524     gdk_colormap_alloc_color(map, &gui_colour_pc, TRUE, TRUE);
   525     gdk_colormap_alloc_color(map, &gui_colour_debug, TRUE, TRUE);
   526     gdk_colormap_alloc_color(map, &gui_colour_trace, TRUE, TRUE);
   527     gdk_colormap_alloc_color(map, &gui_colour_break, TRUE, TRUE);
   528     gdk_colormap_alloc_color(map, &gui_colour_temp_break, TRUE, TRUE);
   529     gdk_colormap_alloc_color(map, &gui_colour_white, TRUE, TRUE);
   530     gui_fixed_font = pango_font_description_from_string("Courier 10");
   531 }
   533 gint gtk_gui_run_property_dialog( const gchar *title, GtkWidget *panel, gtk_dialog_done_fn fn )
   534 {
   535     GtkWidget *dialog =
   536         gtk_dialog_new_with_buttons(title, main_window_get_frame(main_win), 
   537                 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
   538                 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
   539                 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
   540                 NULL);
   541     gint result;
   542     gtk_widget_show_all(panel);
   543     gtk_container_add( GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), panel );
   544     result = gtk_dialog_run( GTK_DIALOG(dialog) );
   545     if( fn != NULL ) {
   546         fn(panel, result == GTK_RESPONSE_ACCEPT);
   547     }
   548     gtk_widget_destroy( dialog );
   549     return result;
   550 }
   552 void gtk_gui_enable_action( const gchar *action, gboolean enable )
   553 {
   554     gtk_action_set_sensitive( gtk_action_group_get_action( global_action_group, action), enable);
   555 }
   557 static void delete_frame_buffer( guchar *pixels, gpointer buffer )
   558 {
   559     if( buffer != NULL ) {
   560         g_free(buffer);
   561     }
   562 }
   564 GdkPixbuf *gdk_pixbuf_new_from_frame_buffer( frame_buffer_t buffer )
   565 {
   566     return gdk_pixbuf_new_from_data( (unsigned char *)buffer->data, 
   567             GDK_COLORSPACE_RGB,
   568             (buffer->colour_format == COLFMT_BGRA8888),
   569             8,
   570             buffer->width,
   571             buffer->height,
   572             buffer->rowstride,
   573             delete_frame_buffer,
   574             buffer );
   575 }
   577 /**
   578  * Extract the keyval of the key event if no modifier keys were pressed -
   579  * in other words get the keyval of the key by itself. The other way around
   580  * would be to use the hardware keysyms directly rather than the keyvals,
   581  * but the mapping looks to be messier.
   582  */
   583 uint16_t gtk_get_unmodified_keyval( GdkEventKey *event )
   584 {
   585     GdkKeymap *keymap = gdk_keymap_get_default();
   586     guint keyval;
   588     gdk_keymap_translate_keyboard_state( keymap, event->hardware_keycode, 0, 0, &keyval, 
   589                                          NULL, NULL, NULL );
   590     return keyval;
   591 }
.