Search
lxdream.org :: lxdream/src/drivers/video_gtk.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/video_gtk.c
changeset 485:dfa6bd020c11
prev481:3b2d6c5a19ad
next530:28bdc62e642a
author nkeynes
date Wed Oct 31 12:43:51 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Remove gnome.h
file annotate diff log raw
nkeynes@94
     1
/**
nkeynes@485
     2
 * $Id: video_gtk.c,v 1.19 2007-10-31 12:43:51 nkeynes Exp $
nkeynes@94
     3
 *
nkeynes@94
     4
 * The PC side of the video support (responsible for actually displaying / 
nkeynes@94
     5
 * rendering frames)
nkeynes@94
     6
 *
nkeynes@94
     7
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@94
     8
 *
nkeynes@94
     9
 * This program is free software; you can redistribute it and/or modify
nkeynes@94
    10
 * it under the terms of the GNU General Public License as published by
nkeynes@94
    11
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@94
    12
 * (at your option) any later version.
nkeynes@94
    13
 *
nkeynes@94
    14
 * This program is distributed in the hope that it will be useful,
nkeynes@94
    15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@94
    16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@94
    17
 * GNU General Public License for more details.
nkeynes@94
    18
 */
nkeynes@94
    19
nkeynes@94
    20
#include <gdk/gdkx.h>
nkeynes@485
    21
#include <gdk/gdkkeysyms.h>
nkeynes@94
    22
#include <stdint.h>
nkeynes@180
    23
#include "dream.h"
nkeynes@144
    24
#include "display.h"
nkeynes@94
    25
#include "drivers/video_x11.h"
nkeynes@481
    26
#include "drivers/gl_common.h"
nkeynes@435
    27
#include "gui/gtkui.h"
nkeynes@94
    28
nkeynes@436
    29
static GtkWidget *video_win = NULL;
nkeynes@436
    30
int video_width = 640;
nkeynes@436
    31
int video_height = 480;
nkeynes@94
    32
nkeynes@352
    33
gboolean video_gtk_init();
nkeynes@352
    34
void video_gtk_shutdown();
nkeynes@144
    35
uint16_t video_gtk_resolve_keysym( const gchar *keysym );
nkeynes@94
    36
nkeynes@370
    37
struct display_driver display_gtk_driver = { "gtk", video_gtk_init, video_gtk_shutdown,
nkeynes@352
    38
					     video_gtk_resolve_keysym,
nkeynes@352
    39
					     NULL, NULL, NULL, NULL, NULL, NULL, NULL };
nkeynes@449
    40
nkeynes@449
    41
/**
nkeynes@449
    42
 * Extract the keyval of the key event if no modifier keys were pressed -
nkeynes@449
    43
 * in other words get the keyval of the key by itself. The other way around
nkeynes@449
    44
 * would be to use the hardware keysyms directly rather than the keyvals,
nkeynes@449
    45
 * but the mapping looks to be messier.
nkeynes@449
    46
 */
nkeynes@449
    47
uint16_t video_gtk_unmodified_keyval( GdkEventKey *event )
nkeynes@449
    48
{
nkeynes@449
    49
    GdkKeymap *keymap = gdk_keymap_get_default();
nkeynes@449
    50
    guint keyval;
nkeynes@449
    51
    
nkeynes@449
    52
    gdk_keymap_translate_keyboard_state( keymap, event->hardware_keycode, 0, 0, &keyval, 
nkeynes@449
    53
					 NULL, NULL, NULL );
nkeynes@449
    54
    return keyval;
nkeynes@449
    55
}
nkeynes@144
    56
nkeynes@144
    57
gboolean video_gtk_keydown_callback(GtkWidget       *widget,
nkeynes@144
    58
				     GdkEventKey     *event,
nkeynes@144
    59
				     gpointer         user_data)
nkeynes@144
    60
{
nkeynes@449
    61
    input_event_keydown( video_gtk_unmodified_keyval(event) );
nkeynes@449
    62
    return TRUE;
nkeynes@449
    63
}
nkeynes@449
    64
