summaryrefslogtreecommitdiffstats
path: root/include/widgets
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2017-05-30 16:23:19 +0200
committerDave Davenport <qball@gmpclient.org>2017-05-30 16:23:19 +0200
commit9a6fd1c6c3d54c4a6db6ba7d15f317927f4036ec (patch)
treef87ad134ca304112591051fa9dee98a464080557 /include/widgets
parent7aef96d391a166e9768e1ed58de72c4bbe3740ba (diff)
parent4e6af2eab84157794684c485d15fb9624ec0f306 (diff)
Merge in master
Diffstat (limited to 'include/widgets')
-rw-r--r--include/widgets/listview.h2
-rw-r--r--include/widgets/scrollbar.h2
-rw-r--r--include/widgets/textbox.h8
-rw-r--r--include/widgets/widget-internal.h69
-rw-r--r--include/widgets/widget.h116
5 files changed, 145 insertions, 52 deletions
diff --git a/include/widgets/listview.h b/include/widgets/listview.h
index 4373cc6b..81d705b1 100644
--- a/include/widgets/listview.h
+++ b/include/widgets/listview.h
@@ -66,7 +66,7 @@ typedef void ( *listview_update_callback )( textbox *tb, unsigned int entry, voi
/**
* Callback when a element is activated.
*/
-typedef void ( *listview_mouse_activated_cb )( listview *, xcb_button_press_event_t *, void * );
+typedef void ( *listview_mouse_activated_cb )( listview *, gboolean, void * );
/**
* @param name The name of the to be created widget.
diff --git a/include/widgets/scrollbar.h b/include/widgets/scrollbar.h
index 75ecfbf9..7bf97cc1 100644
--- a/include/widgets/scrollbar.h
+++ b/include/widgets/scrollbar.h
@@ -88,7 +88,7 @@ void scrollbar_set_max_value ( scrollbar *sb, unsigned int max );
*
* Calculate the position of the click relative to the max value of bar
*/
-unsigned int scrollbar_clicked ( const scrollbar *sb, int y );
+guint scrollbar_scroll_get_line ( const scrollbar *sb, int y );
/*@}*/
#endif // ROFI_SCROLLBAR_H
diff --git a/include/widgets/textbox.h b/include/widgets/textbox.h
index 8b4c5386..904882bd 100644
--- a/include/widgets/textbox.h
+++ b/include/widgets/textbox.h
@@ -112,6 +112,7 @@ typedef enum
} TextBoxFontType;
/**
+ * @param type The type of the to be created widget.
* @param name The name of the to be created widget.
* @param flags #TextboxFlags indicating the type of textbox.
* @param tbft #TextBoxFontType current state of textbox.
@@ -122,9 +123,10 @@ typedef enum
* free with #widget_free
* @returns a new #textbox
*/
-textbox* textbox_create ( const char *name, TextboxFlags flags,
- TextBoxFontType tbft,
- const char *text );
+textbox* textbox_create_full ( WidgetType type, const char *name, TextboxFlags flags,
+ TextBoxFontType tbft,
+ const char *text );
+#define textbox_create( n, f, tbft, t ) textbox_create_full ( WIDGET_TYPE_UNKNOWN, n, f, tbft, t )
/**
* @param tb Handle to the textbox
* @param tbft The style of font to render.
diff --git a/include/widgets/widget-internal.h b/include/widgets/widget-internal.h
index 762c4794..7a1ab627 100644
--- a/include/widgets/widget-internal.h
+++ b/include/widgets/widget-internal.h
@@ -34,74 +34,79 @@
*/
struct _widget
{
+ /** The type of the widget */
+ WidgetType type;
/** X position relative to parent */
- short x;
+ short x;
/** Y position relative to parent */
- short y;
+ short y;
/** Width of the widget */
- short w;
+ short w;
/** Height of the widget */
- short h;
+ short h;
/** Padding */
- Padding def_margin;
- Padding def_padding;
- Padding def_border;
- Padding def_border_radius;
- Padding margin;
- Padding padding;
- Padding border;
- Padding border_radius;
+ Padding def_margin;
+ Padding def_padding;
+ Padding def_border;
+ Padding def_border_radius;
+ Padding margin;
+ Padding padding;
+ Padding border;
+ Padding border_radius;
/** enabled or not */
- gboolean enabled;
+ gboolean enabled;
/** Expand the widget when packed */
- gboolean expand;
+ gboolean expand;
/*** The packing index */
- int index;
+ int index;
/** Place widget at end of parent */
- gboolean end;
+ gboolean end;
/** Parent widget */
- struct _widget *parent;
+ struct _widget *parent;
/** Internal */
- gboolean need_redraw;
+ gboolean need_redraw;
/** get width of widget implementation function */
- int ( *get_width )( struct _widget * );
+ int ( *get_width )( struct _widget * );
/** get height of widget implementation function */
- int ( *get_height )( struct _widget * );
+ int ( *get_height )( struct _widget * );
/** draw widget implementation function */
- void ( *draw )( struct _widget *widget, cairo_t *draw );
+ void ( *draw )( struct _widget *widget, cairo_t *draw );
/** resize widget implementation function */
- void ( *resize )( struct _widget *, short, short );
+ void ( *resize )( struct _widget *, short, short );
/** update widget implementation function */
- void ( *update )( struct _widget * );
+ void ( *update )( struct _widget * );
/** Handle mouse motion, used for dragging */
- gboolean ( *motion_notify )( struct _widget *, xcb_motion_notify_event_t * );
+ gboolean ( *motion_notify )( struct _widget *, gint x, gint y );
int ( *get_desired_height )( struct _widget * );
int ( *get_desired_width )( struct _widget * );
- /** widget clicked callback */
- widget_clicked_cb clicked;
- /** user data for clicked callback */
- void *clicked_cb_data;
+ /** widget find_mouse_target callback */
+ widget_find_mouse_target_cb find_mouse_target;
+ /** widget trigger_action callback */
+ widget_trigger_action_cb trigger_action;
+ /** user data for find_mouse_target and trigger_action callback */
+ void *trigger_action_cb_data;
/** Free widget callback */
- void ( *free )( struct _widget *widget );
+ void ( *free )( struct _widget *widget );
/** Name of widget (used for theming) */
- char *name;
- const char *state;
+ char *name;
+ const char *state;
};
/**
* @param widget The widget to initialize.
+ * @param type The type of the widget.
* @param name The name of the widget.
*
* Initializes the widget structure.
*
*/
-void widget_init ( widget *widget, const char *name );
+void widget_init ( widget *widget, WidgetType type, const char *name );
/**
* @param widget The widget handle.
diff --git a/include/widgets/widget.h b/include/widgets/widget.h
index 36eecf90..8fce3a43 100644
--- a/include/widgets/widget.h
+++ b/include/widgets/widget.h
@@ -31,6 +31,7 @@
#include <cairo.h>
#include <xcb/xcb.h>
#include <xcb/xproto.h>
+#include "keyb.h"
/**
* @defgroup widget widget
*
@@ -50,9 +51,63 @@
typedef struct _widget widget;
/**
- * Callback for when widget is clicked.
+ * Type of the widget. It is used to bubble events to the relevant widget.
*/
-typedef gboolean ( *widget_clicked_cb )( widget *, xcb_button_press_event_t *, void * );
+typedef enum
+{
+ /** Default type */
+ WIDGET_TYPE_UNKNOWN,
+ /** The listview widget */
+ WIDGET_TYPE_LISTVIEW = SCOPE_MOUSE_LISTVIEW,
+ /** An element in the listview */
+ WIDGET_TYPE_LISTVIEW_ELEMENT = SCOPE_MOUSE_LISTVIEW_ELEMENT,
+ /** The input bar edit box */
+ WIDGET_TYPE_EDITBOX = SCOPE_MOUSE_EDITBOX,
+ /** The listview scrollbar */
+ WIDGET_TYPE_SCROLLBAR = SCOPE_MOUSE_SCROLLBAR,
+ /** A tab in the modi sidebar */
+ WIDGET_TYPE_SIDEBAR_MODI = SCOPE_MOUSE_SIDEBAR_MODI,
+} WidgetType;
+
+/**
+ * Whether and how the action was handled
+ */
+typedef enum
+{
+ /** The action was ignore and should bubble */
+ WIDGET_TRIGGER_ACTION_RESULT_IGNORED,
+ /** The action was handled directly */
+ WIDGET_TRIGGER_ACTION_RESULT_HANDLED,
+ /** The action was handled and should start the grab for motion events */
+ WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_BEGIN,
+ /** The action was handled and should stop the grab for motion events */
+ WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_END,
+} WidgetTriggerActionResult;
+
+/**
+ * @param widget The container widget itself
+ * @param type The widget type searched for
+ * @param x The X coordination of the mouse event relative to @param widget
+ * @param y The Y coordination of the mouse event relative to @param widget
+ *
+ * This callback must only iterate over the children of a Widget, and return NULL if none of them is relevant.
+ *
+ * @returns A child widget if found, NULL otherwise
+ */
+typedef widget * ( *widget_find_mouse_target_cb )( widget *widget, WidgetType type, gint x, gint y );
+
+/**
+ * @param widget The target widget
+ * @param action The action value (which enum it is depends on the widget type)
+ * @param x The X coordination of the mouse event relative to @param widget
+ * @param y The Y coordination of the mouse event relative to @param widget
+ * @param user_data The data passed to widget_set_trigger_action_handler()
+ *
+ * This callback should handle the action if relevant, and returns whether it did or not.
+ *
+ * @returns Whether the action was handled or not, see enum values for details
+ */
+typedef WidgetTriggerActionResult ( *widget_trigger_action_cb )( widget *widget, guint action, gint x, gint y, void *user_data );
/** Macro to get widget from an implementation (e.g. textbox/scrollbar) */
#define WIDGET( a ) ( (widget *) ( a ) )
@@ -80,6 +135,14 @@ void widget_move ( widget *widget, short x, short y );
/**
* @param widget Handle to widget
*
+ * Get the type of the widget.
+ * @returns The type of the widget.
+ */
+WidgetType widget_type ( widget *widget );
+
+/**
+ * @param widget Handle to widget
+ *
* Check if widget is enabled.
* @returns TRUE when widget is enabled.
*/
@@ -151,6 +214,15 @@ int widget_get_x_pos ( widget *widget );
/**
* @param widget The widget handle
+ * @param x A pointer to the absolute X coordinates
+ * @param y A pointer to the absolute Y coordinates
+ *
+ * Will modify @param x and @param y to make them relative to @param widget .
+ */
+void widget_xy_to_relative ( widget *widget, gint *x, gint *y );
+
+/**
+ * @param widget The widget handle
*
* Update the widget, and its parent recursively.
* This should be called when size of widget changes.
@@ -172,34 +244,48 @@ gboolean widget_need_redraw ( widget *wid );
/**
* @param wid The widget handle
- * @param xbe The button press event
+ * @param type The type of the wanted widget
+ * @param x The x coordinate of the mouse event
+ * @param y The y coordinate of the mouse event
*
- * Signal the widget that it has been clicked,
- * The click should have happened within the region of the widget, check with
- * ::widget_intersect.
+ * Get the widget that should handle a mouse event.
*
- * @returns returns TRUE if click is handled.
+ * @returns returns the widget that should handle the mouse event.
*/
-gboolean widget_clicked ( widget *wid, xcb_button_press_event_t *xbe );
+widget *widget_find_mouse_target ( widget *wid, WidgetType type, gint x, gint y );
/**
* @param wid The widget handle
- * @param cb The widget click callback
+ * @param action The action to trigger
+ * @param x A pointer to the x coordinate of the click
+ * @param y A pointer to the y coordinate of the click
+ *
+ * Trigger an action on widget.
+ * @param x and @param y are relative to @param wid .
+ *
+ * @returns Whether the action was handled or not
+ */
+WidgetTriggerActionResult widget_trigger_action ( widget *wid, guint action, gint x, gint y );
+
+/**
+ * @param wid The widget handle
+ * @param cb The widget trigger action callback
* @param udata the user data to pass to callback
*
- * Override the widget clicked handler on widget.
+ * Override the widget trigger action handler on widget.
*/
-void widget_set_clicked_handler ( widget *wid, widget_clicked_cb cb, void *udata );
+void widget_set_trigger_action_handler ( widget *wid, widget_trigger_action_cb cb, void *udata );
/**
* @param wid The widget handle
- * @param xme The motion notify object.
+ * @param x The x coordinate of the mouse event
+ * @param y The y coordinate of the mouse event
*
* Motion notify.
- * TODO make this like clicked with callback.
- * returns TRUE when handled.
+ *
+ * @returns TRUE when handled.
*/
-gboolean widget_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme );
+gboolean widget_motion_notify ( widget *wid, gint x, gint y );
/**
* @param wid The widget handle