2017-04-15 06:32:05 -04:00
|
|
|
/*
|
|
|
|
* rofi
|
|
|
|
*
|
|
|
|
* MIT/X11 License
|
|
|
|
* Copyright © 2013-2017 Qball Cow <qball@gmpclient.org>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-10-08 12:57:59 -04:00
|
|
|
#ifndef ROFI_WIDGET_H
|
|
|
|
#define ROFI_WIDGET_H
|
2021-08-19 07:34:01 -04:00
|
|
|
#include "keyb.h"
|
2016-10-08 12:57:59 -04:00
|
|
|
#include <cairo.h>
|
2021-08-19 07:34:01 -04:00
|
|
|
#include <glib.h>
|
2016-10-08 12:57:59 -04:00
|
|
|
#include <xcb/xcb.h>
|
|
|
|
#include <xcb/xproto.h>
|
|
|
|
/**
|
2016-10-13 03:22:08 -04:00
|
|
|
* @defgroup widget widget
|
2016-10-08 12:57:59 -04:00
|
|
|
*
|
2021-08-19 07:34:01 -04:00
|
|
|
* Generic abstract widget class. Widgets should 'inherit' from this class
|
|
|
|
* (first structure in there structure should be widget). The generic widget
|
|
|
|
* implements generic functions like get_width, get_height, draw, resize,
|
|
|
|
* update, free and clicked. It also holds information about how the widget
|
|
|
|
* should be packed.
|
2016-10-08 12:57:59 -04:00
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*/
|
2016-10-14 02:47:21 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract structure holding internal state of a widget.
|
|
|
|
* Structure is elaborated in widget-internal.h
|
|
|
|
*/
|
2017-10-21 05:18:52 -04:00
|
|
|
typedef struct _widget widget;
|
2016-10-11 02:11:14 -04:00
|
|
|
|
|
|
|
/**
|
2017-05-30 06:08:44 -04:00
|
|
|
* Type of the widget. It is used to bubble events to the relevant widget.
|
2016-10-11 02:11:14 -04:00
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
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,
|
2022-02-23 16:42:56 -05:00
|
|
|
/** A widget allowing user to swithc between modes */
|
2021-08-19 07:34:01 -04:00
|
|
|
WIDGET_TYPE_MODE_SWITCHER = SCOPE_MOUSE_MODE_SWITCHER,
|
|
|
|
/** Text-only textbox */
|
|
|
|
WIDGET_TYPE_TEXTBOX_TEXT,
|
2017-05-27 20:18:09 -04:00
|
|
|
} WidgetType;
|
|
|
|
|
2017-05-30 06:45:48 -04:00
|
|
|
/**
|
|
|
|
* Whether and how the action was handled
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
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,
|
2017-05-30 06:45:48 -04:00
|
|
|
} WidgetTriggerActionResult;
|
|
|
|
|
2017-05-30 06:08:44 -04:00
|
|
|
/**
|
|
|
|
* @param widget The container widget itself
|
|
|
|
* @param type The widget type searched for
|
2022-07-27 18:23:21 -04:00
|
|
|
* @param x The X coordination of the mouse event relative to #widget
|
|
|
|
* @param y The Y coordination of the mouse event relative to #widget
|
2017-05-30 06:08:44 -04:00
|
|
|
*
|
2021-08-19 07:34:01 -04:00
|
|
|
* This callback must only iterate over the children of a Widget, and return
|
|
|
|
* NULL if none of them is relevant.
|
2017-05-30 06:08:44 -04:00
|
|
|
*
|
|
|
|
* @returns A child widget if found, NULL otherwise
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
typedef widget *(*widget_find_mouse_target_cb)(widget *widget, WidgetType type,
|
|
|
|
gint x, gint y);
|
2017-05-30 06:08:44 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param widget The target widget
|
|
|
|
* @param action The action value (which enum it is depends on the widget type)
|
2022-07-27 18:23:21 -04:00
|
|
|
* @param x The X coordination of the mouse event relative to #widget
|
|
|
|
* @param y The Y coordination of the mouse event relative to #widget
|
2017-05-30 06:08:44 -04:00
|
|
|
* @param user_data The data passed to widget_set_trigger_action_handler()
|
|
|
|
*
|
2021-08-19 07:34:01 -04:00
|
|
|
* This callback should handle the action if relevant, and returns whether it
|
|
|
|
* did or not.
|
2017-05-30 06:08:44 -04:00
|
|
|
*
|
2017-05-30 06:45:48 -04:00
|
|
|
* @returns Whether the action was handled or not, see enum values for details
|
2017-05-30 06:08:44 -04:00
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
typedef WidgetTriggerActionResult (*widget_trigger_action_cb)(widget *widget,
|
|
|
|
guint action,
|
|
|
|
gint x, gint y,
|
|
|
|
void *user_data);
|
2016-10-08 12:57:59 -04:00
|
|
|
|
|
|
|
/** Macro to get widget from an implementation (e.g. textbox/scrollbar) */
|
2021-08-19 07:34:01 -04:00
|
|
|
#define WIDGET(a) ((widget *)(a))
|
2016-10-08 12:57:59 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param widget The widget to check
|
|
|
|
* @param x The X position relative to parent window
|
|
|
|
* @param y the Y position relative to parent window
|
|
|
|
*
|
|
|
|
* Check if x,y falls within the widget.
|
|
|
|
*
|
|
|
|
* @return TRUE if x,y falls within the widget
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
int widget_intersect(const widget *widget, int x, int y);
|
2016-10-08 12:57:59 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param widget The widget to move
|
|
|
|
* @param x The new X position relative to parent window
|
|
|
|
* @param y The new Y position relative to parent window
|
|
|
|
*
|
|
|
|
* Moves the widget.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void widget_move(widget *widget, short x, short y);
|
2016-10-08 12:57:59 -04:00
|
|
|
|
2019-08-08 14:02:20 -04:00
|
|
|
/**
|
|
|
|
* @param widget Handle to widget
|
|
|
|
* @param type The widget type.
|
|
|
|
*
|
|
|
|
* Set the widget type.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void widget_set_type(widget *widget, WidgetType type);
|
2019-08-08 14:02:20 -04:00
|
|
|
|
2016-10-11 02:11:14 -04:00
|
|
|
/**
|
|
|
|
* @param widget Handle to widget
|
|
|
|
*
|
|
|
|
* Check if widget is enabled.
|
|
|
|
* @returns TRUE when widget is enabled.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
gboolean widget_enabled(widget *widget);
|
2020-07-11 08:48:58 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param widget Handle to widget
|
|
|
|
* @param enabled The new state
|
|
|
|
*
|
|
|
|
* Disable the widget.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void widget_set_enabled(widget *widget, gboolean enabled);
|
2020-07-11 08:48:58 -04:00
|
|
|
|
2016-10-11 02:11:14 -04:00
|
|
|
/**
|
|
|
|
* @param widget Handle to widget
|
|
|
|
*
|
|
|
|
* Disable the widget.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
static inline void widget_disable(widget *widget) {
|
|
|
|
widget_set_enabled(widget, FALSE);
|
2020-07-11 08:48:58 -04:00
|
|
|
}
|
2016-10-11 02:11:14 -04:00
|
|
|
/**
|
|
|
|
* @param widget Handle to widget
|
|
|
|
*
|
|
|
|
* Enable the widget.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
static inline void widget_enable(widget *widget) {
|
|
|
|
widget_set_enabled(widget, TRUE);
|
2020-07-11 08:48:58 -04:00
|
|
|
}
|
2016-10-08 12:57:59 -04:00
|
|
|
|
|
|
|
/**
|
2017-04-23 09:17:15 -04:00
|
|
|
* @param widget widget Handle to the widget
|
2016-11-15 15:54:31 -05:00
|
|
|
* @param d The cairo object used to draw itself.
|
2016-10-08 12:57:59 -04:00
|
|
|
*
|
|
|
|
* Render the textbox.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void widget_draw(widget *widget, cairo_t *d);
|
2016-10-08 12:57:59 -04:00
|
|
|
|
|
|
|
/**
|
2017-04-25 05:59:25 -04:00
|
|
|
* @param wid Handle to the widget
|
2016-10-08 12:57:59 -04:00
|
|
|
*
|
|
|
|
* Free the widget and all allocated memory.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void widget_free(widget *wid);
|
2016-10-08 12:57:59 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param widget The widget toresize
|
|
|
|
* @param w The new width
|
|
|
|
* @param h The new height
|
|
|
|
*
|
|
|
|
* Resizes the widget.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void widget_resize(widget *widget, short w, short h);
|
2016-10-08 12:57:59 -04:00
|
|
|
|
2016-10-13 03:22:08 -04:00
|
|
|
/**
|
|
|
|
* @param widget The widget handle
|
|
|
|
*
|
|
|
|
* @returns the height of the widget.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
int widget_get_height(widget *widget);
|
2016-10-13 03:22:08 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param widget The widget handle
|
|
|
|
*
|
|
|
|
* @returns the width of the widget.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
int widget_get_width(widget *widget);
|
2016-10-08 12:57:59 -04:00
|
|
|
|
2016-10-17 12:21:03 -04:00
|
|
|
/**
|
|
|
|
* @param widget The widget handle
|
|
|
|
*
|
2017-11-23 12:41:52 -05:00
|
|
|
* @returns the y position of the widget relative to its parent.
|
2016-10-17 12:21:03 -04:00
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
int widget_get_y_pos(widget *widget);
|
2016-10-17 12:21:03 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param widget The widget handle
|
|
|
|
*
|
2017-11-23 12:41:52 -05:00
|
|
|
* @returns the x position of the widget relative to its parent.
|
2016-10-17 12:21:03 -04:00
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
int widget_get_x_pos(widget *widget);
|
2016-10-17 12:21:03 -04:00
|
|
|
|
2017-05-30 06:37:11 -04:00
|
|
|
/**
|
|
|
|
* @param widget The widget handle
|
|
|
|
* @param x A pointer to the absolute X coordinates
|
|
|
|
* @param y A pointer to the absolute Y coordinates
|
|
|
|
*
|
2021-05-05 16:39:03 -04:00
|
|
|
* Will modify param x and param y to make them relative to param widget .
|
2017-05-30 06:37:11 -04:00
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void widget_xy_to_relative(widget *widget, gint *x, gint *y);
|
2017-05-30 06:37:11 -04:00
|
|
|
|
2016-10-13 03:22:08 -04:00
|
|
|
/**
|
|
|
|
* @param widget The widget handle
|
|
|
|
*
|
|
|
|
* Update the widget, and its parent recursively.
|
|
|
|
* This should be called when size of widget changes.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void widget_update(widget *widget);
|
2016-10-13 03:22:08 -04:00
|
|
|
/**
|
2017-04-23 09:17:15 -04:00
|
|
|
* @param wid The widget handle
|
2016-10-13 03:22:08 -04:00
|
|
|
*
|
|
|
|
* Indicate that the widget needs to be redrawn.
|
|
|
|
* This is done by setting the redraw flag on the toplevel widget.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void widget_queue_redraw(widget *wid);
|
2016-10-13 03:22:08 -04:00
|
|
|
/**
|
2016-11-15 15:54:31 -05:00
|
|
|
* @param wid The widget handle
|
2016-10-13 03:22:08 -04:00
|
|
|
*
|
|
|
|
* Check the flag indicating the widget needs to be redrawn.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
gboolean widget_need_redraw(widget *wid);
|
2016-10-08 12:57:59 -04:00
|
|
|
|
2016-10-13 03:22:08 -04:00
|
|
|
/**
|
|
|
|
* @param wid The widget handle
|
2017-05-30 08:15:13 -04:00
|
|
|
* @param type The type of the wanted widget
|
2017-05-30 06:37:11 -04:00
|
|
|
* @param x The x coordinate of the mouse event
|
|
|
|
* @param y The y coordinate of the mouse event
|
2016-10-13 03:22:08 -04:00
|
|
|
*
|
2017-05-27 20:18:09 -04:00
|
|
|
* Get the widget that should handle a mouse event.
|
2016-10-13 03:22:08 -04:00
|
|
|
*
|
2017-05-27 20:18:09 -04:00
|
|
|
* @returns returns the widget that should handle the mouse event.
|
2016-10-13 03:22:08 -04:00
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
widget *widget_find_mouse_target(widget *wid, WidgetType type, gint x, gint y);
|
2016-10-08 12:57:59 -04:00
|
|
|
|
2021-10-28 02:33:12 -04:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*
|
|
|
|
* Trigger an action on widget.
|
|
|
|
* param x and param y are relative to param wid .
|
|
|
|
*
|
|
|
|
* @returns Whether the action would be handled or not
|
|
|
|
*/
|
2022-11-19 15:50:34 -05:00
|
|
|
WidgetTriggerActionResult widget_check_action(widget *wid,
|
|
|
|
G_GNUC_UNUSED guint action,
|
|
|
|
G_GNUC_UNUSED gint x,
|
|
|
|
G_GNUC_UNUSED gint y);
|
2021-10-28 02:33:12 -04:00
|
|
|
|
2016-10-13 03:22:08 -04:00
|
|
|
/**
|
|
|
|
* @param wid The widget handle
|
2017-05-27 20:18:09 -04:00
|
|
|
* @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
|
2016-10-13 03:22:08 -04:00
|
|
|
*
|
2017-05-27 20:18:09 -04:00
|
|
|
* Trigger an action on widget.
|
2021-05-05 16:39:03 -04:00
|
|
|
* param x and param y are relative to param wid .
|
2017-05-30 06:08:44 -04:00
|
|
|
*
|
|
|
|
* @returns Whether the action was handled or not
|
2016-10-13 03:22:08 -04:00
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
WidgetTriggerActionResult widget_trigger_action(widget *wid, guint action,
|
|
|
|
gint x, gint y);
|
2016-10-08 12:57:59 -04:00
|
|
|
|
2016-10-13 03:22:08 -04:00
|
|
|
/**
|
|
|
|
* @param wid The widget handle
|
2017-05-27 20:18:09 -04:00
|
|
|
* @param cb The widget trigger action callback
|
2017-06-09 03:18:17 -04:00
|
|
|
* @param cb_data the user data to pass to callback
|
2016-10-13 03:22:08 -04:00
|
|
|
*
|
2017-05-27 20:18:09 -04:00
|
|
|
* Override the widget trigger action handler on widget.
|
2016-10-13 03:22:08 -04:00
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void widget_set_trigger_action_handler(widget *wid, widget_trigger_action_cb cb,
|
|
|
|
void *cb_data);
|
2016-10-08 12:57:59 -04:00
|
|
|
|
2016-10-25 15:19:39 -04:00
|
|
|
/**
|
|
|
|
* @param wid The widget handle
|
2017-05-30 08:15:13 -04:00
|
|
|
* @param x The x coordinate of the mouse event
|
|
|
|
* @param y The y coordinate of the mouse event
|
2016-10-25 15:19:39 -04:00
|
|
|
*
|
|
|
|
* Motion notify.
|
2017-05-30 08:15:13 -04:00
|
|
|
*
|
|
|
|
* @returns TRUE when handled.
|
2016-10-25 15:19:39 -04:00
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
gboolean widget_motion_notify(widget *wid, gint x, gint y);
|
2016-12-11 06:19:46 -05:00
|
|
|
|
2017-01-01 12:08:49 -05:00
|
|
|
/**
|
|
|
|
* @param wid The widget handle
|
2021-09-07 13:40:07 -04:00
|
|
|
* @param width The Widget width to get height for
|
2017-01-01 12:08:49 -05:00
|
|
|
*
|
|
|
|
* Get the desired height of this widget recursively.
|
|
|
|
*
|
|
|
|
* @returns the desired height of the widget in pixels.
|
|
|
|
*/
|
2021-09-07 13:40:07 -04:00
|
|
|
int widget_get_desired_height(widget *wid, const int width);
|
2017-01-01 12:08:49 -05:00
|
|
|
|
2017-05-28 10:10:11 -04:00
|
|
|
/**
|
|
|
|
* @param wid The widget handle
|
2021-09-07 13:40:07 -04:00
|
|
|
* @param height The Widget height to get height for
|
2017-05-28 10:10:11 -04:00
|
|
|
*
|
|
|
|
* Get the desired width of this widget recursively.
|
|
|
|
*
|
|
|
|
* @returns the desired width of the widget in pixels.
|
|
|
|
*/
|
2021-09-07 13:40:07 -04:00
|
|
|
int widget_get_desired_width(widget *wid, const int height);
|
2017-06-12 02:17:28 -04:00
|
|
|
/**
|
|
|
|
* @param wid The widget handle
|
|
|
|
*
|
|
|
|
* Get the absolute x-position on the root widget..
|
|
|
|
*
|
|
|
|
* @returns the absolute x-position of widget of the widget in pixels.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
int widget_get_absolute_xpos(widget *wid);
|
2017-06-12 02:17:28 -04:00
|
|
|
/**
|
|
|
|
* @param wid The widget handle
|
|
|
|
*
|
|
|
|
* Get the absolute y-position on the root widget..
|
|
|
|
*
|
|
|
|
* @returns the absolute y-position of widget of the widget in pixels.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
int widget_get_absolute_ypos(widget *wid);
|
2020-10-12 15:39:36 -04:00
|
|
|
/**@}*/
|
2016-10-08 12:57:59 -04:00
|
|
|
#endif // ROFI_WIDGET_H
|