From 2d3a6703f8a71938565454dc2c12177083fefc7f Mon Sep 17 00:00:00 2001 From: Lev Babiev Date: Mon, 23 Dec 2024 08:00:47 +0000 Subject: [PATCH] deprecate action_t --- src/action.c | 56 +++++------------------------------------- src/action.h | 20 +++------------ src/config.h | 2 +- src/config/layout.c | 4 +-- src/config/toplevel.c | 27 ++++++-------------- src/gui/basewidget.c | 31 +++++++++++------------ src/gui/basewidget.h | 6 ++--- src/gui/menu.c | 6 ++--- src/gui/menu.h | 2 +- src/gui/pageritem.c | 2 +- src/gui/taskbar.c | 5 ++-- src/gui/taskbaritem.c | 2 +- src/gui/taskbaritem.h | 2 +- src/gui/taskbarpopup.c | 2 +- 14 files changed, 47 insertions(+), 120 deletions(-) diff --git a/src/action.c b/src/action.c index c5bfd29..34a54ed 100644 --- a/src/action.c +++ b/src/action.c @@ -11,7 +11,7 @@ static GHashTable *functions; -void action_function_add ( gchar *name, action_t *action ) +void action_function_add ( gchar *name, GBytes *action ) { if(!functions) functions = g_hash_table_new_full((GHashFunc)str_nhash, @@ -56,7 +56,7 @@ guint16 action_state_build ( GtkWidget *widget, window_t *win ) return state; } -void action_exec ( GtkWidget *widget, action_t *action, +void action_exec ( GtkWidget *widget, GBytes *action, GdkEvent *event, window_t *win, guint16 *istate ) { /* ModuleActionHandlerV1 *ahandler; @@ -65,8 +65,8 @@ void action_exec ( GtkWidget *widget, action_t *action, guint16 state; action_t *caction;*/ - if(action && action->code) - vm_run_action(action->code, widget, event, istate); + if(action) + vm_run_action(action, widget, event, istate); // vm_run_action((gchar *)action->id, action->addr->definition, // action->command->definition, widget, event, action->cond, action->ncond); @@ -139,56 +139,12 @@ void action_exec ( GtkWidget *widget, action_t *action, action->command->cache, action->addr->cache, widget, event, win, &state);*/ } -action_t *action_new ( void ) -{ - action_t *new; - - new = g_malloc0(sizeof(action_t)); -// new->command = expr_cache_new(); -// new->addr = expr_cache_new(); - - return new; -} - -/*action_t *action_dup ( action_t *src ) -{ - action_t *dest; - - if(!src) - return NULL; - - dest = action_new(); - dest->cond = src->cond; - dest->ncond = src->ncond; - dest->id = src->id; - - dest->command->definition = g_strdup(src->command->definition); - dest->command->cache = g_strdup(src->command->cache); - dest->command->eval = src->command->eval; - dest->addr->definition = g_strdup(src->addr->definition); - dest->addr->cache = g_strdup(src->addr->cache); - dest->addr->eval = src->addr->eval; - return dest; -}*/ - -void action_free ( action_t *action, GObject *old ) -{ - if(!action) - return; - -// expr_cache_free(action->command); -// expr_cache_free(action->addr); - g_bytes_unref(action->code); - - g_free(action); -} - -void action_trigger_cb ( action_t *action ) +void action_trigger_cb ( GBytes *action ) { action_exec(NULL, action, NULL, NULL, NULL); } -void action_trigger_add ( action_t *action, gchar *trigger ) +void action_trigger_add ( GBytes *action, gchar *trigger ) { trigger_add(trigger, (GSourceFunc)action_trigger_cb, action); } diff --git a/src/action.h b/src/action.h index b2f75b4..8d3be89 100644 --- a/src/action.h +++ b/src/action.h @@ -2,26 +2,12 @@ #define __ACTION_H__ #include "wintree.h" -#include "vm/expr.h" -typedef struct user_action { - GBytes *code; - guchar cond; - guchar ncond; -// expr_cache_t *command; -// expr_cache_t *addr; -// const gchar *id; -} action_t; - -void action_exec ( GtkWidget *, action_t *, GdkEvent *, window_t *, guint16 *); -action_t *action_new ( void ); -void action_free ( action_t *, GObject *); -action_t *action_dup ( action_t *src ); -void action_function_add ( gchar *, action_t *); +void action_exec ( GtkWidget *, GBytes *, GdkEvent *, window_t *, guint16 *); +void action_function_add ( gchar *, GBytes *); void action_function_exec ( gchar *, GtkWidget *, GdkEvent *, window_t *, guint16 *); -void action_trigger_add ( action_t *action, gchar *trigger ); -action_t *action_trigger_lookup ( const gchar *trigger ); +void action_trigger_add ( GBytes *action, gchar *trigger ); void action_lib_init ( void ); guint16 action_state_build ( GtkWidget *widget, window_t *win ); diff --git a/src/config.h b/src/config.h index f7af3da..c67691e 100644 --- a/src/config.h +++ b/src/config.h @@ -41,7 +41,7 @@ gchar *config_assign_string ( GScanner *scanner, gchar *expr ); gdouble config_assign_number ( GScanner *scanner, gchar *expr ); void *config_assign_tokens ( GScanner *scanner, GHashTable *keys, gchar *err ); GList *config_assign_string_list ( GScanner *scanner ); -gboolean config_action ( GScanner *scanner, action_t **action_dst ); +gboolean config_action ( GScanner *scanner, GBytes **action_dst ); void config_action_finish ( GScanner *scanner ); void config_define ( GScanner *scanner ); gchar *config_get_value ( GScanner *, gchar *, gboolean, gchar **); diff --git a/src/config/layout.c b/src/config/layout.c index b9cebad..d5ee51f 100644 --- a/src/config/layout.c +++ b/src/config/layout.c @@ -75,7 +75,7 @@ gboolean config_action_slot ( GScanner *scanner, gint *slot ) void config_widget_action ( GScanner *scanner, GtkWidget *widget ) { gint slot = 1, mod = 0; - action_t *action = NULL; + GBytes *action = NULL; config_parse_sequence(scanner, SEQ_OPT, '[', NULL, NULL, NULL, @@ -90,7 +90,7 @@ void config_widget_action ( GScanner *scanner, GtkWidget *widget ) if(!scanner->max_parse_errors) base_widget_set_action(widget, slot, mod, action); else if(action) - action_free(action, NULL); + g_bytes_unref(action); } gboolean config_include ( GScanner *scanner, GtkWidget *container ) diff --git a/src/config/toplevel.c b/src/config/toplevel.c index 83a672c..e43dcb2 100644 --- a/src/config/toplevel.c +++ b/src/config/toplevel.c @@ -10,28 +10,17 @@ #include "gui/menu.h" #include "vm/vm.h" -gboolean config_action ( GScanner *scanner, action_t **action_dst ) +gboolean config_action ( GScanner *scanner, GBytes **action_dst ) { - GBytes *code; - action_t *action; + *action_dst = parser_closure_parse(scanner); - if( !(code = parser_closure_parse(scanner)) ) - { - *action_dst = NULL; - return FALSE; - } - - action = action_new(); - action->code = code; - *action_dst = action; - - return TRUE; + return !!*action_dst; } GtkWidget *config_menu_item ( GScanner *scanner ) { gchar *label, *id; - action_t *action; + GBytes *action; GtkWidget *item; config_parse_sequence(scanner, @@ -162,7 +151,7 @@ void config_menu_clear ( GScanner *scanner ) void config_function ( GScanner *scanner ) { gchar *name; - action_t *action; + GBytes *action; config_parse_sequence(scanner, SEQ_REQ, '(', NULL, NULL, "missing '(' after 'function'", @@ -226,7 +215,7 @@ void config_mappid_map ( GScanner *scanner ) void config_trigger_action ( GScanner *scanner ) { gchar *trigger; - action_t *action; + GBytes *action; config_parse_sequence(scanner, SEQ_REQ, G_TOKEN_STRING, NULL, &trigger, @@ -236,8 +225,8 @@ void config_trigger_action ( GScanner *scanner ) SEQ_OPT, ';', NULL, NULL, NULL, SEQ_END); -if(!scanner->max_parse_errors) - action_trigger_add(action, trigger); + if(!scanner->max_parse_errors) + action_trigger_add(action, trigger); } void config_module ( GScanner *scanner ) diff --git a/src/gui/basewidget.c b/src/gui/basewidget.c index dc09e13..1682a31 100644 --- a/src/gui/basewidget.c +++ b/src/gui/basewidget.c @@ -28,7 +28,7 @@ static void base_widget_attachment_free ( base_widget_attachment_t *attach ) if(!attach) return; - action_free(attach->action, NULL); + g_bytes_unref(attach->action); g_free(attach); } @@ -212,19 +212,16 @@ static gboolean base_widget_scroll_event ( GtkWidget *self, static gboolean base_widget_action_exec_impl ( GtkWidget *self, gint slot, GdkEvent *ev ) { - action_t *action; + GBytes *action; if(!base_widget_check_action_slot(self, slot)) return FALSE; - action = base_widget_get_action(self, slot, - base_widget_get_modifiers(self)); - if(!action) - return FALSE; - - action_exec(self, action, (GdkEvent *)ev, - wintree_from_id(wintree_get_focus()), NULL); - return TRUE; + if( (action = base_widget_get_action(self, slot, + base_widget_get_modifiers(self))) ) + action_exec(self, action, (GdkEvent *)ev, + wintree_from_id(wintree_get_focus()), NULL); + return !!action; } static gboolean base_widget_drag_motion( GtkWidget *self, GdkDragContext *ctx, @@ -755,7 +752,7 @@ gint64 base_widget_get_next_poll ( GtkWidget *self ) return priv->next_poll; } -action_t *base_widget_get_action ( GtkWidget *self, gint n, +GBytes *base_widget_get_action ( GtkWidget *self, gint n, GdkModifierType mods ) { BaseWidgetPrivate *priv; @@ -829,7 +826,7 @@ void base_widget_set_css ( GtkWidget *self, gchar *css ) } void base_widget_set_action ( GtkWidget *self, gint slot, - GdkModifierType mods, action_t *action ) + GdkModifierType mods, GBytes *action ) { BaseWidgetPrivate *priv; base_widget_attachment_t *attach; @@ -851,7 +848,7 @@ void base_widget_set_action ( GtkWidget *self, gint slot, if(iter) { attach = iter->data; - action_free(attach->action, NULL); + g_bytes_unref(attach->action); } else { @@ -959,7 +956,7 @@ gpointer base_widget_scanner_thread ( GMainContext *gmc ) void base_widget_autoexec ( GtkWidget *self, gpointer data ) { - action_t *action; + GBytes *action; if(GTK_IS_CONTAINER(self)) gtk_container_forall(GTK_CONTAINER(self), base_widget_autoexec, data); @@ -967,7 +964,7 @@ void base_widget_autoexec ( GtkWidget *self, gpointer data ) if(!IS_BASE_WIDGET(self)) return; - action = base_widget_get_action(self, 0, 0); - if(action) - action_exec(self, action, NULL, wintree_from_id(wintree_get_focus()),NULL); + if( (action = base_widget_get_action(self, 0, 0)) ) + action_exec(self, action, NULL, wintree_from_id(wintree_get_focus()), + NULL); } diff --git a/src/gui/basewidget.h b/src/gui/basewidget.h index b53d9a6..3915ca6 100644 --- a/src/gui/basewidget.h +++ b/src/gui/basewidget.h @@ -66,7 +66,7 @@ struct _BaseWidgetPrivate }; typedef struct _base_widget_attachment { - action_t *action; + GBytes *action; gint event; GdkModifierType mods; } base_widget_attachment_t; @@ -82,7 +82,7 @@ void base_widget_set_trigger ( GtkWidget *self, gchar *trigger ); void base_widget_set_id ( GtkWidget *self, gchar *id ); void base_widget_set_interval ( GtkWidget *self, gint64 interval ); void base_widget_set_state ( GtkWidget *self, guint16 mask, gboolean state ); -void base_widget_set_action ( GtkWidget *, gint, GdkModifierType, action_t *); +void base_widget_set_action ( GtkWidget *, gint, GdkModifierType, GBytes *); void base_widget_set_max_width ( GtkWidget *self, guint x ); void base_widget_set_max_height ( GtkWidget *self, guint x ); gboolean base_widget_update_value ( GtkWidget *self ); @@ -98,7 +98,7 @@ gchar *base_widget_get_id ( GtkWidget *self ); GtkWidget *base_widget_get_child ( GtkWidget *self ); GtkWidget *base_widget_from_id ( gchar *id ); gchar *base_widget_get_value ( GtkWidget *self ); -action_t *base_widget_get_action ( GtkWidget *self, gint, GdkModifierType ); +GBytes *base_widget_get_action ( GtkWidget *self, gint, GdkModifierType ); gpointer base_widget_scanner_thread ( GMainContext *gmc ); void base_widget_set_css ( GtkWidget *widget, gchar *css ); //gboolean base_widget_emit_trigger ( const gchar *trigger ); diff --git a/src/gui/menu.c b/src/gui/menu.c index 376aa98..06ed326 100644 --- a/src/gui/menu.c +++ b/src/gui/menu.c @@ -138,7 +138,7 @@ void menu_popup( GtkWidget *widget, GtkWidget *menu, GdkEvent *event, gtk_menu_popup_at_widget(GTK_MENU(menu), widget, wanchor, manchor, event); } -gboolean menu_action_cb ( GtkWidget *w ,action_t *action ) +gboolean menu_action_cb ( GtkWidget *w, GBytes *action ) { GtkWidget *parent; gpointer wid; @@ -200,7 +200,7 @@ void menu_item_update ( GtkWidget *item, const gchar *label, const gchar *icon ) gtk_label_set_text_with_mnemonic(GTK_LABEL(wlabel), label); } -GtkWidget *menu_item_new ( gchar *label, action_t *action, gchar *id ) +GtkWidget *menu_item_new ( gchar *label, GBytes *action, gchar *id ) { GtkWidget *item; gchar *text, *icon; @@ -220,7 +220,7 @@ GtkWidget *menu_item_new ( gchar *label, action_t *action, gchar *id ) { g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(menu_action_cb), action); - g_object_weak_ref(G_OBJECT(item), (GWeakNotify)action_free, action); + g_object_weak_ref(G_OBJECT(item), (GWeakNotify)g_bytes_unref, action); } if(id) diff --git a/src/gui/menu.h b/src/gui/menu.h index f5ca02b..8a5127c 100644 --- a/src/gui/menu.h +++ b/src/gui/menu.h @@ -9,7 +9,7 @@ GtkWidget *menu_new ( gchar *name ); void menu_remove ( gchar *name ); void menu_item_remove ( gchar *id ); void menu_popup ( GtkWidget *, GtkWidget *, GdkEvent *, gpointer, guint16 * ); -GtkWidget *menu_item_new ( gchar *label, action_t *action, gchar *id ); +GtkWidget *menu_item_new ( gchar *label, GBytes *action, gchar *id ); void menu_item_update ( GtkWidget *item, const gchar *label, const gchar *icon ); #endif diff --git a/src/gui/pageritem.c b/src/gui/pageritem.c index 3345607..ed08db9 100644 --- a/src/gui/pageritem.c +++ b/src/gui/pageritem.c @@ -15,7 +15,7 @@ static gboolean pager_item_action_exec ( GtkWidget *self, gint slot, { PagerItemPrivate *priv; GdkModifierType mods; - action_t *action; + GBytes *action; g_return_val_if_fail(IS_PAGER_ITEM(self),FALSE); priv = pager_item_get_instance_private(PAGER_ITEM(self)); diff --git a/src/gui/taskbar.c b/src/gui/taskbar.c index 5d7c191..52e1a31 100644 --- a/src/gui/taskbar.c +++ b/src/gui/taskbar.c @@ -29,16 +29,15 @@ static void taskbar_class_init ( TaskbarClass *kclass ) static void taskbar_init ( Taskbar *self ) { - action_t *action; + GBytes *action; static guint8 data[sizeof(gpointer)+2]; gpointer fptr = vm_func_lookup("taskbaritemdefault"); flow_grid_invalidate(GTK_WIDGET(self)); - action = action_new(); data[0] = EXPR_OP_FUNCTION; memcpy(data+2, &fptr, sizeof(gpointer)); - action->code = g_bytes_new_static(data, sizeof(gpointer)+2); + action = g_bytes_new_static(data, sizeof(gpointer)+2); base_widget_set_action(GTK_WIDGET(self), 1, 0, action); } diff --git a/src/gui/taskbaritem.c b/src/gui/taskbaritem.c index a3af8d3..321460a 100644 --- a/src/gui/taskbaritem.c +++ b/src/gui/taskbaritem.c @@ -24,7 +24,7 @@ static gboolean taskbar_item_action_exec ( GtkWidget *self, gint slot, TaskbarItemPrivate *priv; GdkModifierType mods; GtkWidget *shell, *parent; - action_t *action; + GBytes *action; g_return_val_if_fail(IS_TASKBAR_ITEM(self), FALSE); priv = taskbar_item_get_instance_private(TASKBAR_ITEM(self)); diff --git a/src/gui/taskbaritem.h b/src/gui/taskbaritem.h index f95cc35..f2214ce 100644 --- a/src/gui/taskbaritem.h +++ b/src/gui/taskbaritem.h @@ -32,7 +32,7 @@ struct _TaskbarItemPrivate GtkWidget *box; GtkWidget *taskbar; window_t *win; - action_t **actions; + GBytes **actions; gboolean invalid; GdkModifierType saved_modifiers; }; diff --git a/src/gui/taskbarpopup.c b/src/gui/taskbarpopup.c index bd5093e..43ff9f1 100644 --- a/src/gui/taskbarpopup.c +++ b/src/gui/taskbarpopup.c @@ -219,7 +219,7 @@ static gboolean taskbar_popup_action_exec ( GtkWidget *self, gint slot, TaskbarPopupPrivate *priv; GList *children; window_t *win; - action_t *action; + GBytes *action; g_return_val_if_fail(IS_TASKBAR_POPUP(self),FALSE); priv = taskbar_popup_get_instance_private(TASKBAR_POPUP(self));