1
0
Fork 0
forked from Miroirs/x49gp

Compare commits

..

No commits in common. "7d313c91f9e4c5416c00f863df4924fb2a70c894" and "0e0e1d646cbd96d6d3dc97b9e2e40df2b409078f" have entirely different histories.

View file

@ -651,9 +651,6 @@ char* css_global = "window {"
" margin-left: 15px;"
" margin-right: 15px;"
"}"
"button.key-down {"
" border-color: #080808;"
"}"
"button.menu {"
" background-color: #a9a9a9;"
"}"
@ -734,28 +731,6 @@ static inline int _tiny_text_width( const char* text )
return strlen( stripped_text ) * TINY_TEXT_WIDTH;
}
static bool ui_press_button( x49gp_ui_button_t* button, x49gp_ui_button_t* cause, bool hold )
{
x49gp_t* x49gp = button->x49gp;
const x49gp_ui_key_t* key = button->key;
x49gp_ui_t* ui = x49gp->ui;
if ( button->down )
return false;
button->down = true;
button->hold = hold;
if ( !button->hold )
ui->buttons_down++;
gtk_style_context_add_class( gtk_widget_get_style_context( button->button ), "key-down" );
x49gpng_release_key( x49gp, key );
return true;
}
static void ui_release_button( x49gp_ui_button_t* button, x49gp_ui_button_t* cause )
{
x49gp_t* x49gp = button->x49gp;
@ -764,8 +739,6 @@ static void ui_release_button( x49gp_ui_button_t* button, x49gp_ui_button_t* cau
button->down = false;
button->hold = false;
gtk_style_context_remove_class( gtk_widget_get_style_context( button->button ), "key-down" );
x49gpng_release_key( x49gp, key );
}
@ -789,12 +762,29 @@ static gboolean react_to_button_press( GtkWidget* widget, GdkEventButton* event,
x49gp_ui_button_t* button = user_data;
const x49gp_ui_key_t* key = button->key;
x49gp_t* x49gp = button->x49gp;
x49gp_ui_t* ui = x49gp->ui;
if ( event->type != GDK_BUTTON_PRESS || event->button > 3 )
if ( event->type != GDK_BUTTON_PRESS )
return false;
if ( !ui_press_button( button, button, event->button == 3 ) )
switch ( event->button ) {
case 1:
ui->buttons_down++;
if ( button->down )
return false;
button->down = true;
break;
case 2:
case 3:
button->hold = true;
if ( button->down )
return false;
button->down = true;
break;
default:
return true;
}
x49gpng_press_key( x49gp, key );
@ -911,16 +901,16 @@ static gboolean react_to_key_event( GtkWidget* widget, GdkEventKey* event, gpoin
{
x49gp_t* x49gp = user_data;
x49gp_ui_t* ui = x49gp->ui;
int index;
guint keyval;
/* We want to know the keyval as interpreted without modifiers. */
/* However, there is one modifier we do care about: NumLock, */
/* which normally is represented by MOD2. */
guint keyval;
if ( !gdk_keymap_translate_keyboard_state( gdk_keymap_get_for_display( gdk_display_get_default() ), event->hardware_keycode,
event->state & GDK_MOD2_MASK, event->group, &keyval, NULL, NULL, NULL ) )
return false;
int index;
switch ( keyval ) {
case GDK_KEY_a:
case GDK_KEY_F1:
@ -1194,7 +1184,7 @@ static gboolean react_to_key_event( GtkWidget* widget, GdkEventKey* event, gpoin
return true;
}
static gboolean react_to_display_click( GtkWidget* widget, GdkEventButton* event, gpointer user_data )
static gboolean react_to_window_click( GtkWidget* widget, GdkEventButton* event, gpointer user_data )
{
gdk_window_focus( gtk_widget_get_window( widget ), event->time );
gdk_window_raise( gtk_widget_get_window( widget ) );
@ -1211,13 +1201,13 @@ static gboolean react_to_display_click( GtkWidget* widget, GdkEventButton* event
switch ( event->button ) {
case 1: // left click
gdk_window_begin_move_drag( gtk_widget_get_window( ui->window ), event->button, event->x_root, event->y_root, event->time );
break;
case 2: // middle click
GtkClipboard* clip = gtk_clipboard_get( GDK_SELECTION_CLIPBOARD );
gchar* text = gtk_clipboard_wait_for_text( clip );
fprintf( stderr, "clipboard: %s\n", text );
gdk_window_begin_move_drag( gtk_widget_get_window( widget ), event->button, event->x_root, event->y_root, event->time );
break;
/* case 2: // middle click */
/* GtkClipboard* clip = gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ); */
/* gchar* text = gtk_clipboard_wait_for_text( clip ); */
/* fprintf( stderr, "clipboard: %s\n", text ); */
/* break; */
case 3: // right click
gtk_menu_popup_at_pointer( GTK_MENU( ui->menu ), NULL );
return true;
@ -1437,7 +1427,7 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
g_signal_connect( G_OBJECT( ui->window ), "focus-out-event", G_CALLBACK( react_to_focus_lost ), x49gp );
g_signal_connect( G_OBJECT( ui->window ), "key-press-event", G_CALLBACK( react_to_key_event ), x49gp );
g_signal_connect( G_OBJECT( ui->window ), "key-release-event", G_CALLBACK( react_to_key_event ), x49gp );
/* g_signal_connect( G_OBJECT( ui->window ), "button-press-event", G_CALLBACK( react_to_display_click ), x49gp ); */
g_signal_connect( G_OBJECT( ui->window ), "button-press-event", G_CALLBACK( react_to_window_click ), x49gp );
g_signal_connect_swapped( G_OBJECT( ui->window ), "delete-event", G_CALLBACK( do_quit ), x49gp );
g_signal_connect_swapped( G_OBJECT( ui->window ), "destroy", G_CALLBACK( do_quit ), x49gp );
gtk_widget_add_events( ui->window, GDK_FOCUS_CHANGE_MASK | GDK_BUTTON_PRESS_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK );
@ -1468,11 +1458,7 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
gtk_container_add( GTK_CONTAINER( display_container ), annunciators_container );
gtk_container_add( GTK_CONTAINER( display_container ), lcd_container );
GtkWidget* display_container_event_box = gtk_event_box_new();
g_signal_connect( G_OBJECT( display_container_event_box ), "button-press-event", G_CALLBACK( react_to_display_click ), x49gp );
gtk_container_add( GTK_CONTAINER( display_container_event_box ), display_container );
gtk_container_add( GTK_CONTAINER( window_container ), display_container_event_box );
gtk_container_add( GTK_CONTAINER( window_container ), display_container );
// keyboard
GtkWidget* keyboard_container = gtk_box_new( GTK_ORIENTATION_VERTICAL, 0 );