Search
lxdream.org :: lxdream/src/gtkui/gtk_win.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gtkui/gtk_win.c
changeset 1098:4f2750753a6c
prev1066:ddffe9d2b332
author nkeynes
date Sun Jan 31 18:36:06 2010 +1000 (10 years ago)
permissions -rw-r--r--
last change Show '<no disc>' in the title bar when there is no cdrom disc attached
file annotate diff log raw
nkeynes@435
     1
/**
nkeynes@561
     2
 * $Id$
nkeynes@435
     3
 *
nkeynes@435
     4
 * Define the main (emu) GTK window, along with its menubars,
nkeynes@435
     5
 * toolbars, etc.
nkeynes@435
     6
 *
nkeynes@435
     7
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@435
     8
 *
nkeynes@435
     9
 * This program is free software; you can redistribute it and/or modify
nkeynes@435
    10
 * it under the terms of the GNU General Public License as published by
nkeynes@435
    11
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@435
    12
 * (at your option) any later version.
nkeynes@435
    13
 *
nkeynes@435
    14
 * This program is distributed in the hope that it will be useful,
nkeynes@435
    15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@435
    16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@435
    17
 * GNU General Public License for more details.
nkeynes@435
    18
 */
nkeynes@435
    19
nkeynes@435
    20
#include <assert.h>
nkeynes@435
    21
#include <sys/types.h>
nkeynes@435
    22
#include <sys/stat.h>
nkeynes@435
    23
#include <unistd.h>
nkeynes@435
    24
#include <string.h>
nkeynes@435
    25
#include <stdio.h>
nkeynes@435
    26
#include <stdlib.h>
nkeynes@435
    27
nkeynes@986
    28
#include <X11/Xlib.h>
nkeynes@986
    29
#include <X11/Xutil.h>
nkeynes@435
    30
#include <gtk/gtk.h>
nkeynes@608
    31
#include <gdk/gdk.h>
nkeynes@608
    32
#include <gdk/gdkkeysyms.h>
nkeynes@435
    33
nkeynes@658
    34
#include "lxdream.h"
nkeynes@669
    35
#include "dreamcast.h"
nkeynes@669
    36
#include "display.h"
nkeynes@839
    37
#include "gdrom/gdrom.h"
nkeynes@537
    38
#include "gtkui/gtkui.h"
nkeynes@887
    39
#include "drivers/video_gl.h"
nkeynes@658
    40
nkeynes@435
    41
nkeynes@435
    42
struct main_window_info {
nkeynes@435
    43
    GtkWidget *window;
nkeynes@435
    44
    GtkWidget *video;
nkeynes@486
    45
    GtkWidget *menubar;
nkeynes@486
    46
    GtkWidget *toolbar;
nkeynes@435
    47
    GtkWidget *statusbar;
nkeynes@435
    48
    GtkActionGroup *actions;
nkeynes@608
    49
    gboolean use_grab;
nkeynes@608
    50
    gboolean is_grabbed;
nkeynes@608
    51
    int32_t mouse_x, mouse_y;
nkeynes@435
    52
};
nkeynes@435
    53
nkeynes@608
    54
nkeynes@608
    55
/******************** Video window **************************/
nkeynes@608
    56
nkeynes@839
    57
#if !(GTK_CHECK_VERSION(2,8,0))
nkeynes@839
    58
void gdk_display_warp_pointer (GdkDisplay *display,
nkeynes@839
    59
                               GdkScreen  *screen,
nkeynes@839
    60
                               gint        x,
nkeynes@839
    61
                               gint        y);
nkeynes@839
    62
#endif
nkeynes@839
    63
nkeynes@608
    64
/**
nkeynes@608
    65
 * Adjust the mouse pointer so that it appears in the center of the video
nkeynes@608
    66
 * window. Mainly used for when we have the mouse grab
nkeynes@608
    67
 */
nkeynes@608
    68
