gtk3 to gtk4: don't access GdkEvent fields directly

This commit is contained in:
NunoSempere 2024-03-12 15:10:20 -03:00
parent 4663cb3a70
commit d9d18bf7f3
4 changed files with 15 additions and 8 deletions

View File

@ -75,6 +75,7 @@ typedef enum {
#define SFT 1 << 0 #define SFT 1 << 0
#define CTRL 1 << 2 #define CTRL 1 << 2
#define ALT 1 << 3 #define ALT 1 << 3
// reference: <https://github.com/GNOME/gtk/blob/7ea7d5c3906ccd231b04654101bb742f157d82f6/gdk/gdkenums.h#L140>
static struct { static struct {
unsigned mod; unsigned mod;

View File

@ -1,8 +1,8 @@
# C compiler # C compiler
CC=gcc # other options: tcc, clang, zig cc CC=gcc # other options: tcc, clang, zig cc
WARNINGS=-Wall WARNINGS=-Wall
DEBUG= #'-g' DEBUG= #'-g'
COMPILETIME_DEPRECATION_WARNINGS=#-DGDK_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED # turns out that webkit2gtk-4.1 is using some deprecated stuff, lol
OPTIMIZED_SOME=-O3 OPTIMIZED_SOME=-O3
OPTIMIZED_MORE=-Ofast -march=native -funit-at-a-time -flto # binary will not be compatible with other computers, but may be much faster OPTIMIZED_MORE=-Ofast -march=native -funit-at-a-time -flto # binary will not be compatible with other computers, but may be much faster
@ -29,12 +29,12 @@ STYLE_BLUEPRINT=webkit
FORMATTER=clang-format -i -style=$(STYLE_BLUEPRINT) FORMATTER=clang-format -i -style=$(STYLE_BLUEPRINT)
# Change hardcoded paths when building # Change hardcoded paths when building
## Cache ## Data dirs
USER=`whoami` USER=`whoami`
DEFAULT_DATA_DIR=/home/nuno/.cache/rose DEFAULT_DATA_DIR=/home/nuno/.cache/rose
CURRENT_DATA_DIR=/home/$(USER)/.cache/rose CURRENT_DATA_DIR=/home/$(USER)/.cache/rose
## dir ## dir
DEFAULT_DIR=/home/loki/Documents/core/software/fresh/C/rose-browser/rosenrot DEFAULT_DIR=/home/nuno/Documents/workspace/rosenrot
CURRENT_DIR=`pwd` CURRENT_DIR=`pwd`
build: $(SRC) $(PLUGINS) $(CONFIG) build: $(SRC) $(PLUGINS) $(CONFIG)
@ -51,7 +51,7 @@ build: $(SRC) $(PLUGINS) $(CONFIG)
sed -i "s|$(DEFAULT_DIR)|$(CURRENT_DIR)|g" {} + sed -i "s|$(DEFAULT_DIR)|$(CURRENT_DIR)|g" {} +
# Compile rosenrot # Compile rosenrot
GIO_MODULE_DIR=/usr/lib/x86_64-linux-gnu/gio/modules/ GIO_MODULE_DIR=/usr/lib/x86_64-linux-gnu/gio/modules/
$(CC) $(WARNINGS) $(OPTIMIZED_SOME) $(DEBUG) $(INCS) $(PLUGINS) $(SRC) -o rose $(LIBS) $(ADBLOCK) $(CC) $(WARNINGS) $(OPTIMIZED_SOME) $(DEBUG) $(INCS) $(PLUGINS) $(SRC) $(COMPILETIME_DEPRECATION_WARNINGS) -o rose $(LIBS) $(ADBLOCK)
fast: $(SRC) $(PLUGINS) $(CONFIG) fast: $(SRC) $(PLUGINS) $(CONFIG)
rm -f *.gcda rm -f *.gcda
@ -92,7 +92,7 @@ format: $(SRC) $(PLUGINS)
$(FORMATTER) $(SRC) $(PLUGINS) $(rose.h) $(FORMATTER) $(SRC) $(PLUGINS) $(rose.h)
diagnose_deprecations: diagnose_deprecations:
make && G_ENABLE_DIAGNOSTIC=1 ./rose G_ENABLE_DIAGNOSTIC=1 ./rose
view-gtk3-version: view-gtk3-version:
dpkg -l libgtk-3-0 dpkg -l libgtk-3-0

BIN
rose

Binary file not shown.

12
rose.c
View File

@ -381,15 +381,21 @@ int handle_signal_keypress(void* self, GdkEvent* event, GtkNotebook* notebook)
{ {
(void)self; (void)self;
guint event_keyval = 0;
gdk_event_get_keyval(event, &event_keyval);
GdkModifierType event_state = 0;
gdk_event_get_state(event, &event_state);
/* /*
printf("Keypress state: %d\n", event->key.state); printf("Keypress state: %d\n", event_state);
if(event->key.state & GDK_CONTROL_MASK){ if(event->key.state & GDK_CONTROL_MASK){
printf("Keypress state is: CONTROL\n"); printf("Keypress state is: CONTROL\n");
} }
printf("Keypress value: %d\n", event->key.keyval); printf("Keypress value: %d\n", event_keyval);
*/ */
for (int i = 0; i < sizeof(shortcut) / sizeof(shortcut[0]); i++) for (int i = 0; i < sizeof(shortcut) / sizeof(shortcut[0]); i++)
if ((event->key.state & shortcut[i].mod || shortcut[i].mod == 0x0) && event->key.keyval == shortcut[i].key) if ((event_state & shortcut[i].mod || shortcut[i].mod == 0x0) && event_keyval == shortcut[i].key)
return handle_shortcut(shortcut[i].id, notebook); return handle_shortcut(shortcut[i].id, notebook);
/* /*
If I wanted to bind button presses, like the extra button in the mouse, If I wanted to bind button presses, like the extra button in the mouse,