Skip to content

Commit

Permalink
exprlib: implement WidgetId expression function
Browse files Browse the repository at this point in the history
  • Loading branch information
LBCrion committed Aug 28, 2023
1 parent bf7c019 commit bc39c56
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/config/layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,7 @@ void config_widget ( GScanner *scanner, GtkWidget *widget )
SEQ_OPT,G_TOKEN_STRING,NULL,&id,NULL,
SEQ_OPT,'{',NULL,&curly,NULL,
SEQ_END);
if(id)
base_widget_set_id(widget,id);
base_widget_set_id(widget,id);

if(curly)
{
Expand Down
15 changes: 15 additions & 0 deletions src/exprlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "module.h"
#include "wintree.h"
#include "expr.h"
#include "basewidget.h"

/* extract a substring */
static void *expr_lib_mid ( void **params, void *widget, void *event )
Expand Down Expand Up @@ -276,6 +277,13 @@ static void *expr_lib_gtkevent ( void **params, void *base, void *event )
return result;
}

static void *expr_lib_widget_id ( void **params, void *widget, void *event )
{
gchar *id = base_widget_get_id(widget);

return g_strdup(id?id:"");
}

ModuleExpressionHandlerV1 mid_handler = {
.flags = MODULE_EXPR_DETERMINISTIC,
.name = "mid",
Expand Down Expand Up @@ -367,6 +375,12 @@ ModuleExpressionHandlerV1 gtkevent_handler = {
.function = expr_lib_gtkevent
};

ModuleExpressionHandlerV1 widget_id_handler = {
.name = "widgetid",
.parameters = "",
.function = expr_lib_widget_id
};

ModuleExpressionHandlerV1 *expr_lib_handlers[] = {
&mid_handler,
&pad_handler,
Expand All @@ -381,6 +395,7 @@ ModuleExpressionHandlerV1 *expr_lib_handlers[] = {
&upper_handler,
&lower_handler,
&gtkevent_handler,
&widget_id_handler,
NULL
};

Expand Down

0 comments on commit bc39c56

Please sign in to comment.