summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornotuxic <notuxic@gmail.com>2023-03-05 11:17:25 +0100
committerGitHub <noreply@github.com>2023-03-05 11:17:25 +0100
commitc870d512ff95d5749960e9b6026ac9f7aa7c4bf3 (patch)
treee5a746ca736a247cb0e9b11ed20e8f543dfc48de
parenta5bd8bc63095d80ea3ad6f462138c23dc57c4e74 (diff)
Add support for adding textbox widgets to listview elements (#1792)
* Add support for adding textbox-widgets to listview entries * Add support for adding icons and buttons to listview elements
-rw-r--r--include/view.h6
-rw-r--r--source/view.c2
-rw-r--r--source/widgets/listview.c23
3 files changed, 30 insertions, 1 deletions
diff --git a/include/view.h b/include/view.h
index 3d4e97d8..503a6180 100644
--- a/include/view.h
+++ b/include/view.h
@@ -29,6 +29,7 @@
#define ROFI_VIEW_H
#include "mode.h"
+#include "widgets/widget.h"
#include <pango/pango.h>
#include <xcb/xcb.h>
/**
@@ -355,5 +356,10 @@ void rofi_view_ellipsize_listview(RofiViewState *state,
*/
gboolean rofi_set_im_window_pos(int new_x, int new_y);
+
+WidgetTriggerActionResult textbox_button_trigger_action(
+ widget *wid, MouseBindingMouseDefaultAction action, G_GNUC_UNUSED gint x,
+ G_GNUC_UNUSED gint y, G_GNUC_UNUSED void *user_data);
+
/** @} */
#endif
diff --git a/source/view.c b/source/view.c
index 011b23e1..3861f6b5 100644
--- a/source/view.c
+++ b/source/view.c
@@ -2115,7 +2115,7 @@ static int rofi_view_calculate_height(RofiViewState *state) {
return widget_get_desired_height(main_window, state->width);
}
-static WidgetTriggerActionResult textbox_button_trigger_action(
+WidgetTriggerActionResult textbox_button_trigger_action(
widget *wid, MouseBindingMouseDefaultAction action, G_GNUC_UNUSED gint x,
G_GNUC_UNUSED gint y, G_GNUC_UNUSED void *user_data) {
RofiViewState *state = (RofiViewState *)user_data;
diff --git a/source/widgets/listview.c b/source/widgets/listview.c
index 9c147d7a..c1be8760 100644
--- a/source/widgets/listview.c
+++ b/source/widgets/listview.c
@@ -36,6 +36,7 @@
#include "settings.h"
#include "theme.h"
+#include "view.h"
#include "timings.h"
@@ -182,6 +183,28 @@ static void listview_add_widget(listview *lv, _listview_row *row, widget *wid,
textbox_create(WIDGET(wid), WIDGET_TYPE_TEXTBOX_TEXT, "element-index",
TB_AUTOHEIGHT, NORMAL, " ", 0, 0);
box_add((box *)wid, WIDGET(row->index), FALSE);
+ } else if (strncasecmp(label, "textbox", 7) == 0) {
+ textbox *textbox_custom =
+ textbox_create(wid, WIDGET_TYPE_TEXTBOX_TEXT, label,
+ TB_AUTOHEIGHT | TB_WRAP, NORMAL, "", 0, 0);
+ box_add((box *)wid, WIDGET(textbox_custom), TRUE);
+ } else if (strncasecmp(label, "button", 6) == 0) {
+ textbox *button_custom =
+ textbox_create(wid, WIDGET_TYPE_EDITBOX, label,
+ TB_AUTOHEIGHT | TB_WRAP, NORMAL, "", 0, 0);
+ box_add((box *)wid, WIDGET(button_custom), TRUE);
+ widget_set_trigger_action_handler(WIDGET(button_custom), textbox_button_trigger_action,
+ lv->udata);
+ } else if (strncasecmp(label, "icon", 4) == 0) {
+ icon *icon_custom = icon_create(wid, label);
+ /* small hack to make it clickable */
+ const char *type = rofi_theme_get_string(WIDGET(icon_custom), "action", NULL);
+ if (type) {
+ WIDGET(icon_custom)->type = WIDGET_TYPE_EDITBOX;
+ }
+ box_add((box *)wid, WIDGET(icon_custom), TRUE);
+ widget_set_trigger_action_handler(WIDGET(icon_custom), textbox_button_trigger_action,
+ lv->udata);
} else {
widget *wid2 = (widget *)box_create(wid, label, ROFI_ORIENTATION_VERTICAL);
box_add((box *)wid, WIDGET(wid2), TRUE);