void video_window_center_pointer( main_window_t win )
nkeynes@608
    69
{
nkeynes@608
    70
    GdkDisplay *display = gtk_widget_get_display(win->video);
nkeynes@608
    71
    GdkScreen *screen = gtk_widget_get_screen(win->video);
nkeynes@608
    72
    int x,y;
nkeynes@608
    73
    int width, height;
nkeynes@608
    74
nkeynes@608
    75
    gdk_window_get_origin(win->video->window, &x, &y);
nkeynes@608
    76
    gdk_drawable_get_size(GDK_DRAWABLE(win->video->window), &width, &height);
nkeynes@608
    77
    x += width / 2;
nkeynes@608
    78
    y += height / 2;
nkeynes@736
    79
nkeynes@608
    80
    gdk_display_warp_pointer( display, screen, x, y );
nkeynes@608
    81
    win->mouse_x = width/2;
nkeynes@608
    82
    win->mouse_y = height/2;
nkeynes@608
    83
}
nkeynes@608
    84
nkeynes@608
    85
/**
nkeynes@608
    86
 * Grab the keyboard and mouse for the display. The mouse cursor is hidden and
nkeynes@608
    87
 * moved to the centre of the window.
nkeynes@608
    88
 *
nkeynes@608
    89
 * @param win The window receiving the grab
nkeynes@608
    90
 * @return TRUE if the grab was successful, FALSE on failure.
nkeynes@608
    91
 */
nkeynes@608
    92
gboolean video_window_grab_display( main_window_t win )
nkeynes@608
    93
{
nkeynes@608
    94
    GdkWindow *gdkwin = win->video->window;
nkeynes@608
    95
    GdkColor color = { 0,0,0,0 };
nkeynes@608
    96
    char bytes[32]; /* 16 * 16 / 8 */
nkeynes@608
    97
    memset(bytes, 0, 32);
nkeynes@608
    98
    GdkPixmap *pixmap = gdk_bitmap_create_from_data(NULL, bytes, 16, 16);
nkeynes@608
    99
    GdkCursor *cursor = gdk_cursor_new_from_pixmap(pixmap, pixmap, &color, &color, 16, 16);
nkeynes@608
   100
    gdk_pixmap_unref(pixmap);
nkeynes@608
   101
nkeynes@608
   102
    gboolean success =
nkeynes@736
   103
        gdk_pointer_grab( gdkwin, FALSE, 
nkeynes@736
   104
                GDK_POINTER_MOTION_MASK|GDK_BUTTON_PRESS_MASK|GDK_BUTTON_RELEASE_MASK, 
nkeynes@736
   105
                gdkwin, cursor, GDK_CURRENT_TIME ) == GDK_GRAB_SUCCESS;
nkeynes@608
   106
    gdk_cursor_unref(cursor);
nkeynes@608
   107
    if( success ) {
nkeynes@736
   108
        success = gdk_keyboard_grab( gdkwin, FALSE, GDK_CURRENT_TIME ) == GDK_GRAB_SUCCESS;
nkeynes@736
   109
        if( !success ) {
nkeynes@736
   110
            gdk_pointer_ungrab(GDK_CURRENT_TIME);
nkeynes@736
   111
        }
nkeynes@608
   112
    }
nkeynes@608
   113
    win->is_grabbed = success;
nkeynes@608
   114
    main_window_set_running(win, dreamcast_is_running());
nkeynes@608
   115
    return success;
nkeynes@608
   116
}
nkeynes@608
   117
nkeynes@608
   118
/**
nkeynes@608
   119
 * Release the display grab.
nkeynes@608
   120
 */
nkeynes@608
   121
void video_window_ungrab_display( main_window_t win )
nkeynes@608
   122
{
nkeynes@608
   123
    gdk_pointer_ungrab(GDK_CURRENT_TIME);
nkeynes@608
   124
    gdk_keyboard_ungrab(GDK_CURRENT_TIME);
nkeynes@608
   125
    win->is_grabbed = FALSE;
nkeynes@608
   126
    main_window_set_running(win, dreamcast_is_running());
nkeynes@608
   127
}
nkeynes@608
   128
