2017-04-15 06:32:05 -04:00
|
|
|
/*
|
|
|
|
* rofi
|
|
|
|
*
|
|
|
|
* MIT/X11 License
|
2022-02-07 17:16:46 -05:00
|
|
|
* Copyright © 2013-2022 Qball Cow <qball@gmpclient.org>
|
2017-04-15 06:32:05 -04:00
|
|
|
*
|
|
|
|
* 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-02-06 08:27:36 -05:00
|
|
|
#ifndef ROFI_VIEW_H
|
|
|
|
#define ROFI_VIEW_H
|
2016-02-21 07:10:32 -05:00
|
|
|
|
2021-08-19 07:34:01 -04:00
|
|
|
#include "mode.h"
|
|
|
|
#include <xcb/xcb.h>
|
2016-02-06 08:27:36 -05:00
|
|
|
/**
|
|
|
|
* @defgroup View View
|
|
|
|
*
|
|
|
|
* The rofi Menu view.
|
2021-05-05 16:39:03 -04:00
|
|
|
* @{
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2016-02-08 12:16:16 -05:00
|
|
|
* @defgroup ViewHandle ViewHandle
|
|
|
|
* @ingroup View
|
|
|
|
*
|
2016-02-06 08:27:36 -05:00
|
|
|
* @{
|
|
|
|
*/
|
2017-10-21 05:18:52 -04:00
|
|
|
typedef struct RofiViewState RofiViewState;
|
2021-08-19 07:34:01 -04:00
|
|
|
typedef enum {
|
|
|
|
/** Create a menu for entering text */
|
|
|
|
MENU_NORMAL = 0,
|
|
|
|
/** Create a menu for entering passwords */
|
|
|
|
MENU_PASSWORD = 1,
|
|
|
|
/** Create amanaged window. */
|
|
|
|
MENU_NORMAL_WINDOW = 2,
|
|
|
|
/** ERROR dialog */
|
|
|
|
MENU_ERROR_DIALOG = 4,
|
2016-02-07 06:31:17 -05:00
|
|
|
} MenuFlags;
|
2016-02-06 07:06:58 -05:00
|
|
|
|
2016-02-07 06:31:17 -05:00
|
|
|
/**
|
|
|
|
* @param sw the Mode to show.
|
|
|
|
* @param input A pointer to a string where the inputted data is placed.
|
2017-04-23 09:17:15 -04:00
|
|
|
* @param menu_flags Flags indicating state of the menu.
|
2021-08-14 07:03:16 -04:00
|
|
|
* @param finalize the finalize callback
|
2016-02-07 06:31:17 -05:00
|
|
|
*
|
|
|
|
* Main menu callback.
|
|
|
|
*
|
|
|
|
* @returns The command issued (see MenuReturn)
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
RofiViewState *rofi_view_create(Mode *sw, const char *input,
|
|
|
|
MenuFlags menu_flags,
|
|
|
|
void (*finalize)(RofiViewState *));
|
2016-02-07 14:38:34 -05:00
|
|
|
|
2016-02-06 07:06:58 -05:00
|
|
|
/**
|
|
|
|
* @param state The Menu Handle
|
|
|
|
*
|
|
|
|
* Check if a finalize function is set, and if sets executes it.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void rofi_view_finalize(RofiViewState *state);
|
2016-02-06 07:06:58 -05:00
|
|
|
|
2016-11-15 15:54:31 -05:00
|
|
|
/**
|
|
|
|
* @param state the Menu handle
|
|
|
|
*
|
|
|
|
* Get the return value associated to the users action.
|
|
|
|
*
|
|
|
|
* @returns the return value
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
MenuReturn rofi_view_get_return_value(const RofiViewState *state);
|
2016-11-15 15:54:31 -05:00
|
|
|
/**
|
|
|
|
* @param state the Menu handle
|
|
|
|
*
|
|
|
|
* Returns the index of the next visible position.
|
|
|
|
*
|
|
|
|
* @return the next position.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
unsigned int rofi_view_get_next_position(const RofiViewState *state);
|
2016-11-15 15:54:31 -05:00
|
|
|
/**
|
|
|
|
* @param state the Menu handle
|
2017-06-01 07:30:29 -04:00
|
|
|
* @param text The text to add to the input box
|
2016-11-15 15:54:31 -05:00
|
|
|
*
|
2017-06-01 07:30:29 -04:00
|
|
|
* Update the state if needed.
|
2016-11-15 15:54:31 -05:00
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void rofi_view_handle_text(RofiViewState *state, char *text);
|
2017-06-01 07:30:29 -04:00
|
|
|
/**
|
|
|
|
* @param state the Menu handle
|
|
|
|
* @param x The X coordinates of the motion
|
2017-06-03 10:27:11 -04:00
|
|
|
* @param y The Y coordinates of the motion
|
2021-04-13 05:45:20 -04:00
|
|
|
* @param find_mouse_target if we should handle pure mouse motion
|
2017-06-01 07:30:29 -04:00
|
|
|
*
|
|
|
|
* Update the state if needed.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void rofi_view_handle_mouse_motion(RofiViewState *state, gint x, gint y,
|
|
|
|
gboolean find_mouse_target);
|
2017-06-01 07:30:29 -04:00
|
|
|
/**
|
|
|
|
* @param state the Menu handle
|
|
|
|
*
|
|
|
|
* Update the state if needed.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void rofi_view_maybe_update(RofiViewState *state);
|
|
|
|
void rofi_view_temp_configure_notify(RofiViewState *state,
|
|
|
|
xcb_configure_notify_event_t *xce);
|
|
|
|
void rofi_view_temp_click_to_exit(RofiViewState *state, xcb_window_t target);
|
2017-06-01 07:30:29 -04:00
|
|
|
/**
|
|
|
|
* Update the state if needed.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void rofi_view_frame_callback(void);
|
2016-11-15 15:54:31 -05:00
|
|
|
/**
|
|
|
|
* @param state the Menu handle
|
|
|
|
*
|
|
|
|
* @returns returns if this state is completed.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
unsigned int rofi_view_get_completed(const RofiViewState *state);
|
2016-11-15 15:54:31 -05:00
|
|
|
/**
|
|
|
|
* @param state the Menu handle
|
|
|
|
*
|
|
|
|
* @returns the raw user input.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
const char *rofi_view_get_user_input(const RofiViewState *state);
|
2016-02-08 12:16:16 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param state The Menu Handle
|
|
|
|
* @param selected_line The line to select.
|
|
|
|
*
|
|
|
|
* Select a line.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void rofi_view_set_selected_line(RofiViewState *state,
|
|
|
|
unsigned int selected_line);
|
2016-02-06 08:27:36 -05:00
|
|
|
|
2016-02-08 12:16:16 -05:00
|
|
|
/**
|
|
|
|
* @param state The Menu Handle
|
|
|
|
*
|
|
|
|
* Get the selected line.
|
|
|
|
*
|
|
|
|
* @returns the selected line or UINT32_MAX if none selected.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
unsigned int rofi_view_get_selected_line(const RofiViewState *state);
|
2016-02-08 12:16:16 -05:00
|
|
|
/**
|
|
|
|
* @param state The Menu Handle
|
|
|
|
*
|
|
|
|
* Restart the menu so it can be displayed again.
|
|
|
|
* Resets RofiViewState::quit and RofiViewState::retv.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void rofi_view_restart(RofiViewState *state);
|
2016-02-06 08:27:36 -05:00
|
|
|
|
2016-11-15 15:54:31 -05:00
|
|
|
/**
|
|
|
|
* @param state The handle to the view
|
2017-05-30 08:14:51 -04:00
|
|
|
* @param scope The scope of the action
|
|
|
|
* @param action The action
|
2016-11-15 15:54:31 -05:00
|
|
|
*
|
|
|
|
* @returns TRUE if action was handled.
|
|
|
|
*/
|
2021-10-28 02:33:12 -04:00
|
|
|
gboolean rofi_view_check_action(RofiViewState *state, BindingsScope scope,
|
|
|
|
guint action);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param state The handle to the view
|
|
|
|
* @param scope The scope of the action
|
|
|
|
* @param action The action
|
|
|
|
*/
|
|
|
|
void rofi_view_trigger_action(RofiViewState *state, BindingsScope scope,
|
|
|
|
guint action);
|
2016-05-07 05:31:00 -04:00
|
|
|
|
2016-02-08 12:16:16 -05:00
|
|
|
/**
|
|
|
|
* @param state The handle to the view
|
|
|
|
*
|
|
|
|
* Free's the memory allocated for this handle.
|
|
|
|
* After a call to this function, state is invalid and can no longer be used.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void rofi_view_free(RofiViewState *state);
|
2016-02-08 12:16:16 -05:00
|
|
|
/** @} */
|
|
|
|
/**
|
|
|
|
* @defgroup ViewGlobal ViewGlobal
|
|
|
|
* @ingroup View
|
|
|
|
*
|
|
|
|
* Global menu view functions.
|
|
|
|
* These do not work on the view itself but modifies the global state.
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current active view Handle.
|
|
|
|
*
|
|
|
|
* @returns the active view handle or NULL
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
RofiViewState *rofi_view_get_active(void);
|
2016-02-08 12:16:16 -05:00
|
|
|
|
|
|
|
/**
|
2020-09-13 15:56:25 -04:00
|
|
|
* @param state the new active view handle.
|
2016-02-08 12:16:16 -05:00
|
|
|
*
|
2020-09-13 15:56:25 -04:00
|
|
|
* Set the current active view Handle, If NULL passed a queued view is popped
|
|
|
|
* from stack.
|
2016-02-08 12:16:16 -05:00
|
|
|
*
|
|
|
|
*/
|
2020-09-13 15:56:25 -04:00
|
|
|
|
2021-08-19 07:34:01 -04:00
|
|
|
void rofi_view_set_active(RofiViewState *state);
|
2016-02-08 03:03:11 -05:00
|
|
|
|
2020-09-13 15:56:25 -04:00
|
|
|
/**
|
|
|
|
* @param state remove view handle.
|
|
|
|
*
|
|
|
|
* remove state handle from queue, if current view, pop view from
|
|
|
|
* stack.
|
|
|
|
*
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void rofi_view_remove_active(RofiViewState *state);
|
2016-02-08 03:03:11 -05:00
|
|
|
/**
|
|
|
|
* @param msg The error message to show.
|
|
|
|
* @param markup The error message uses pango markup.
|
|
|
|
*
|
|
|
|
* The error message to show.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
int rofi_view_error_dialog(const char *msg, int markup);
|
2016-02-08 12:16:16 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Queue a redraw.
|
|
|
|
* This triggers a X11 Expose Event.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void rofi_view_queue_redraw(void);
|
2016-02-08 12:16:16 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Cleanup internal data of the view.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void rofi_view_cleanup(void);
|
2016-02-08 12:16:16 -05:00
|
|
|
|
2016-10-14 02:47:21 -04:00
|
|
|
/**
|
|
|
|
* @param state The handle to the view
|
|
|
|
*
|
|
|
|
* Get the mode currently displayed by the view.
|
|
|
|
*
|
|
|
|
* @returns the mode currently displayed by the view
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
Mode *rofi_view_get_mode(RofiViewState *state);
|
2016-10-14 02:47:21 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unmap the current view.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void rofi_view_hide(void);
|
2016-10-14 02:47:21 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicate the current view needs to reload its data.
|
|
|
|
* This can only be done when *more* information is available.
|
2016-10-14 10:46:54 -04:00
|
|
|
*
|
2016-10-14 02:47:21 -04:00
|
|
|
* The reloading happens 'lazy', multiple calls might be handled at once.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void rofi_view_reload(void);
|
2016-10-14 02:47:21 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param state The handle to the view
|
|
|
|
* @param mode The new mode to display
|
2016-10-14 10:46:54 -04:00
|
|
|
*
|
2016-10-14 02:47:21 -04:00
|
|
|
* Change the current view to show a different mode.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void rofi_view_switch_mode(RofiViewState *state, Mode *mode);
|
2016-10-14 02:47:21 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param state The handle to the view
|
|
|
|
* @param text An UTF-8 encoded character array with the text to overlay.
|
2016-10-14 10:46:54 -04:00
|
|
|
*
|
2016-10-14 02:47:21 -04:00
|
|
|
* Overlays text over the current view. Passing NULL for text hides the overlay.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void rofi_view_set_overlay(RofiViewState *state, const char *text);
|
2016-10-14 02:47:21 -04:00
|
|
|
|
2016-12-12 02:52:27 -05:00
|
|
|
/**
|
|
|
|
* @param state The handle to the view.
|
|
|
|
*
|
|
|
|
* Clears the user entry box, set selected to 0.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void rofi_view_clear_input(RofiViewState *state);
|
2016-12-12 02:52:27 -05:00
|
|
|
|
2016-10-14 02:47:21 -04:00
|
|
|
/**
|
|
|
|
* @param menu_flags The state of the new window.
|
|
|
|
*
|
|
|
|
* Creates the internal 'Cached' window that gets reused between views.
|
2016-11-15 15:54:31 -05:00
|
|
|
* TODO: Internal call to view exposed.
|
2016-10-14 02:47:21 -04:00
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void __create_window(MenuFlags menu_flags);
|
2020-09-13 15:56:25 -04:00
|
|
|
|
2016-12-20 03:25:56 -05:00
|
|
|
/**
|
|
|
|
* Get the handle of the main window.
|
|
|
|
*
|
|
|
|
* @returns the xcb_window_t for rofi's view or XCB_WINDOW_NONE.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
xcb_window_t rofi_view_get_window(void);
|
2016-02-06 08:27:36 -05:00
|
|
|
/** @} */
|
2016-10-14 02:47:21 -04:00
|
|
|
|
2021-08-20 08:54:34 -04:00
|
|
|
/**
|
2016-02-10 13:40:19 -05:00
|
|
|
* @defgroup ViewThreadPool ViewThreadPool
|
|
|
|
* @ingroup View
|
|
|
|
*
|
2021-08-19 07:34:01 -04:00
|
|
|
* The view can (optionally) keep a set of worker threads around to parallize
|
|
|
|
* work. This includes filtering and sorting.
|
2016-02-10 13:40:19 -05:00
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*/
|
2016-10-14 02:47:21 -04:00
|
|
|
/**
|
|
|
|
* Initialize the threadpool
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void rofi_view_workers_initialize(void);
|
2016-08-30 02:14:53 -04:00
|
|
|
/**
|
2016-10-14 02:47:21 -04:00
|
|
|
* Stop all threads and free the resources used by the threadpool
|
2016-08-30 02:14:53 -04:00
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void rofi_view_workers_finalize(void);
|
2017-01-03 13:23:09 -05:00
|
|
|
|
|
|
|
/**
|
2021-05-05 16:39:03 -04:00
|
|
|
* @param width the width of the monitor.
|
|
|
|
* @param height the height of the monitor.
|
|
|
|
*
|
2017-01-03 13:23:09 -05:00
|
|
|
* Return the current monitor workarea.
|
|
|
|
*
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void rofi_view_get_current_monitor(int *width, int *height);
|
2017-04-27 16:59:14 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Takes a screenshot.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void rofi_capture_screenshot(void);
|
2019-08-10 06:02:49 -04:00
|
|
|
/**
|
|
|
|
* Set the window title.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void rofi_view_set_window_title(const char *title);
|
2020-04-16 17:31:43 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* set ellipsize mode to start.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void rofi_view_ellipsize_start(RofiViewState *state);
|
2022-11-08 13:18:45 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param new_x New XIM window x pos
|
|
|
|
* @param new_y New XIM window y pos
|
|
|
|
*
|
|
|
|
* Updates the XIM window position to new_x and new_y, relative to the
|
|
|
|
* main_window
|
|
|
|
*/
|
|
|
|
gboolean rofi_set_im_window_pos(int new_x, int new_y);
|
|
|
|
|
2021-05-05 16:39:03 -04:00
|
|
|
/** @} */
|
2016-02-06 08:27:36 -05:00
|
|
|
#endif
|