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 443:1163eb5c0590
prev436:e8c461d2545e
next449:21440948c684
author nkeynes
date Sat Oct 13 04:01:02 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Add ability to track the last displayed buffer, and handle expose/resize
events appropriately
file annotate diff log raw
nkeynes@94
     1
/**
nkeynes@443
     2
 * $Id: video_gtk.c,v 1.15 2007-10-13 04:01:02 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 <gnome.h>
nkeynes@94
    21
#include <gdk/gdkx.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@435
    26
#include "gui/gtkui.h"
nkeynes@94
    27
nkeynes@436
    28
static GtkWidget *video_win = NULL;
nkeynes@436
    29
int video_width = 640;
nkeynes@436
    30
int video_height = 480;
nkeynes@94
    31
nkeynes@352
    32
gboolean video_gtk_init();
nkeynes@352
    33
void video_gtk_shutdown();
nkeynes@144
    34
uint16_t video_gtk_resolve_keysym( const gchar *keysym );
nkeynes@94
    35
nkeynes@370
    36
struct display_driver display_gtk_driver = { "gtk", video_gtk_init, video_gtk_shutdown,
nkeynes@352
    37
					     video_gtk_resolve_keysym,
nkeynes@352
    38
					     NULL, NULL, NULL, NULL, NULL, NULL, NULL };
nkeynes@352
    39
					     
nkeynes@144
    40
nkeynes@144
    41
gboolean video_gtk_keydown_callback(GtkWidget       *widget,
nkeynes@144
    42
				     GdkEventKey     *event,
nkeynes@144
    43
				     gpointer         user_data)
nkeynes@144
    44
{
nkeynes@144
    45
    input_event_keydown( event->keyval );
nkeynes@424
    46
    return TRUE;
nkeynes@144
    47
}
nkeynes@144
    48
nkeynes@144
    49
uint16_t video_gtk_resolve_keysym( const gchar *keysym )
nkeynes@144
    50
{
nkeynes@144
    51
    int val = gdk_keyval_from_name( keysym );
nkeynes@144
    52
    if( val == GDK_VoidSymbol )
nkeynes@144
    53
	return 0;
nkeynes@144
    54
    return (uint16_t)val;
nkeynes@144
    55
}
nkeynes@144
    56
nkeynes@144
    57
gboolean video_gtk_keyup_callback(GtkWidget       *widget,
nkeynes@144
    58
				  GdkEventKey     *event,
nkeynes@144
    59
				  gpointer         user_data)
nkeynes@144
    60
{
nkeynes@144
    61
    input_event_keyup( event->keyval );
nkeynes@424
    62
    return TRUE;
nkeynes@144
    63
}
nkeynes@94
    64
nkeynes@435
    65
gboolean video_gtk_expose_callback(GtkWidget *widget, GdkEventExpose *event, gpointer data )
nkeynes@435
    66
{
nkeynes@443
    67
    gl_redisplay_last();
nkeynes@443
    68
    return TRUE;
nkeynes@435
    69
}
nkeynes@435
    70
nkeynes@436
    71
gboolean video_gtk_resize_callback(GtkWidget *widget, GdkEventConfigure *event, gpointer data )
nkeynes@436
    72
{
nkeynes@436
    73
    video_width = event->width;
nkeynes@436
    74
    video_height = event->height;
nkeynes@443
    75
    gl_redisplay_last();
nkeynes@443
    76
    return TRUE;
nkeynes@436
    77
}
nkeynes@436
    78
nkeynes@352
    79
gboolean video_gtk_init()
nkeynes@94
    80
{
nkeynes@435
    81
    video_win = gtk_gui_get_renderarea();
nkeynes@435
    82
nkeynes@352
    83
    g_signal_connect( video_win, "key_press_event", 
nkeynes@352
    84
		      G_CALLBACK(video_gtk_keydown_callback), NULL );
nkeynes@352
    85
    g_signal_connect( video_win, "key_release_event", 
nkeynes@352
    86
		      G_CALLBACK(video_gtk_keyup_callback), NULL );
nkeynes@435
    87
    g_signal_connect( video_win, "expose_event",
nkeynes@435
    88
		      G_CALLBACK(video_gtk_expose_callback), NULL );
nkeynes@436
    89
    g_signal_connect( video_win, "configure_event",
nkeynes@436
    90
		      G_CALLBACK(video_gtk_resize_callback), NULL );
nkeynes@435
    91
    gtk_widget_add_events( video_win, 
nkeynes@352
    92
			   GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK |
nkeynes@352
    93
			   GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK );
nkeynes@443
    94
    gtk_widget_set_double_buffered( video_win, FALSE );
nkeynes@436
    95
    video_width = video_win->allocation.width;
nkeynes@436
    96
    video_height = video_win->allocation.height;
nkeynes@370
    97
    return video_glx_init( gdk_x11_display_get_xdisplay( gtk_widget_get_display(GTK_WIDGET(video_win))),
nkeynes@436
    98
			   gdk_x11_screen_get_xscreen( gtk_widget_get_screen(GTK_WIDGET(video_win))),
nkeynes@436
    99
			   GDK_WINDOW_XWINDOW( GTK_WIDGET(video_win)->window ),
nkeynes@436
   100
			   video_width, video_height, &display_gtk_driver );
nkeynes@94
   101
}
nkeynes@94
   102
nkeynes@352
   103
void video_gtk_shutdown()
nkeynes@352
   104
{
nkeynes@370
   105
    video_glx_shutdown();
nkeynes@370
   106
    gtk_widget_destroy( GTK_WIDGET(video_win) );
nkeynes@352
   107
nkeynes@94
   108
}
nkeynes@94
   109
.