nkeynes@608
   129
static gboolean on_video_window_mouse_motion( GtkWidget *widget, GdkEventMotion *event,
nkeynes@736
   130
                                              gpointer user_data )
nkeynes@608
   131
{
nkeynes@608
   132
    main_window_t win = (main_window_t)user_data;
nkeynes@854
   133
    int x = (int)event->x;
nkeynes@854
   134
    int y = (int)event->y;
nkeynes@608
   135
    if( win->is_grabbed && 
nkeynes@736
   136
            (x != win->mouse_x || y != win->mouse_y) ) {
nkeynes@849
   137
        input_event_mousemove( x - win->mouse_x, y - win->mouse_y, FALSE );
nkeynes@736
   138
        video_window_center_pointer(win);
nkeynes@849
   139
    } else {
nkeynes@850
   140
        int width, height;
nkeynes@854
   141
        gl_window_to_system_coords( &x, &y );
nkeynes@854
   142
        input_event_mousemove( x, y, TRUE );
nkeynes@608
   143
    }
nkeynes@608
   144
    return TRUE;
nkeynes@608
   145
}
nkeynes@608
   146
nkeynes@850
   147
static gboolean on_video_window_mouse_exited( GtkWidget *widget, GdkEventCrossing *event,
nkeynes@850
   148
                                              gpointer user_data )
nkeynes@850
   149
{
nkeynes@850
   150
    main_window_t win = (main_window_t)user_data;
nkeynes@850
   151
    if( !win->is_grabbed ) {
nkeynes@850
   152
        input_event_mousemove( -1, -1, TRUE );
nkeynes@850
   153
    }
nkeynes@850
   154
    return TRUE;
nkeynes@850
   155
}    
nkeynes@850
   156
nkeynes@608
   157
static gboolean on_video_window_mouse_pressed( GtkWidget *widget, GdkEventButton *event,
nkeynes@736
   158
                                               gpointer user_data )
nkeynes@608
   159
{
nkeynes@608
   160
    main_window_t win = (main_window_t)user_data;
nkeynes@608
   161
    if( win->is_grabbed ) {
nkeynes@849
   162
        input_event_mousedown( event->button-1, 0, 0, FALSE );
nkeynes@839
   163
    } else {
nkeynes@854
   164
        int x = (int)event->x;
nkeynes@854
   165
        int y = (int)event->y;
nkeynes@854
   166
        gl_window_to_system_coords( &x, &y );
nkeynes@854
   167
        input_event_mousedown( event->button-1, x, y, TRUE ); 
nkeynes@608
   168
    }
nkeynes@608
   169
    return TRUE;
nkeynes@608
   170
}
nkeynes@608
   171
nkeynes@608
   172
static gboolean on_video_window_mouse_released( GtkWidget *widget, GdkEventButton *event,
nkeynes@736
   173
                                                gpointer user_data )
nkeynes@608
   174
{
nkeynes@608
   175
    main_window_t win = (main_window_t)user_data;
nkeynes@608
   176
    if( win->is_grabbed ) {
nkeynes@849
   177
        input_event_mouseup( event->button-1, 0, 0, FALSE );
nkeynes@608
   178
    } else if( win->use_grab) {
nkeynes@736
   179
        video_window_grab_display(win);
nkeynes@839
   180
    } else {
nkeynes@854
   181
        int x = (int)event->x;
nkeynes@854
   182
        int y = (int)event->y;
nkeynes@854
   183
        gl_window_to_system_coords( &x, &y );
nkeynes@854
   184
        input_event_mouseup( event->button-1, x, y, TRUE ); 
nkeynes@839
   185
    }        
nkeynes@608
   186
    return TRUE;
nkeynes@608
   187
}
nkeynes@608
   188
nkeynes@608
   189
static gboolean on_video_window_key_pressed( GtkWidget *widget, GdkEventKey *event,
nkeynes@736
   190
                                             gpointer user_data )