nkeynes@449
    65
gboolean video_gtk_keyup_callback(GtkWidget       *widget,
nkeynes@449
    66
				  GdkEventKey     *event,
nkeynes@449
    67
				  gpointer         user_data)
nkeynes@449
    68
{
nkeynes@449
    69
    input_event_keyup( video_gtk_unmodified_keyval(event) );
nkeynes@424
    70
    return TRUE;
nkeynes@144
    71
}
nkeynes@144
    72
nkeynes@144
    73
uint16_t video_gtk_resolve_keysym( const gchar *keysym )
nkeynes@144
    74
{
nkeynes@144
    75
    int val = gdk_keyval_from_name( keysym );
nkeynes@144
    76
    if( val == GDK_VoidSymbol )
nkeynes@144
    77
	return 0;
nkeynes@144
    78
    return (uint16_t)val;
nkeynes@144
    79
}
nkeynes@144
    80
nkeynes@435
    81
gboolean video_gtk_expose_callback(GtkWidget *widget, GdkEventExpose *event, gpointer data )
nkeynes@435
    82
{
nkeynes@477
    83
    gl_fbo_detach();
nkeynes@443
    84
    gl_redisplay_last();
nkeynes@443
    85
    return TRUE;
nkeynes@435
    86
}
nkeynes@435
    87
nkeynes@436
    88
gboolean video_gtk_resize_callback(GtkWidget *widget, GdkEventConfigure *event, gpointer data )
nkeynes@436
    89
{
nkeynes@436
    90
    video_width = event->width;
nkeynes@436
    91
    video_height = event->height;
nkeynes@477
    92
    gl_fbo_detach();
nkeynes@443
    93
    gl_redisplay_last();
nkeynes@443
    94
    return TRUE;
nkeynes@436
    95
}
nkeynes@436
    96
nkeynes@352
    97
gboolean video_gtk_init()
nkeynes@94
    98
{
nkeynes@435
    99
    video_win = gtk_gui_get_renderarea();
nkeynes@435
   100
nkeynes@352
   101
    g_signal_connect( video_win, "key_press_event", 
nkeynes@352
   102
		      G_CALLBACK(video_gtk_keydown_callback), NULL );
nkeynes@352
   103
    g_signal_connect( video_win, "key_release_event", 
nkeynes@352
   104
		      G_CALLBACK(video_gtk_keyup_callback), NULL );
nkeynes@435
   105
    g_signal_connect( video_win, "expose_event",
nkeynes@435
   106
		      G_CALLBACK(video_gtk_expose_callback), NULL );
nkeynes@436
   107
    g_signal_connect( video_win, "configure_event",
nkeynes@436
   108
		      G_CALLBACK(video_gtk_resize_callback), NULL );
nkeynes@435
   109
    gtk_widget_add_events( video_win, 
nkeynes@352
   110
			   GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK |
nkeynes@352
   111
			   GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK );
nkeynes@443
   112
    gtk_widget_set_double_buffered( video_win, FALSE );
nkeynes@436
   113
    video_width = video_win->allocation.width;
nkeynes@436
   114
    video_height = video_win->allocation.height;
nkeynes@370
   115
    return video_glx_init( gdk_x11_display_get_xdisplay( gtk_widget_get_display(GTK_WIDGET(video_win))),
nkeynes@436
   116
			   gdk_x11_screen_get_xscreen( gtk_widget_get_screen(GTK_WIDGET(video_win))),
nkeynes@436
   117
			   GDK_WINDOW_XWINDOW( GTK_WIDGET(video_win)->window ),
nkeynes@436
   118
			   video_width, video_height, &display_gtk_driver );
nkeynes@94
   119
}
nkeynes@94
   120
nkeynes@352
   121
void video_gtk_shutdown()
nkeynes@352
   122
{
nkeynes@370
   123
    video_glx_shutdown();
nkeynes@370
   124
    gtk_widget_destroy( GTK_WIDGET(video_win) );
nkeynes@352
   125
nkeynes@94
   126
}
nkeynes@94
   127
.