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