nkeynes@608
   191
{
nkeynes@608
   192
    main_window_t win = (main_window_t)user_data;
nkeynes@608
   193
    if( win->is_grabbed ) {
nkeynes@668
   194
#ifdef HAVE_GTK_OSX
nkeynes@736
   195
        /* On OSX, use the command key rather than ctrl-alt. Mainly because GTK/OSX 
nkeynes@736
   196
         * doesn't seem to be able to get ctrl-alt reliably 
nkeynes@736
   197
         **/
nkeynes@736
   198
        if( event->keyval == GDK_Meta_L || event->keyval == GDK_Meta_R ) {
nkeynes@736
   199
            video_window_ungrab_display(win);
nkeynes@736
   200
            return TRUE;
nkeynes@736
   201
        }
nkeynes@668
   202
#else    	
nkeynes@736
   203
        /* Check for ungrab key combo (ctrl-alt). Unfortunately GDK sends it as
nkeynes@736
   204
         * a singly-modified keypress rather than a double-modified 'null' press, 
nkeynes@736
   205
         * so we have to do a little more work.
nkeynes@736
   206
         * Only check Ctrl/Shift/Alt for state - don't want to check numlock/capslock/
nkeynes@736
   207
         * mouse buttons/etc
nkeynes@736
   208
         */
nkeynes@618
   209
        int mod = gdk_keycode_to_modifier(gtk_widget_get_display(widget), event->hardware_keycode);
nkeynes@736
   210
        int state = event->state & gtk_accelerator_get_default_mod_mask();
nkeynes@736
   211
        if( (state == GDK_CONTROL_MASK && mod == GDK_MOD1_MASK) ||
nkeynes@736
   212
                (state == GDK_MOD1_MASK && mod == GDK_CONTROL_MASK) ) {
nkeynes@736
   213
            video_window_ungrab_display(win);
nkeynes@736
   214
            // Consume the keypress, DC doesn't get it.
nkeynes@736
   215
            return TRUE;
nkeynes@736
   216
        }
nkeynes@668
   217
#endif
nkeynes@608
   218
    }
nkeynes@1010
   219
    input_event_keydown( NULL, gtk_get_unmodified_keyval(event), MAX_PRESSURE );
nkeynes@608
   220
    return TRUE;
nkeynes@608
   221
}
nkeynes@608
   222
nkeynes@608
   223
static gboolean on_video_window_key_released( GtkWidget *widget, GdkEventKey *event,
nkeynes@736
   224
                                              gpointer user_data )
nkeynes@608
   225
{
nkeynes@1010
   226
    input_event_keyup( NULL, gtk_get_unmodified_keyval(event) );
nkeynes@608
   227
    return TRUE;
nkeynes@608
   228
}
nkeynes@608
   229
nkeynes@614
   230
static gboolean on_video_window_focus_changed( GtkWidget *widget, GdkEventFocus *event,
nkeynes@736
   231
                                               gpointer user_data )
nkeynes@614
   232
{
nkeynes@614
   233
    display_set_focused(event->in);
nkeynes@669
   234
    return TRUE;
nkeynes@614
   235
}
nkeynes@614
   236
nkeynes@608
   237
/*************************** Main window (frame) ******************************/
nkeynes@608
   238
nkeynes@486
   239
static gboolean on_main_window_deleted( GtkWidget *widget, GdkEvent event, gpointer user_data )
nkeynes@457
   240
{
nkeynes@671
   241
    dreamcast_shutdown();
nkeynes@457
   242
    exit(0);
nkeynes@457
   243
}
nkeynes@457
   244
nkeynes@486
   245
static void on_main_window_state_changed( GtkWidget *widget, GdkEventWindowState *state, 
nkeynes@736
   246
                                          gpointer userdata )
nkeynes@486
   247
{
nkeynes@497
   248
    main_window_t win = (main_window_t)userdata;
nkeynes@486
   249
    if( state->changed_mask & GDK_WINDOW_STATE_FULLSCREEN ) {
nkeynes@736
   250
        gboolean fs = (state->new_window_state & GDK_WINDOW_STATE_FULLSCREEN);
nkeynes@1015
   251
        main_window_show_gui(win, fs);
nkeynes@1015
   252
    }
nkeynes@1015
   253
}
nkeynes@736
   254
