1
0
Fork 0
forked from Miroirs/x49gp

Compare commits

...

3 commits

Author SHA1 Message Date
Gwenhael Le Moine
af2ef94142
refactor changing key state and a second right-click unhold a held key 2024-11-14 09:50:43 +01:00
Gwenhael Le Moine
53bd74a1ab
don't release all keys when losing focus 2024-11-14 09:49:53 +01:00
Gwenhael Le Moine
2ac5cad77b
remove unnecessary code 2024-11-14 09:49:40 +01:00

View file

@ -6,7 +6,6 @@
#include <string.h> #include <string.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/times.h> #include <sys/times.h>
#include <math.h>
#include <errno.h> #include <errno.h>
#include <arpa/inet.h> /* For ntohl() */ #include <arpa/inet.h> /* For ntohl() */
@ -43,17 +42,14 @@
#define KB_HEIGHT_SMALL_KEYS ( ( int )( 2 * opt.font_size ) ) #define KB_HEIGHT_SMALL_KEYS ( ( int )( 2 * opt.font_size ) )
#define KB_HEIGHT_BIG_KEYS ( ( int )( 2.5 * opt.font_size ) ) #define KB_HEIGHT_BIG_KEYS ( ( int )( 2.5 * opt.font_size ) )
#define KB_SPACING_KEYS ( ( int )( 0.5 * TINY_TEXT_WIDTH ) ) #define KB_SPACING_KEYS ( opt.display_scale )
#define KB_COLUMN_WIDTH_6_KEYS ( KB_WIDTH_6_KEYS + KB_SPACING_KEYS )
#define KB_COLUMN_WIDTH_5_KEYS ( KB_WIDTH_5_KEYS + KB_SPACING_KEYS )
#define ANNUNCIATOR_WIDTH 16 #define ANNUNCIATOR_WIDTH 16
#define ANNUNCIATOR_HEIGHT 16 #define ANNUNCIATOR_HEIGHT 16
#define ANNUNCIATORS_HEIGHT ANNUNCIATOR_HEIGHT #define ANNUNCIATORS_HEIGHT ANNUNCIATOR_HEIGHT
#define LCD_PIXEL_SCALE opt.display_scale #define LCD_WIDTH ( 131 * opt.display_scale )
#define LCD_WIDTH ( 131 * LCD_PIXEL_SCALE ) #define LCD_HEIGHT ( 80 * opt.display_scale )
#define LCD_HEIGHT ( 80 * LCD_PIXEL_SCALE )
#define WINDOW_WIDTH ( 384 ) #define WINDOW_WIDTH ( 384 )
@ -710,21 +706,15 @@ char* css_global = "window {"
/* functions */ /* functions */
/*************/ /*************/
static void x49gpng_press_key( x49gp_t* x49gp, const x49gp_ui_key_t* key ) static inline void x49gpng_set_key_state( x49gp_t* x49gp, const x49gp_ui_key_t* key, bool state )
{ {
if ( key->rowbit ) if ( key->rowbit )
s3c2410_io_port_g_update( x49gp, key->column, key->row, key->columnbit, key->rowbit, 1 ); s3c2410_io_port_g_update( x49gp, key->column, key->row, key->columnbit, key->rowbit, state );
else else
s3c2410_io_port_f_set_bit( x49gp, key->eint, 1 ); s3c2410_io_port_f_set_bit( x49gp, key->eint, state );
}
static void x49gpng_release_key( x49gp_t* x49gp, const x49gp_ui_key_t* key )
{
if ( key->rowbit )
s3c2410_io_port_g_update( x49gp, key->column, key->row, key->columnbit, key->rowbit, 0 );
else
s3c2410_io_port_f_set_bit( x49gp, key->eint, 0 );
} }
#define X49GPNG_PRESS_KEY( x49gp, key ) x49gpng_set_key_state( x49gp, key, true )
#define X49GPNG_RELEASE_KEY( x49gp, key ) x49gpng_set_key_state( x49gp, key, false )
static inline int _tiny_text_width( const char* text ) static inline int _tiny_text_width( const char* text )
{ {
@ -734,32 +724,6 @@ static inline int _tiny_text_width( const char* text )
return strlen( stripped_text ) * TINY_TEXT_WIDTH; 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++;
#if GTK_MAJOR_VERSION == 4
gtk_widget_add_css_class( button->button, "key-down" );
#else
gtk_style_context_add_class( gtk_widget_get_style_context( button->button ), "key-down" );
#endif
x49gpng_release_key( x49gp, key );
return true;
}
static void ui_release_button( x49gp_ui_button_t* button, x49gp_ui_button_t* cause ) static void ui_release_button( x49gp_ui_button_t* button, x49gp_ui_button_t* cause )
{ {
x49gp_t* x49gp = button->x49gp; x49gp_t* x49gp = button->x49gp;
@ -774,7 +738,7 @@ static void ui_release_button( x49gp_ui_button_t* button, x49gp_ui_button_t* cau
gtk_style_context_remove_class( gtk_widget_get_style_context( button->button ), "key-down" ); gtk_style_context_remove_class( gtk_widget_get_style_context( button->button ), "key-down" );
#endif #endif
x49gpng_release_key( x49gp, key ); X49GPNG_RELEASE_KEY( x49gp, key );
} }
static void ui_release_all_buttons( x49gp_t* x49gp, x49gp_ui_button_t* cause ) static void ui_release_all_buttons( x49gp_t* x49gp, x49gp_ui_button_t* cause )
@ -792,6 +756,37 @@ static void ui_release_all_buttons( x49gp_t* x49gp, x49gp_ui_button_t* cause )
} }
} }
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 ) {
if ( button->hold && hold ) {
ui_release_button( button, cause );
return true;
} else
return false;
}
button->down = true;
button->hold = hold;
if ( !button->hold )
ui->buttons_down++;
#if GTK_MAJOR_VERSION == 4
gtk_widget_add_css_class( button->button, "key-down" );
#else
gtk_style_context_add_class( gtk_widget_get_style_context( button->button ), "key-down" );
#endif
X49GPNG_RELEASE_KEY( x49gp, key );
return true;
}
static gboolean react_to_button_press( GtkWidget* widget, GdkEventButton* event, gpointer user_data ) static gboolean react_to_button_press( GtkWidget* widget, GdkEventButton* event, gpointer user_data )
{ {
x49gp_ui_button_t* button = user_data; x49gp_ui_button_t* button = user_data;
@ -804,7 +799,7 @@ static gboolean react_to_button_press( GtkWidget* widget, GdkEventButton* event,
if ( !ui_press_button( button, button, event->button == 3 ) ) if ( !ui_press_button( button, button, event->button == 3 ) )
return false; return false;
x49gpng_press_key( x49gp, key ); X49GPNG_PRESS_KEY( x49gp, key );
return false; return false;
} }
@ -845,20 +840,6 @@ static gboolean react_to_button_leave( GtkWidget* widget, GdkEventCrossing* even
return true; return true;
} }
static gboolean react_to_focus_lost( GtkWidget* widget, GdkEventFocus* event, gpointer user_data )
{
x49gp_t* x49gp = user_data;
x49gp_ui_t* ui = x49gp->ui;
if ( event->type != GDK_FOCUS_CHANGE )
return false;
ui->buttons_down = 0;
ui_release_all_buttons( x49gp, NULL );
return false;
}
static void ui_open_file_dialog( x49gp_t* x49gp, const char* prompt, GtkFileChooserAction action, char** filename ) static void ui_open_file_dialog( x49gp_t* x49gp, const char* prompt, GtkFileChooserAction action, char** filename )
{ {
x49gp_ui_t* ui = x49gp->ui; x49gp_ui_t* ui = x49gp->ui;
@ -1450,7 +1431,6 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
GtkWidget* window_container = gtk_box_new( GTK_ORIENTATION_VERTICAL, 0 ); GtkWidget* window_container = gtk_box_new( GTK_ORIENTATION_VERTICAL, 0 );
gtk_container_add( GTK_CONTAINER( ui->window ), window_container ); gtk_container_add( GTK_CONTAINER( ui->window ), window_container );
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-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 ), "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_display_click ), x49gp ); */
@ -1683,9 +1663,9 @@ void gui_update_lcd( x49gp_t* x49gp )
gtk_widget_set_opacity( ui->ui_ann_busy, x49gp_get_pixel_color( lcd, 131, 5 ) ); gtk_widget_set_opacity( ui->ui_ann_busy, x49gp_get_pixel_color( lcd, 131, 5 ) );
gtk_widget_set_opacity( ui->ui_ann_io, x49gp_get_pixel_color( lcd, 131, 0 ) ); gtk_widget_set_opacity( ui->ui_ann_io, x49gp_get_pixel_color( lcd, 131, 0 ) );
for ( int y = 0; y < ( LCD_HEIGHT / LCD_PIXEL_SCALE ); y++ ) for ( int y = 0; y < ( LCD_HEIGHT / opt.display_scale ); y++ )
for ( int x = 0; x < ( LCD_WIDTH / LCD_PIXEL_SCALE ); x++ ) for ( int x = 0; x < ( LCD_WIDTH / opt.display_scale ); x++ )
_draw_pixel( ui->lcd_surface, LCD_PIXEL_SCALE * x, LCD_PIXEL_SCALE * y, LCD_PIXEL_SCALE, LCD_PIXEL_SCALE, _draw_pixel( ui->lcd_surface, opt.display_scale * x, opt.display_scale * y, opt.display_scale, opt.display_scale,
&( ui->colors[ UI_COLOR_GRAYSCALE_0 + x49gp_get_pixel_color( lcd, x, y ) ] ) ); &( ui->colors[ UI_COLOR_GRAYSCALE_0 + x49gp_get_pixel_color( lcd, x, y ) ] ) );
} }
@ -1719,35 +1699,6 @@ int gui_init( x49gp_t* x49gp )
{ {
x49gp_module_t* module; x49gp_module_t* module;
if ( opt.verbose ) {
fprintf( stderr,
"\n FONT_SIZE_KEY = %i\n"
" FONT_SIZE_SYMBOL = %i\n"
" FONT_SIZE_NUMBER = %i\n"
" FONT_SIZE_TINY = %i\n"
" TINY_TEXT_HEIGHT = %i\n"
" TINY_TEXT_WIDTH = %i\n"
" KB_WIDTH_6_KEYS = %i\n"
" KB_WIDTH_5_KEYS = %i\n"
" KB_HEIGHT_MENU_KEYS = %i\n"
" KB_HEIGHT_SMALL_KEYS = %i\n"
" KB_HEIGHT_BIG_KEYS = %i\n"
" KB_SPACING_KEYS = %i\n"
" KB_COLUMN_WIDTH_6_KEYS = %i\n"
" KB_COLUMN_WIDTH_5_KEYS = %i\n"
" ANNUNCIATOR_WIDTH = %i\n"
" ANNUNCIATOR_HEIGHT = %i\n"
" ANNUNCIATORS_HEIGHT = %i\n"
" LCD_PIXEL_SCALE = %i\n"
" LCD_WIDTH = %i\n"
" LCD_HEIGHT = %i\n"
" WINDOW_WIDTH = %i\n",
FONT_SIZE_KEY, FONT_SIZE_SYMBOL, FONT_SIZE_NUMBER, FONT_SIZE_TINY, TINY_TEXT_HEIGHT, TINY_TEXT_WIDTH, KB_WIDTH_6_KEYS,
KB_WIDTH_5_KEYS, KB_HEIGHT_MENU_KEYS, KB_HEIGHT_SMALL_KEYS, KB_HEIGHT_BIG_KEYS, KB_SPACING_KEYS, KB_COLUMN_WIDTH_6_KEYS,
KB_COLUMN_WIDTH_5_KEYS, ANNUNCIATOR_WIDTH, ANNUNCIATOR_HEIGHT, ANNUNCIATORS_HEIGHT, LCD_PIXEL_SCALE, LCD_WIDTH, LCD_HEIGHT,
WINDOW_WIDTH );
}
if ( x49gp_module_init( x49gp, "gui", ui_init, ui_exit, ui_reset, ui_load, ui_save, NULL, &module ) ) if ( x49gp_module_init( x49gp, "gui", ui_init, ui_exit, ui_reset, ui_load, ui_save, NULL, &module ) )
return -1; return -1;