summaryrefslogtreecommitdiffstats
path: root/include/widgets
diff options
context:
space:
mode:
authorQuentin Glidic <sardemff7+git@sardemff7.net>2017-05-28 02:18:09 +0200
committerQuentin Glidic <sardemff7+git@sardemff7.net>2017-05-29 16:51:06 +0200
commita9199e3e1762182ddd8a19514a75f6c78c14481a (patch)
tree1ed440438f11206d7770159a1f30d60ea9dd7587 /include/widgets
parent6acf365420beb5219a4d8643d93bf74a479dd2e3 (diff)
Use libnkutils for keybindings
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
Diffstat (limited to 'include/widgets')
-rw-r--r--include/widgets/listview.h2
-rw-r--r--include/widgets/scrollbar.h3
-rw-r--r--include/widgets/textbox.h7
-rw-r--r--include/widgets/widget-internal.h70
-rw-r--r--include/widgets/widget.h55
5 files changed, 85 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..50fb78bc 100644
--- a/include/widgets/scrollbar.h
+++ b/include/widgets/scrollbar.h
@@ -43,6 +43,7 @@
typedef struct _scrollbar
{
widget widget;
+ gboolean scrolling;
unsigned int length;
unsigned int pos;
unsigned int pos_length;
@@ -88,7 +89,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 );
+unsigned int scrollbar_scroll ( const scrollbar *sb, int y );
/*@}*/
#endif // ROFI_SCROLLBAR_H
diff --git a/include/widgets/textbox.h b/include/widgets/textbox.h
index fc75baa7..2209de29 100644
--- a/include/widgets/textbox.h
+++ b/include/widgets/textbox.h
@@ -120,9 +120,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 0ac497d5..60e1d11c 100644
--- a/include/widgets/widget-internal.h
+++ b/include/widgets/widget-internal.h
@@ -34,63 +34,67 @@
*/
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 *, xcb_motion_notify_event_t * );
- int ( *get_desired_height )( struct _widget * );
+ int ( *get_desired_height )( 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;
};
/**
@@ -100,7 +104,7 @@ struct _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 990e50b4..dd3ea162 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
*
@@ -48,11 +49,18 @@
* Structure is elaborated in widget-internal.h
*/
typedef struct _widget widget;
-
-/**
- * Callback for when widget is clicked.
- */
-typedef gboolean ( *widget_clicked_cb )( widget *, xcb_button_press_event_t *, void * );
+typedef enum
+{
+ WIDGET_TYPE_UNKNOWN,
+ WIDGET_TYPE_LISTVIEW = SCOPE_MOUSE_LISTVIEW,
+ WIDGET_TYPE_LISTVIEW_ELEMENT = SCOPE_MOUSE_LISTVIEW_ELEMENT,
+ WIDGET_TYPE_EDITBOX = SCOPE_MOUSE_EDITBOX,
+ WIDGET_TYPE_SCROLLBAR = SCOPE_MOUSE_SCROLLBAR,
+ WIDGET_TYPE_SIDEBAR_MODI = SCOPE_MOUSE_SIDEBAR_MODI,
+} WidgetType;
+
+typedef widget * ( *widget_find_mouse_target_cb )( widget *, WidgetType type, gint *x, gint *y );
+typedef gboolean ( *widget_trigger_action_cb )( widget *, guint action, gint x, gint y, void * );
/** Macro to get widget from an implementation (e.g. textbox/scrollbar) */
#define WIDGET( a ) ( (widget *) ( a ) )
@@ -80,6 +88,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.
*/
@@ -172,24 +188,35 @@ gboolean widget_need_redraw ( widget *wid );
/**
* @param wid The widget handle
- * @param xbe The button press event
+ * @param x A pointer to the x coordinate of the mouse event
+ * @param y A pointer to the y coordinate of the mouse event
+ *
+ * Get the widget that should handle a mouse event.
+ * @x and @y are adjusted to be relative to the widget.
*
- * Signal the widget that it has been clicked,
- * The click should have happened within the region of the widget, check with
- * ::widget_intersect.
+ * @returns returns the widget that should handle the mouse event.
+ */
+widget *widget_find_mouse_target ( widget *wid, WidgetType type, gint *x, gint *y );
+
+/**
+ * @param wid The widget handle
+ * @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
*
- * @returns returns TRUE if click is handled.
+ * Trigger an action on widget.
+ * @x and @y are relative to the widget.
*/
-gboolean widget_clicked ( widget *wid, xcb_button_press_event_t *xbe );
+gboolean widget_trigger_action ( widget *wid, guint action, gint x, gint y );
/**
* @param wid The widget handle
- * @param cb The widget click callback
+ * @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