nkeynes@1015
   255
void main_window_show_gui(main_window_t win, gboolean fullscreen)
nkeynes@1015
   256
{
nkeynes@1015
   257
    GtkWidget *frame = gtk_widget_get_parent(win->video);
nkeynes@1015
   258
    if( frame->style == NULL ) {
nkeynes@1015
   259
        gtk_widget_set_style( frame, gtk_style_new() );
nkeynes@486
   260
    }
nkeynes@1015
   261
    if( fullscreen ) {
nkeynes@1015
   262
        gtk_widget_hide( win->menubar );
nkeynes@1015
   263
        gtk_widget_hide( win->toolbar );
nkeynes@1015
   264
        gtk_widget_hide( win->statusbar );
nkeynes@1015
   265
nkeynes@1015
   266
        frame->style->xthickness = 0;
nkeynes@1015
   267
        frame->style->ythickness = 0;
nkeynes@1015
   268
    } else {
nkeynes@1015
   269
        frame->style->xthickness = 2;
nkeynes@1015
   270
        frame->style->ythickness = 2;
nkeynes@1015
   271
        gtk_widget_show( win->menubar );
nkeynes@1015
   272
        gtk_widget_show( win->toolbar );
nkeynes@1015
   273
        gtk_widget_show( win->statusbar );
nkeynes@1015
   274
    }
nkeynes@1015
   275
    gtk_widget_queue_draw( win->window );
nkeynes@486
   276
}
nkeynes@486
   277
nkeynes@455
   278
main_window_t main_window_new( const gchar *title, GtkWidget *menubar, GtkWidget *toolbar,
nkeynes@736
   279
                               GtkAccelGroup *accel_group )
nkeynes@435
   280
{
nkeynes@435
   281
    GtkWidget *vbox;
nkeynes@437
   282
    GtkWidget *frame;
nkeynes@435
   283
    main_window_t win = g_malloc0( sizeof(struct main_window_info) );
nkeynes@435
   284
nkeynes@435
   285
    win->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
nkeynes@486
   286
    win->menubar = menubar;
nkeynes@486
   287
    win->toolbar = toolbar;
nkeynes@608
   288
    win->use_grab = FALSE;
nkeynes@608
   289
    win->is_grabbed = FALSE;
nkeynes@435
   290
    gtk_window_set_title( GTK_WINDOW(win->window), title );
nkeynes@435
   291
    gtk_window_add_accel_group (GTK_WINDOW (win->window), accel_group);
nkeynes@1017
   292
    gtk_window_set_icon_from_file( GTK_WINDOW(win->window), 
nkeynes@1017
   293
                                   PACKAGE_DATA_DIR "/pixmaps/lxdream.png", NULL );
nkeynes@435
   294
nkeynes@455
   295
    gtk_toolbar_set_style( GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS );
nkeynes@658
   296
nkeynes@659
   297
    win->video = video_gtk_create_drawable();
nkeynes@435
   298
    gtk_widget_set_size_request( win->video, 640, 480 ); 
nkeynes@608
   299
    gtk_widget_set_double_buffered( win->video, FALSE );
nkeynes@437
   300
    frame = gtk_frame_new(NULL);
nkeynes@437
   301
    gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_IN );
nkeynes@437
   302
    gtk_container_add( GTK_CONTAINER(frame), win->video );
nkeynes@437
   303
nkeynes@435
   304
    win->statusbar = gtk_statusbar_new();
nkeynes@435
   305
nkeynes@435
   306
    vbox = gtk_vbox_new(FALSE, 0);
nkeynes@435
   307
    gtk_container_add( GTK_CONTAINER(win->window), vbox );
nkeynes@455
   308
    gtk_box_pack_start( GTK_BOX(vbox), menubar, FALSE, FALSE, 0 );
