Skip to content

Commit

Permalink
deprecate action_t
Browse files Browse the repository at this point in the history
  • Loading branch information
LBCrion committed Dec 23, 2024
1 parent d16e095 commit 2d3a670
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 120 deletions.
56 changes: 6 additions & 50 deletions src/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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);
}
20 changes: 3 additions & 17 deletions src/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
2 changes: 1 addition & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 **);
Expand Down
4 changes: 2 additions & 2 deletions src/config/layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 )
Expand Down
27 changes: 8 additions & 19 deletions src/config/toplevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'",
Expand Down Expand Up @@ -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,
Expand All @@ -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 )
Expand Down
31 changes: 14 additions & 17 deletions src/gui/basewidget.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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
{
Expand Down Expand Up @@ -959,15 +956,15 @@ 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);

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);
}
6 changes: 3 additions & 3 deletions src/gui/basewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct _BaseWidgetPrivate
};

typedef struct _base_widget_attachment {
action_t *action;
GBytes *action;
gint event;
GdkModifierType mods;
} base_widget_attachment_t;
Expand All @@ -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 );
Expand All @@ -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 );
Expand Down
6 changes: 3 additions & 3 deletions src/gui/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/gui/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/gui/pageritem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
5 changes: 2 additions & 3 deletions src/gui/taskbar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/taskbaritem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/gui/taskbaritem.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct _TaskbarItemPrivate
GtkWidget *box;
GtkWidget *taskbar;
window_t *win;
action_t **actions;
GBytes **actions;
gboolean invalid;
GdkModifierType saved_modifiers;
};
Expand Down
Loading

0 comments on commit 2d3a670

Please sign in to comment.