nkeynes@455
   309
    gtk_box_pack_start( GTK_BOX(vbox), toolbar, FALSE, FALSE, 0 );
nkeynes@437
   310
    gtk_box_pack_start( GTK_BOX(vbox), frame, TRUE, TRUE, 0 );
nkeynes@435
   311
    gtk_box_pack_start( GTK_BOX(vbox), win->statusbar, FALSE, FALSE, 0 );
nkeynes@435
   312
    gtk_widget_show_all( win->window );
nkeynes@435
   313
    gtk_widget_grab_focus( win->video );
nkeynes@736
   314
nkeynes@437
   315
    gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, "Stopped" );
nkeynes@608
   316
nkeynes@457
   317
    g_signal_connect( win->window, "delete_event", 
nkeynes@736
   318
                      G_CALLBACK(on_main_window_deleted), win );
nkeynes@486
   319
    g_signal_connect( win->window, "window-state-event",
nkeynes@736
   320
                      G_CALLBACK(on_main_window_state_changed), win );
nkeynes@608
   321
nkeynes@608
   322
    g_signal_connect( win->video, "key-press-event",
nkeynes@736
   323
                      G_CALLBACK(on_video_window_key_pressed), win );
nkeynes@608
   324
    g_signal_connect( win->video, "key-release-event",
nkeynes@736
   325
                      G_CALLBACK(on_video_window_key_released), win );
nkeynes@608
   326
    g_signal_connect( win->video, "motion-notify-event",
nkeynes@736
   327
                      G_CALLBACK(on_video_window_mouse_motion), win );
nkeynes@850
   328
    g_signal_connect( win->video, "leave-notify-event",
nkeynes@850
   329
                      G_CALLBACK(on_video_window_mouse_exited), win );
nkeynes@608
   330
    g_signal_connect( win->video, "button-press-event",
nkeynes@736
   331
                      G_CALLBACK(on_video_window_mouse_pressed), win );
nkeynes@608
   332
    g_signal_connect( win->video, "button-release-event", 
nkeynes@736
   333
                      G_CALLBACK(on_video_window_mouse_released), win );
nkeynes@614
   334
    g_signal_connect( win->video, "focus-in-event",
nkeynes@736
   335
                      G_CALLBACK(on_video_window_focus_changed), win);
nkeynes@614
   336
    g_signal_connect( win->video, "focus-out-event",
nkeynes@736
   337
                      G_CALLBACK(on_video_window_focus_changed), win);
nkeynes@608
   338
nkeynes@608
   339
    gtk_widget_add_events( win->video, 
nkeynes@736
   340
                           GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK |
nkeynes@736
   341
                           GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
nkeynes@850
   342
                           GDK_POINTER_MOTION_MASK | GDK_FOCUS_CHANGE_MASK |
nkeynes@850
   343
                           GDK_LEAVE_NOTIFY_MASK );
nkeynes@608
   344
nkeynes@435
   345
    return win;
nkeynes@435
   346
}
nkeynes@435
   347
nkeynes@887
   348
void main_window_set_status_text( main_window_t win, const char *text )
nkeynes@608
   349
{
nkeynes@608
   350
    gtk_statusbar_pop( GTK_STATUSBAR(win->statusbar), 1 );
nkeynes@608
   351
    if( win->is_grabbed ) {
nkeynes@736
   352
        char buf[128];
nkeynes@668
   353
#ifdef HAVE_GTK_OSX
nkeynes@736
   354
        snprintf( buf, sizeof(buf), "%s %s", text, _("(Press <command> to release grab)") );
nkeynes@668
   355
#else	
nkeynes@736
   356
        snprintf( buf, sizeof(buf), "%s %s", text, _("(Press <ctrl><alt> to release grab)") );
nkeynes@668
   357
#endif
nkeynes@736
   358
        gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, buf );
nkeynes@608
   359
    } else {
nkeynes@736
   360
        gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, text );
nkeynes@608
   361
    }
nkeynes@608
   362
}
nkeynes@608
   363
nkeynes@435
   364
void main_window_set_running( main_window_t win, gboolean running )
nkeynes@435
   365
{
nkeynes@887
   366
    const char *text = running ? _("Running") : _("Stopped");
nkeynes@455
   367
    gtk_gui_enable_action( "Pause", running );
nkeynes@889
   368
    gtk_gui_enable_action( "Run", !running );
nkeynes@608
   369
    main_window_set_status_text( win, text );
nkeynes@435
   370
}
nkeynes@435
   371
nkeynes@435
   372
void main_window_set_framerate( main_window_t win, float rate )
nkeynes@435
   373
{
nkeynes@435
   374
nkeynes@435
   375
nkeynes@435
   376
}
nkeynes@435
   377
nkeynes@437
   378
void main_window_set_speed( main_window_t win, double speed )
nkeynes@437
   379
{
nkeynes@437
   380
    char buf[32];
nkeynes@437
   381
nkeynes@480
   382
    snprintf( buf, 32, "Running (%2.4f%%)", speed );
nkeynes@608
   383
    main_window_set_status_text( win, buf );
nkeynes@437
   384
}
nkeynes@437
   385
nkeynes@435
   386
GtkWidget *main_window_get_renderarea( main_window_t win )
nkeynes@435
   387
{
nkeynes@435
   388
    return win->video;
nkeynes@435
   389
}
nkeynes@447
   390
nkeynes@447
   391
GtkWindow *main_window_get_frame( main_window_t win )
nkeynes@447
   392
{
nkeynes@447
   393
    return GTK_WINDOW(win->window);
nkeynes@447
   394
}
nkeynes@486
   395
nkeynes@486
   396
void main_window_set_fullscreen( main_window_t win, gboolean fullscreen )
nkeynes@486
   397
{
nkeynes@486
   398
    if( fullscreen ) {
nkeynes@736
   399
        gtk_window_fullscreen( GTK_WINDOW(win->window) );
nkeynes@486
   400
    } else {
nkeynes@736
   401
        gtk_window_unfullscreen( GTK_WINDOW(win->window) );
nkeynes@486
   402
    }
nkeynes@486
   403
}
nkeynes@608
   404
nkeynes@608
   405
void main_window_set_use_grab( main_window_t win, gboolean use_grab )
nkeynes@608
   406
{
nkeynes@608
   407
    if( use_grab != win->use_grab ) {
nkeynes@736
   408
        if( use_grab ) {
nkeynes@736
   409
            GdkCursor *cursor = gdk_cursor_new( GDK_HAND2 );
nkeynes@736
   410
            gdk_window_set_cursor( win->video->window, cursor );
nkeynes@736
   411
            gdk_cursor_unref( cursor );
nkeynes@736
   412
        } else {
nkeynes@736
   413
            gdk_window_set_cursor( win->video->window, NULL );
nkeynes@736
   414
            if( gdk_pointer_is_grabbed() ) {
nkeynes@736
   415
                video_window_ungrab_display(win);
nkeynes@736
   416
            }
nkeynes@736
   417
        }
nkeynes@736
   418
        win->use_grab = use_grab;
nkeynes@608
   419
    }
nkeynes@608
   420
}
nkeynes@837
   421
nkeynes@837
   422
void main_window_update_title( main_window_t win )
nkeynes@837
   423
{
nkeynes@837
   424
    const char *disc = gdrom_get_current_disc_title();
nkeynes@1098
   425
    char buf[256];
nkeynes@837
   426
    
nkeynes@837
   427
    if( disc == NULL ) {
nkeynes@1098
   428
        snprintf( buf, sizeof(buf), "%s - <%s>", lxdream_package_name, _("no disc") );
nkeynes@837
   429
    } else {
nkeynes@837
   430
        snprintf( buf, sizeof(buf), "%s - %s", lxdream_package_name, disc );
nkeynes@837
   431
    }
nkeynes@1098
   432
    gtk_window_set_title( GTK_WINDOW(win->window), buf );
nkeynes@843
   433
}
.