2
0
Fork 0
mirror of https://github.com/lbonn/rofi synced 2025-03-01 05:37:08 +00:00

Merge commit '954fc728b29d3c63a09a84870f29b57640062966' into wayland

Formatting changes only
This commit is contained in:
lbonn 2021-09-06 13:01:37 +02:00
commit 6baa463264
73 changed files with 17651 additions and 17392 deletions

View file

@ -1,6 +1,7 @@
#ifndef ROFI_INCLUDE_CSS_COLORS_H
#define ROFI_INCLUDE_CSS_COLORS_H
#include <stdint.h>
/**
* @defgroup CSSCOLORS CssColors
* @ingroup HELPERS
@ -13,16 +14,16 @@
/**
* Structure of colors.
*/
typedef struct CSSColor
{
/** CSS name of the color. */
char *name;
/** BGRA 8 bit color components. */
uint8_t b, g, r, a;
}CSSColor;
typedef struct CSSColor {
/** CSS name of the color. */
char *name;
/** BGRA 8 bit color components. */
uint8_t b, g, r, a;
} CSSColor;
/**
* Array with all the named colors. Of type #CSSColor, there are #num_CSSColors items in this array.
* Array with all the named colors. Of type #CSSColor, there are #num_CSSColors
* items in this array.
*/
extern const CSSColor CSSColors[];
/**

View file

@ -27,6 +27,7 @@
#ifndef ROFI_DIALOG_COMBI_H
#define ROFI_DIALOG_COMBI_H
#include "mode.h"
/**
* @defgroup COBIMode Combi

View file

@ -35,13 +35,13 @@
* List of available dialogs.
*/
#include "dialogs/run.h"
#include "dialogs/ssh.h"
#include "dialogs/drun.h"
#include "dialogs/dmenu.h"
#include "dialogs/script.h"
#include "dialogs/window.h"
#include "dialogs/combi.h"
#include "dialogs/help-keys.h"
#include "dialogs/dmenu.h"
#include "dialogs/drun.h"
#include "dialogs/filebrowser.h"
#include "dialogs/help-keys.h"
#include "dialogs/run.h"
#include "dialogs/script.h"
#include "dialogs/ssh.h"
#include "dialogs/window.h"
#endif // ROFI_DIALOGS_DIALOGS_H

View file

@ -40,12 +40,12 @@
*
* @returns TRUE if script was successful.
*/
int dmenu_switcher_dialog ( void );
int dmenu_switcher_dialog(void);
/**
* Print dmenu mode commandline options to stdout, for use in help menu.
*/
void print_dmenu_options ( void );
void print_dmenu_options(void);
/**@}*/
#endif // ROFI_DIALOG_DMENU_H

View file

@ -1,22 +1,21 @@
#ifndef ROFI_DIALOGS_DMENU_SCRIPT_SHARED_H
#define ROFI_DIALOGS_DMENU_SCRIPT_SHARED_H
typedef struct
{
/** Entry content. (visible part) */
char *entry;
/** Icon name to display. */
char *icon_name;
/** Async icon fetch handler. */
uint32_t icon_fetch_uid;
/** Hidden meta keywords. */
char *meta;
typedef struct {
/** Entry content. (visible part) */
char *entry;
/** Icon name to display. */
char *icon_name;
/** Async icon fetch handler. */
uint32_t icon_fetch_uid;
/** Hidden meta keywords. */
char *meta;
/** info */
char *info;
/** info */
char *info;
/** non-selectable */
gboolean nonselectable;
/** non-selectable */
gboolean nonselectable;
} DmenuScriptEntry;
/**
* @param sw Unused
@ -26,5 +25,7 @@ typedef struct
*
* Updates entry with the parsed values from buffer.
*/
void dmenuscript_parse_entry_extras ( G_GNUC_UNUSED Mode *sw, DmenuScriptEntry *entry, char *buffer, size_t length );
void dmenuscript_parse_entry_extras(G_GNUC_UNUSED Mode *sw,
DmenuScriptEntry *entry, char *buffer,
size_t length);
#endif // ROFI_DIALOGS_DMENU_SCRIPT_SHARED_H

View file

@ -27,13 +27,15 @@
#ifndef ROFI_DIALOG_DRUN_H
#define ROFI_DIALOG_DRUN_H
#include "mode.h"
#include "mode.h"
/**
* @defgroup DRUNMode DRun
* @ingroup MODES
* @{
*/
#include <config.h>
#ifdef ENABLE_DRUN
/** #Mode object representing the desktop menu run dialog. */
extern Mode drun_mode;

View file

@ -27,7 +27,7 @@
#ifndef ROFI_DIALOG_FILE_BROWSER_H
#define ROFI_DIALOG_FILE_BROWSER_H
#include "mode.h"
/**
* @defgroup FileBrowserMode FileBrowser
* @ingroup MODES
@ -42,7 +42,7 @@ extern Mode file_browser_mode;
* Create a new filebrowser.
* @returns a new filebrowser structure.
*/
Mode *create_new_file_browser ( void );
Mode *create_new_file_browser(void);
/**
* @param sw Mode object.
* @param mretv return value passed in.
@ -52,6 +52,7 @@ Mode *create_new_file_browser ( void );
*
* @returns the state the user selected.
*/
ModeMode file_browser_mode_completer ( Mode *sw, int mretv, char **input, unsigned int selected_line, char **path );
ModeMode file_browser_mode_completer(Mode *sw, int mretv, char **input,
unsigned int selected_line, char **path);
/**@}*/
#endif // ROFI_DIALOG_FILE_BROWSER_H

View file

@ -27,7 +27,9 @@
#ifndef ROFI_DIALOG_HELPKEYS_H
#define ROFI_DIALOG_HELPKEYS_H
#include "mode.h"
#include "mode.h"
/**
* @defgroup HELPKEYSMode KeysHelp
* @ingroup MODES

View file

@ -27,6 +27,7 @@
#ifndef ROFI_DIALOG_RUN_H
#define ROFI_DIALOG_RUN_H
#include "mode.h"
/**
* @defgroup RUNMode Run

View file

@ -27,6 +27,9 @@
#ifndef ROFI_DIALOG_SCRIPT_H
#define ROFI_DIALOG_SCRIPT_H
#include "mode.h"
#include "mode.h"
/**
* @defgroup SCRIPTMode Script
@ -42,7 +45,7 @@
*
* @returns NULL when it fails, a newly allocated ScriptOptions when successful.
*/
Mode *script_switcher_parse_setup ( const char *str );
Mode *script_switcher_parse_setup(const char *str);
/**
* @param token The modi str to check
@ -51,6 +54,6 @@ Mode *script_switcher_parse_setup ( const char *str );
*
* @returns true when valid.
*/
gboolean script_switcher_is_valid ( const char *token );
gboolean script_switcher_is_valid(const char *token);
/**@}*/
#endif // ROFI_DIALOG_SCRIPT_H

View file

@ -27,14 +27,14 @@
#ifndef ROFI_DIALOG_SSH_H
#define ROFI_DIALOG_SSH_H
#include "mode.h"
/**
* @defgroup SSHMode SSH
* @ingroup MODES
*
* SSH Mode, returns a list of known SSH hosts the user can log into.
* It does this by parsing the SSH config file and optional the known host and host list
* It also keeps history of the last chosen hosts.
* It does this by parsing the SSH config file and optional the known host and
* host list It also keeps history of the last chosen hosts.
*
* This mode uses the following options from the #config object:
* * #Settings::ssh_command

View file

@ -27,6 +27,9 @@
#ifndef ROFI_DIALOG_WINDOW_H
#define ROFI_DIALOG_WINDOW_H
#include "mode.h"
#include "mode.h"
/**
* @defgroup WINDOWMode Window
@ -34,7 +37,6 @@
*
* @{
*/
#include <config.h>
#ifdef WINDOW_MODE
extern Mode window_mode;

View file

@ -28,28 +28,30 @@
#ifndef ROFI_DISPLAY_INTERNAL_H
#define ROFI_DISPLAY_INTERNAL_H
#include <glib.h>
#include "helper.h"
#include "nkutils-bindings.h"
#include <glib.h>
struct _workarea;
struct _view_proxy;
typedef struct _display_proxy {
gboolean (*setup) ( GMainLoop *main_loop, NkBindings *bindings );
gboolean (*late_setup) ( void );
void (*early_cleanup) ( void );
void (*cleanup) ( void );
void (*dump_monitor_layout) ( void );
void (*startup_notification) ( RofiHelperExecuteContext *context, GSpawnChildSetupFunc *child_setup, gpointer *user_data );
int (*monitor_active) ( struct _workarea *mon );
gboolean (*setup)(GMainLoop *main_loop, NkBindings *bindings);
gboolean (*late_setup)(void);
void (*early_cleanup)(void);
void (*cleanup)(void);
void (*dump_monitor_layout)(void);
void (*startup_notification)(RofiHelperExecuteContext *context,
GSpawnChildSetupFunc *child_setup,
gpointer *user_data);
int (*monitor_active)(struct _workarea *mon);
void (*set_input_focus) ( guint window );
void (*revert_input_focus) ( void );
void (*set_input_focus)(guint window);
void (*revert_input_focus)(void);
guint (*scale) ( void );
guint (*scale)(void);
const struct _view_proxy* (*view) ( void );
const struct _view_proxy *(*view)(void);
} display_proxy;
#endif

View file

@ -28,43 +28,42 @@
#ifndef ROFI_DISPLAY_H
#define ROFI_DISPLAY_H
#include <glib.h>
#include "helper.h"
#include "nkutils-bindings.h"
#include <glib.h>
/**
* Structure describing a workarea/monitor.
*/
typedef struct _workarea
{
/** numeric monitor id. */
int monitor_id;
/** if monitor is set as primary monitor. */
int primary;
/** Horizontal location (in pixels) of the monitor. */
int x;
/** Vertical location (in pixels) of the monitor. */
int y;
/** Width of the monitor. */
int w;
/** Height of the monitor */
int h;
int mw, mh;
/** Output name of the monitor, e.g. eDP1 or VGA-1 */
char *name;
/** Pointer to next monitor */
struct _workarea *next;
typedef struct _workarea {
/** numeric monitor id. */
int monitor_id;
/** if monitor is set as primary monitor. */
int primary;
/** Horizontal location (in pixels) of the monitor. */
int x;
/** Vertical location (in pixels) of the monitor. */
int y;
/** Width of the monitor. */
int w;
/** Height of the monitor */
int h;
int mw, mh;
/** Output name of the monitor, e.g. eDP1 or VGA-1 */
char *name;
/** Pointer to next monitor */
struct _workarea *next;
} workarea;
struct _display_proxy;
/* Implementations */
extern struct _display_proxy * const xcb_proxy;
extern struct _display_proxy *const xcb_proxy;
#ifdef ENABLE_WAYLAND
extern struct _display_proxy * const wayland_proxy;
extern struct _display_proxy *const wayland_proxy;
#endif
void display_init ( const struct _display_proxy *disp_in );
void display_init(const struct _display_proxy *disp_in);
/**
* @param mon workarea to be filled in.
@ -73,7 +72,7 @@ void display_init ( const struct _display_proxy *disp_in );
*
* @returns TRUE if monitor is found, FALSE if no monitor could be detected.
*/
int monitor_active ( workarea *mon );
int monitor_active(workarea *mon);
/**
* @param main_loop The GMainLoop
@ -83,29 +82,29 @@ int monitor_active ( workarea *mon );
*
* @returns Whether the setup succeeded or not
*/
gboolean display_setup ( GMainLoop *main_loop, NkBindings *bindings );
gboolean display_setup(GMainLoop *main_loop, NkBindings *bindings);
/**
* Do some late setup of the display backend
*
* @returns Whether the setup succeeded or not
*/
gboolean display_late_setup ( void );
gboolean display_late_setup(void);
/**
* Do some early cleanup, like unmapping the surface
*/
void display_early_cleanup ( void );
void display_early_cleanup(void);
/**
* Cleanup any remaining display related stuff
*/
void display_cleanup ( void );
void display_cleanup(void);
/**
* Dumps the display layout for -help output
*/
void display_dump_monitor_layout ( void );
void display_dump_monitor_layout(void);
/**
* @param context The startup notification context for the application to launch
@ -114,11 +113,13 @@ void display_dump_monitor_layout ( void );
*
* Provides the needed child setup function
*/
void display_startup_notification ( RofiHelperExecuteContext *context, GSpawnChildSetupFunc *child_setup, gpointer *user_data );
void display_startup_notification(RofiHelperExecuteContext *context,
GSpawnChildSetupFunc *child_setup,
gpointer *user_data);
void display_set_input_focus ( guint w );
void display_revert_input_focus ( void );
void display_set_input_focus(guint w);
void display_revert_input_focus(void);
guint display_scale ( void );
guint display_scale(void);
#endif

View file

@ -27,8 +27,8 @@
#ifndef ROFI_HELPER_THEME_H
#define ROFI_HELPER_THEME_H
#include <pango/pango.h>
#include "theme.h"
#include <pango/pango.h>
/**
* @defgroup HELPERS Helpers
* @{
@ -39,11 +39,15 @@
* @param input The input string to find the matches on
* @param retv The Attribute list to update with matches
*
* Creates a set of pango attributes highlighting the matches found in the input string.
* Creates a set of pango attributes highlighting the matches found in the input
* string.
*
* @returns the updated retv list.
*/
PangoAttrList *helper_token_match_get_pango_attr ( RofiHighlightColorStyle th, rofi_int_matcher **tokens, const char *input, PangoAttrList *retv );
PangoAttrList *helper_token_match_get_pango_attr(RofiHighlightColorStyle th,
rofi_int_matcher **tokens,
const char *input,
PangoAttrList *retv);
/**
* @param pfd Pango font description to validate.
@ -51,6 +55,6 @@ PangoAttrList *helper_token_match_get_pango_attr ( RofiHighlightColorStyle th, r
*
* @returns true if font is valid.
*/
gboolean helper_validate_font ( PangoFontDescription *pfd, const char *font );
gboolean helper_validate_font(PangoFontDescription *pfd, const char *font);
/** @} */
#endif // ROFI_HELPER_THEME_H

View file

@ -27,8 +27,8 @@
#ifndef ROFI_HELPER_H
#define ROFI_HELPER_H
#include <cairo.h>
#include "rofi-types.h"
#include <cairo.h>
G_BEGIN_DECLS
/**
@ -51,7 +51,7 @@ G_BEGIN_DECLS
*
* @returns TRUE when successful, FALSE when failed.
*/
int helper_parse_setup ( char * string, char ***output, int *length, ... );
int helper_parse_setup(char *string, char ***output, int *length, ...);
/**
* @param input The input string.
@ -61,14 +61,14 @@ int helper_parse_setup ( char * string, char ***output, int *length, ... );
*
* @returns a newly allocated array of matching objects
*/
rofi_int_matcher **helper_tokenize ( const char *input, int case_sensitive );
rofi_int_matcher **helper_tokenize(const char *input, int case_sensitive);
/**
* @param tokens Array of regex objects
*
* Frees the array of matching objects.
*/
void helper_tokenize_free ( rofi_int_matcher ** tokens );
void helper_tokenize_free(rofi_int_matcher **tokens);
/**
* @param key The key to search for
@ -79,7 +79,7 @@ void helper_tokenize_free ( rofi_int_matcher ** tokens );
*
* @returns TRUE if key was found and val was set.
*/
int find_arg_char ( const char * const key, char *val );
int find_arg_char(const char *const key, char *val);
/**
* @param key The key to search for
@ -89,7 +89,7 @@ int find_arg_char ( const char * const key, char *val );
*
* @returns TRUE if key was found and val was set.
*/
int find_arg_uint ( const char * const key, unsigned int *val );
int find_arg_uint(const char *const key, unsigned int *val);
/**
* @param key The key to search for
@ -99,7 +99,7 @@ int find_arg_uint ( const char * const key, unsigned int *val );
*
* @returns TRUE if key was found and val was set.
*/
int find_arg_int ( const char * const key, int *val );
int find_arg_int(const char *const key, int *val);
/**
* @param key The key to search for
@ -109,7 +109,7 @@ int find_arg_int ( const char * const key, int *val );
*
* @returns TRUE if key was found and val was set.
*/
int find_arg_str ( const char * const key, char** val );
int find_arg_str(const char *const key, char **val);
/**
* @param key The key to search for
@ -118,7 +118,7 @@ int find_arg_str ( const char * const key, char** val );
*
* @returns str vector. user should free array.
*/
const char ** find_arg_strv ( const char *const key );
const char **find_arg_strv(const char *const key);
/**
* @param key The key to search for
*
@ -126,7 +126,7 @@ const char ** find_arg_strv ( const char *const key );
*
* @returns return position of string or -1 if not found.
*/
int find_arg ( const char * const key );
int find_arg(const char *const key);
/**
* @param tokens List of (input) tokens to match.
@ -136,36 +136,37 @@ int find_arg ( const char * const key );
*
* @returns TRUE when matches, FALSE otherwise
*/
int helper_token_match ( rofi_int_matcher * const *tokens, const char *input );
int helper_token_match(rofi_int_matcher *const *tokens, const char *input);
/**
* @param cmd The command to execute.
*
* Execute cmd using config.run_command and outputs the result (stdout) to the opened file
* descriptor.
* Execute cmd using config.run_command and outputs the result (stdout) to the
* opened file descriptor.
*
* @returns a valid file descriptor on success, or -1 on failure.
*/
int execute_generator ( const char * cmd ) __attribute__( ( nonnull ) );
int execute_generator(const char *cmd) __attribute__((nonnull));
/**
* @param pidfile The pidfile to create.
*
* returns file descriptor (or -1 when failed)
*/
int create_pid_file ( const char *pidfile );
int create_pid_file(const char *pidfile);
/**
* Remove pid file
*/
void remove_pid_file ( int fd );
void remove_pid_file(int fd);
/**
* Do some input validation, especially the first few could break things.
* It is good to catch them beforehand.
*
* This functions exits the program with 1 when it finds an invalid configuration.
* This functions exits the program with 1 when it finds an invalid
* configuration.
*/
int config_sanity_check ( void );
int config_sanity_check(void);
/**
* @param arg string to parse.
@ -174,7 +175,7 @@ int config_sanity_check ( void );
*
* @returns character.
*/
char helper_parse_char ( const char *arg );
char helper_parse_char(const char *arg);
/**
* @param argc number of arguments.
@ -182,7 +183,7 @@ char helper_parse_char ( const char *arg );
*
* Set the application arguments.
*/
void cmd_set_arguments ( int argc, char **argv );
void cmd_set_arguments(int argc, char **argv);
/**
* @param input The path to expand
@ -191,7 +192,7 @@ void cmd_set_arguments ( int argc, char **argv );
*
* @returns path
*/
char *rofi_expand_path ( const char *input );
char *rofi_expand_path(const char *input);
/**
* @param needle The string to find match weight off
@ -203,17 +204,19 @@ char *rofi_expand_path ( const char *input );
*
* @returns the levenshtein distance between needle and haystack
*/
unsigned int levenshtein ( const char *needle, const glong needlelen, const char *haystack, const glong haystacklen );
unsigned int levenshtein(const char *needle, const glong needlelen,
const char *haystack, const glong haystacklen);
/**
* @param data the unvalidated character array holding possible UTF-8 data
* @param length the length of the data array
*
* Convert string to valid utf-8, replacing invalid parts with replacement character.
* Convert string to valid utf-8, replacing invalid parts with replacement
* character.
*
* @returns the converted UTF-8 string
*/
char * rofi_force_utf8 ( const gchar *data, ssize_t length );
char *rofi_force_utf8(const gchar *data, ssize_t length);
/**
* @param input the char array holding latin text
@ -223,7 +226,7 @@ char * rofi_force_utf8 ( const gchar *data, ssize_t length );
*
* @return the UTF-8 representation of data
*/
char * rofi_latin_to_utf8_strdup ( const char *input, gssize length );
char *rofi_latin_to_utf8_strdup(const char *input, gssize length);
/**
* @param text the string to escape
@ -232,7 +235,7 @@ char * rofi_latin_to_utf8_strdup ( const char *input, gssize length );
*
* @return the escaped string
*/
gchar *rofi_escape_markup ( gchar *text );
gchar *rofi_escape_markup(gchar *text);
/**
* @param pattern The user input to match against.
@ -240,28 +243,35 @@ gchar *rofi_escape_markup ( gchar *text );
* @param str The input to match against pattern.
* @param slen Length of str.
*
* rofi_scorer_fuzzy_evaluate implements a global sequence alignment algorithm to find the maximum accumulated score by
* aligning `pattern` to `str`. It applies when `pattern` is a subsequence of `str`.
* rofi_scorer_fuzzy_evaluate implements a global sequence alignment algorithm
* to find the maximum accumulated score by aligning `pattern` to `str`. It
* applies when `pattern` is a subsequence of `str`.
*
* Scoring criteria
* - Prefer matches at the start of a word, or the start of subwords in CamelCase/camelCase/camel123 words. See WORD_START_SCORE/CAMEL_SCORE.
* - Prefer matches at the start of a word, or the start of subwords in
* CamelCase/camelCase/camel123 words. See WORD_START_SCORE/CAMEL_SCORE.
* - Non-word characters matter. See NON_WORD_SCORE.
* - The first characters of words of `pattern` receive bonus because they usually have more significance than the rest.
* See PATTERN_START_MULTIPLIER/PATTERN_NON_START_MULTIPLIER.
* - Superfluous characters in `str` will reduce the score (gap penalty). See GAP_SCORE.
* - Prefer early occurrence of the first character. See LEADING_GAP_SCORE/GAP_SCORE.
* - The first characters of words of `pattern` receive bonus because they
* usually have more significance than the rest. See
* PATTERN_START_MULTIPLIER/PATTERN_NON_START_MULTIPLIER.
* - Superfluous characters in `str` will reduce the score (gap penalty). See
* GAP_SCORE.
* - Prefer early occurrence of the first character. See
* LEADING_GAP_SCORE/GAP_SCORE.
*
* The recurrence of the dynamic programming:
* dp[i][j]: maximum accumulated score by aligning pattern[0..i] to str[0..j]
* dp[0][j] = leading_gap_penalty(0, j) + score[j]
* dp[i][j] = max(dp[i-1][j-1] + CONSECUTIVE_SCORE, max(dp[i-1][k] + gap_penalty(k+1, j) + score[j] : k < j))
* dp[i][j] = max(dp[i-1][j-1] + CONSECUTIVE_SCORE, max(dp[i-1][k] +
* gap_penalty(k+1, j) + score[j] : k < j))
*
* The first dimension can be suppressed since we do not need a matching scheme, which reduces the space complexity from
* O(N*M) to O(M)
* The first dimension can be suppressed since we do not need a matching
* scheme, which reduces the space complexity from O(N*M) to O(M)
*
* @returns the sorting weight.
*/
int rofi_scorer_fuzzy_evaluate ( const char *pattern, glong plen, const char *str, glong slen );
int rofi_scorer_fuzzy_evaluate(const char *pattern, glong plen, const char *str,
glong slen);
/*@}*/
/**
@ -271,31 +281,31 @@ int rofi_scorer_fuzzy_evaluate ( const char *pattern, glong plen, const char *st
*
* Compares the `G_NORMALIZE_ALL_COMPOSE` forms of the two strings.
*
* @returns less than, equal to, or greater than zero if the first `n` characters (not bytes) of `a`
* are found, respectively, to be less than, to match, or be greater than the first `n`
* characters (not bytes) of `b`.
* @returns less than, equal to, or greater than zero if the first `n`
* characters (not bytes) of `a` are found, respectively, to be less than, to
* match, or be greater than the first `n` characters (not bytes) of `b`.
*/
int utf8_strncmp ( const char *a, const char* b, size_t n ) __attribute__( ( nonnull ( 1, 2 ) ) );
int utf8_strncmp(const char *a, const char *b, size_t n)
__attribute__((nonnull(1, 2)));
/**
* The startup notification context of the application to launch
*/
typedef struct
{
/** The name of the application */
const gchar *name;
/** The binary name of the application */
const gchar *binary;
/** The description of the launch */
const gchar *description;
/** The icon name of the application */
const gchar *icon;
/** The application id (desktop file with the .desktop suffix) */
const gchar *app_id;
/** The window manager class of the application */
const gchar *wmclass;
/** The command we run */
const gchar *command;
typedef struct {
/** The name of the application */
const gchar *name;
/** The binary name of the application */
const gchar *binary;
/** The description of the launch */
const gchar *description;
/** The icon name of the application */
const gchar *icon;
/** The application id (desktop file with the .desktop suffix) */
const gchar *app_id;
/** The window manager class of the application */
const gchar *wmclass;
/** The command we run */
const gchar *command;
} RofiHelperExecuteContext;
/**
@ -309,7 +319,9 @@ typedef struct
*
* @returns TRUE when successful, FALSE when failed.
*/
gboolean helper_execute ( const char *wd, char **args, const char *error_precmd, const char *error_cmd, RofiHelperExecuteContext *context );
gboolean helper_execute(const char *wd, char **args, const char *error_precmd,
const char *error_cmd,
RofiHelperExecuteContext *context);
/**
* @param wd The work directory (optional)
@ -322,7 +334,9 @@ gboolean helper_execute ( const char *wd, char **args, const char *error_precmd,
*
* @returns FALSE On failure, TRUE on success
*/
gboolean helper_execute_command ( const char *wd, const char *cmd, gboolean run_in_term, RofiHelperExecuteContext *context );
gboolean helper_execute_command(const char *wd, const char *cmd,
gboolean run_in_term,
RofiHelperExecuteContext *context);
/**
* @param file The file path
@ -331,7 +345,8 @@ gboolean helper_execute_command ( const char *wd, const char *cmd, gboolean run_
*
* @returns a cairo surface from an svg path
*/
cairo_surface_t *cairo_image_surface_create_from_svg ( const gchar* file, int height );
cairo_surface_t *cairo_image_surface_create_from_svg(const gchar *file,
int height);
/**
* Ranges.
@ -344,7 +359,7 @@ cairo_surface_t *cairo_image_surface_create_from_svg ( const gchar* file, int he
*
* ranges
*/
void parse_ranges ( char *input, rofi_range_pair **list, unsigned int *length );
void parse_ranges(char *input, rofi_range_pair **list, unsigned int *length);
/**
* @param format The format string used. See below for possible syntax.
@ -361,25 +376,28 @@ void parse_ranges ( char *input, rofi_range_pair **list, unsigned int *length );
* * f: Print the entered filter.
* * F: Print the entered filter, quoted
*
* This functions outputs the formatted string to stdout, appends a newline (\n) character and
* calls flush on the file descriptor.
* This functions outputs the formatted string to stdout, appends a newline (\n)
* character and calls flush on the file descriptor.
*/
void rofi_output_formatted_line ( const char *format, const char *string, int selected_line, const char *filter );
void rofi_output_formatted_line(const char *format, const char *string,
int selected_line, const char *filter);
/**
* @param string The string with elements to be replaced
* @param ... Set of {key}, value that will be replaced, terminated by a NULL
* @param ... Set of {key}, value that will be replaced, terminated by a
* NULL
*
* Items {key} are replaced by the value if '{key}' is passed as key/value pair, otherwise removed from string.
* If the {key} is in between [] all the text between [] are removed if {key}
* is not found. Otherwise key is replaced and [ & ] removed.
* Items {key} are replaced by the value if '{key}' is passed as key/value pair,
* otherwise removed from string. If the {key} is in between [] all the text
* between [] are removed if {key} is not found. Otherwise key is replaced and [
* & ] removed.
*
* This allows for optional replacement, f.e. '{ssh-client} [-t {title}] -e
* "{cmd}"' the '-t {title}' is only there if {title} is set.
*
* @returns a new string with the keys replaced.
*/
char *helper_string_replace_if_exists ( char * string, ... );
char *helper_string_replace_if_exists(char *string, ...);
/**
* @param file File name passed to option.
@ -387,9 +405,7 @@ char *helper_string_replace_if_exists ( char * string, ... );
*
* @returns path to theme or copy of filename if not found.
*/
char *helper_get_theme_path ( const char *file, const char *ext );
char *helper_get_theme_path(const char *file, const char *ext);
G_END_DECLS

View file

@ -48,7 +48,8 @@
* Sets the entry in the history, if it exists its use-count is incremented.
*
*/
void history_set ( const char *filename, const char *entry ) __attribute__( ( nonnull ) );
void history_set(const char *filename, const char *entry)
__attribute__((nonnull));
/**
* @param filename The filename of the history cache.
@ -56,7 +57,8 @@ void history_set ( const char *filename, const char *entry ) __attribute__( ( no
*
* Removes the entry from the history.
*/
void history_remove ( const char *filename, const char *entry ) __attribute__( ( nonnull ) );
void history_remove(const char *filename, const char *entry)
__attribute__((nonnull));
/**
* @param filename The filename of the history cache.
@ -65,7 +67,8 @@ void history_remove ( const char *filename, const char *entry ) __attribute__( (
* Gets the entries in the list (in order of usage)
* @returns a list of entries length long. (and NULL terminated).
*/
char ** history_get_list ( const char *filename, unsigned int * length ) __attribute__( ( nonnull ) );
char **history_get_list(const char *filename, unsigned int *length)
__attribute__((nonnull));
/**@}*/
#endif // ROFI_HISTORY_H

View file

@ -28,6 +28,7 @@
#ifndef ROFI_KEYB_H
#define ROFI_KEYB_H
#include <glib.h>
#include "nkutils-bindings.h"
/**
@ -39,158 +40,153 @@
/**
* List of all scopes the mouse can interact on.
*/
typedef enum
{
SCOPE_GLOBAL,
SCOPE_MOUSE_LISTVIEW,
SCOPE_MOUSE_LISTVIEW_ELEMENT,
typedef enum {
SCOPE_GLOBAL,
SCOPE_MOUSE_LISTVIEW,
SCOPE_MOUSE_LISTVIEW_ELEMENT,
#define SCOPE_MIN_FIXED SCOPE_MOUSE_EDITBOX
SCOPE_MOUSE_EDITBOX,
SCOPE_MOUSE_SCROLLBAR,
SCOPE_MOUSE_MODE_SWITCHER,
#define SCOPE_MAX_FIXED SCOPE_MOUSE_MODE_SWITCHER
#define SCOPE_MIN_FIXED SCOPE_MOUSE_EDITBOX
SCOPE_MOUSE_EDITBOX,
SCOPE_MOUSE_SCROLLBAR,
SCOPE_MOUSE_MODE_SWITCHER,
#define SCOPE_MAX_FIXED SCOPE_MOUSE_MODE_SWITCHER
} BindingsScope;
/**
* List of all possible actions that can be triggered by a keybinding.
*/
typedef enum
{
/** Paste from primary clipboard */
PASTE_PRIMARY = 1,
/** Paste from secondary clipboard */
PASTE_SECONDARY,
/** Clear the entry box. */
CLEAR_LINE,
/** Move to front of text */
MOVE_FRONT,
/** Move to end of text */
MOVE_END,
/** Move on word back */
MOVE_WORD_BACK,
/** Move on word forward */
MOVE_WORD_FORWARD,
/** Move character back */
MOVE_CHAR_BACK,
/** Move character forward */
MOVE_CHAR_FORWARD,
/** Remove previous word */
REMOVE_WORD_BACK,
/** Remove next work */
REMOVE_WORD_FORWARD,
/** Remove next character */
REMOVE_CHAR_FORWARD,
/** Remove previous character */
REMOVE_CHAR_BACK,
/** Remove till EOL */
REMOVE_TO_EOL,
/** Remove till SOL */
REMOVE_TO_SOL,
/** Accept the current selected entry */
ACCEPT_ENTRY,
ACCEPT_ALT,
ACCEPT_CUSTOM,
ACCEPT_CUSTOM_ALT,
MODE_NEXT,
MODE_COMPLETE,
MODE_PREVIOUS,
TOGGLE_CASE_SENSITIVITY,
DELETE_ENTRY,
ROW_LEFT,
ROW_RIGHT,
ROW_UP,
ROW_DOWN,
ROW_TAB,
PAGE_PREV,
PAGE_NEXT,
ROW_FIRST,
ROW_LAST,
ROW_SELECT,
CANCEL,
CUSTOM_1,
CUSTOM_2,
CUSTOM_3,
CUSTOM_4,
CUSTOM_5,
CUSTOM_6,
CUSTOM_7,
CUSTOM_8,
CUSTOM_9,
CUSTOM_10,
CUSTOM_11,
CUSTOM_12,
CUSTOM_13,
CUSTOM_14,
CUSTOM_15,
CUSTOM_16,
CUSTOM_17,
CUSTOM_18,
CUSTOM_19,
SCREENSHOT,
CHANGE_ELLIPSIZE,
TOGGLE_SORT,
SELECT_ELEMENT_1,
SELECT_ELEMENT_2,
SELECT_ELEMENT_3,
SELECT_ELEMENT_4,
SELECT_ELEMENT_5,
SELECT_ELEMENT_6,
SELECT_ELEMENT_7,
SELECT_ELEMENT_8,
SELECT_ELEMENT_9,
SELECT_ELEMENT_10,
typedef enum {
/** Paste from primary clipboard */
PASTE_PRIMARY = 1,
/** Paste from secondary clipboard */
PASTE_SECONDARY,
/** Clear the entry box. */
CLEAR_LINE,
/** Move to front of text */
MOVE_FRONT,
/** Move to end of text */
MOVE_END,
/** Move on word back */
MOVE_WORD_BACK,
/** Move on word forward */
MOVE_WORD_FORWARD,
/** Move character back */
MOVE_CHAR_BACK,
/** Move character forward */
MOVE_CHAR_FORWARD,
/** Remove previous word */
REMOVE_WORD_BACK,
/** Remove next work */
REMOVE_WORD_FORWARD,
/** Remove next character */
REMOVE_CHAR_FORWARD,
/** Remove previous character */
REMOVE_CHAR_BACK,
/** Remove till EOL */
REMOVE_TO_EOL,
/** Remove till SOL */
REMOVE_TO_SOL,
/** Accept the current selected entry */
ACCEPT_ENTRY,
ACCEPT_ALT,
ACCEPT_CUSTOM,
ACCEPT_CUSTOM_ALT,
MODE_NEXT,
MODE_COMPLETE,
MODE_PREVIOUS,
TOGGLE_CASE_SENSITIVITY,
DELETE_ENTRY,
ROW_LEFT,
ROW_RIGHT,
ROW_UP,
ROW_DOWN,
ROW_TAB,
PAGE_PREV,
PAGE_NEXT,
ROW_FIRST,
ROW_LAST,
ROW_SELECT,
CANCEL,
CUSTOM_1,
CUSTOM_2,
CUSTOM_3,
CUSTOM_4,
CUSTOM_5,
CUSTOM_6,
CUSTOM_7,
CUSTOM_8,
CUSTOM_9,
CUSTOM_10,
CUSTOM_11,
CUSTOM_12,
CUSTOM_13,
CUSTOM_14,
CUSTOM_15,
CUSTOM_16,
CUSTOM_17,
CUSTOM_18,
CUSTOM_19,
SCREENSHOT,
CHANGE_ELLIPSIZE,
TOGGLE_SORT,
SELECT_ELEMENT_1,
SELECT_ELEMENT_2,
SELECT_ELEMENT_3,
SELECT_ELEMENT_4,
SELECT_ELEMENT_5,
SELECT_ELEMENT_6,
SELECT_ELEMENT_7,
SELECT_ELEMENT_8,
SELECT_ELEMENT_9,
SELECT_ELEMENT_10,
} KeyBindingAction;
/**
* Actions mouse can take on the ListView.
*/
typedef enum
{
SCROLL_LEFT = 1,
SCROLL_RIGHT,
SCROLL_DOWN,
SCROLL_UP,
typedef enum {
SCROLL_LEFT = 1,
SCROLL_RIGHT,
SCROLL_DOWN,
SCROLL_UP,
} MouseBindingListviewAction;
/**
* Actions mouse can take on the ListView element.
*/
typedef enum
{
SELECT_HOVERED_ENTRY = 1,
ACCEPT_HOVERED_ENTRY,
ACCEPT_HOVERED_CUSTOM,
typedef enum {
SELECT_HOVERED_ENTRY = 1,
ACCEPT_HOVERED_ENTRY,
ACCEPT_HOVERED_CUSTOM,
} MouseBindingListviewElementAction;
/**
* Default mouse actions.
*/
typedef enum
{
MOUSE_CLICK_DOWN = 1,
MOUSE_CLICK_UP,
MOUSE_DCLICK_DOWN,
MOUSE_DCLICK_UP,
typedef enum {
MOUSE_CLICK_DOWN = 1,
MOUSE_CLICK_UP,
MOUSE_DCLICK_DOWN,
MOUSE_DCLICK_UP,
} MouseBindingMouseDefaultAction;
/**
* Parse the keybindings.
* This should be called after the setting system is initialized.
*/
gboolean parse_keys_abe ( NkBindings *bindings );
gboolean parse_keys_abe(NkBindings *bindings);
/**
* Setup the keybindings
* This adds all the entries to the settings system.
*/
void setup_abe ( void );
void setup_abe(void);
/**
* @param name Don't have the name.
*
* @returns id, or UINT32_MAX if not found.
*/
guint key_binding_get_action_from_name ( const char *name );
guint key_binding_get_action_from_name(const char *name);
/**@}*/
#endif // ROFI_KEYB_H

View file

@ -31,27 +31,30 @@
G_BEGIN_DECLS
/** ABI version to check if loaded plugin is compatible. */
#define ABI_VERSION 0x00000006
#define ABI_VERSION 0x00000006
/**
* @param data Pointer to #Mode object.
*
* Mode free function.
*/
typedef void ( *_mode_free )( Mode *data );
typedef void (*_mode_free)(Mode *data);
/**
* @param sw The #Mode pointer
* @param selected_line The selected line
* @param state The state to display [out]
* @param attribute_list List of extra (pango) attribute to apply when displaying. [out][null]
* @param attribute_list List of extra (pango) attribute to apply when
* displaying. [out][null]
* @param get_entry if it should only return the state
*
* Get the value for displaying.
*
* @return the string and state for displaying.
*/
typedef char * ( *_mode_get_display_value )( const Mode *sw, unsigned int selected_line, int *state, GList **attribute_list, int get_entry );
typedef char *(*_mode_get_display_value)(const Mode *sw,
unsigned int selected_line, int *state,
GList **attribute_list, int get_entry);
/**
* @param sw The #Mode pointer
@ -61,7 +64,9 @@ typedef char * ( *_mode_get_display_value )( const Mode *sw, unsigned int select
*
* @return Get the icon
*/
typedef cairo_surface_t * ( *_mode_get_icon )( const Mode *sw, unsigned int selected_line, int height );
typedef cairo_surface_t *(*_mode_get_icon)(const Mode *sw,
unsigned int selected_line,
int height);
/**
* @param sw The #Mode pointer
@ -71,7 +76,8 @@ typedef cairo_surface_t * ( *_mode_get_icon )( const Mode *sw, unsigned int sele
*
* @return Get the completion string
*/
typedef char * ( *_mode_get_completion )( const Mode *sw, unsigned int selected_line );
typedef char *(*_mode_get_completion)(const Mode *sw,
unsigned int selected_line);
/**
* @param tokens List of (input) tokens to match.
@ -84,7 +90,8 @@ typedef char * ( *_mode_get_completion )( const Mode *sw, unsigned int selected_
*
* @returns 1 when it matches, 0 if not.
*/
typedef int ( *_mode_token_match )( const Mode *data, rofi_int_matcher **tokens, unsigned int index );
typedef int (*_mode_token_match)(const Mode *data, rofi_int_matcher **tokens,
unsigned int index);
/**
* @param sw The #Mode pointer
@ -93,7 +100,7 @@ typedef int ( *_mode_token_match )( const Mode *data, rofi_int_matcher **tokens,
*
* @returns TRUE is successful
*/
typedef int ( *__mode_init )( Mode *sw );
typedef int (*__mode_init)(Mode *sw);
/**
* @param sw The #Mode pointer
@ -102,7 +109,7 @@ typedef int ( *__mode_init )( Mode *sw );
*
* @returns the number of entries
*/
typedef unsigned int ( *__mode_get_num_entries )( const Mode *sw );
typedef unsigned int (*__mode_get_num_entries)(const Mode *sw);
/**
* @param sw The #Mode pointer
@ -110,7 +117,7 @@ typedef unsigned int ( *__mode_get_num_entries )( const Mode *sw );
* Destroy the current mode. Still ready to restart.
*
*/
typedef void ( *__mode_destroy )( Mode *sw );
typedef void (*__mode_destroy)(Mode *sw);
/**
* @param sw The #Mode pointer
@ -122,7 +129,8 @@ typedef void ( *__mode_destroy )( Mode *sw );
*
* @returns the next action to take
*/
typedef ModeMode ( *_mode_result )( Mode *sw, int menu_retv, char **input, unsigned int selected_line );
typedef ModeMode (*_mode_result)(Mode *sw, int menu_retv, char **input,
unsigned int selected_line);
/**
* @param sw The #Mode pointer
@ -132,7 +140,7 @@ typedef ModeMode ( *_mode_result )( Mode *sw, int menu_retv, char **input, unsig
*
* @returns Entry stripped from markup for sorting
*/
typedef char* ( *_mode_preprocess_input )( Mode *sw, const char *input );
typedef char *(*_mode_preprocess_input)(Mode *sw, const char *input);
/**
* @param sw The #Mode pointer
@ -141,60 +149,59 @@ typedef char* ( *_mode_preprocess_input )( Mode *sw, const char *input );
*
* @returns the (valid pango markup) message to display.
*/
typedef char * ( *_mode_get_message )( const Mode *sw );
typedef char *(*_mode_get_message)(const Mode *sw);
/**
* Structure defining a switcher.
* It consists of a name, callback and if enabled
* a textbox for the sidebar-mode.
*/
struct rofi_mode
{
/** Used for external plugins. */
unsigned int abi_version;
/** Name (max 31 char long) */
char *name;
char cfg_name_key[128];
char *display_name;
struct rofi_mode {
/** Used for external plugins. */
unsigned int abi_version;
/** Name (max 31 char long) */
char *name;
char cfg_name_key[128];
char *display_name;
/**
* A switcher normally consists of the following parts:
*/
/** Initialize the Mode */
__mode_init _init;
/** Destroy the switcher, e.g. free all its memory. */
__mode_destroy _destroy;
/** Get number of entries to display. (unfiltered). */
__mode_get_num_entries _get_num_entries;
/** Process the result of the user selection. */
_mode_result _result;
/** Token match. */
_mode_token_match _token_match;
/** Get the string to display for the entry. */
_mode_get_display_value _get_display_value;
/** Get the icon for the entry. */
_mode_get_icon _get_icon;
/** Get the 'completed' entry. */
_mode_get_completion _get_completion;
/**
* A switcher normally consists of the following parts:
*/
/** Initialize the Mode */
__mode_init _init;
/** Destroy the switcher, e.g. free all its memory. */
__mode_destroy _destroy;
/** Get number of entries to display. (unfiltered). */
__mode_get_num_entries _get_num_entries;
/** Process the result of the user selection. */
_mode_result _result;
/** Token match. */
_mode_token_match _token_match;
/** Get the string to display for the entry. */
_mode_get_display_value _get_display_value;
/** Get the icon for the entry. */
_mode_get_icon _get_icon;
/** Get the 'completed' entry. */
_mode_get_completion _get_completion;
_mode_preprocess_input _preprocess_input;
_mode_preprocess_input _preprocess_input;
_mode_get_message _get_message;
_mode_get_message _get_message;
/** Pointer to private data. */
void *private_data;
/** Pointer to private data. */
void *private_data;
/**
* Free SWitcher
* Only to be used when the switcher object itself is dynamic.
* And has data in `ed`
*/
_mode_free free;
/** Extra fields for script */
void *ed;
/**
* Free SWitcher
* Only to be used when the switcher object itself is dynamic.
* And has data in `ed`
*/
_mode_free free;
/** Extra fields for script */
void *ed;
/** Module */
GModule *module;
/** Module */
GModule *module;
};
G_END_DECLS
#endif // ROFI_MODE_PRIVATE_H

View file

@ -27,8 +27,8 @@
#ifndef ROFI_MODE_H
#define ROFI_MODE_H
#include <cairo.h>
#include "rofi-types.h"
#include <cairo.h>
G_BEGIN_DECLS
/**
* @defgroup MODE Mode
@ -46,47 +46,45 @@ typedef struct rofi_mode Mode;
/**
* Enum used to sum the possible states of ROFI.
*/
typedef enum
{
/** Exit. */
MODE_EXIT = 1000,
/** Skip to the next cycle-able dialog. */
NEXT_DIALOG = 1001,
/** Reload current DIALOG */
RELOAD_DIALOG = 1002,
/** Previous dialog */
PREVIOUS_DIALOG = 1003,
/** Reloads the dialog and unset user input */
RESET_DIALOG = 1004,
typedef enum {
/** Exit. */
MODE_EXIT = 1000,
/** Skip to the next cycle-able dialog. */
NEXT_DIALOG = 1001,
/** Reload current DIALOG */
RELOAD_DIALOG = 1002,
/** Previous dialog */
PREVIOUS_DIALOG = 1003,
/** Reloads the dialog and unset user input */
RESET_DIALOG = 1004,
} ModeMode;
/**
* State returned by the rofi window.
*/
typedef enum
{
/** Entry is selected. */
MENU_OK = 0x00010000,
/** User canceled the operation. (e.g. pressed escape) */
MENU_CANCEL = 0x00020000,
/** User requested a mode switch */
MENU_NEXT = 0x00040000,
/** Custom (non-matched) input was entered. */
MENU_CUSTOM_INPUT = 0x00080000,
/** User wanted to delete entry from history. */
MENU_ENTRY_DELETE = 0x00100000,
/** User wants to jump to another switcher. */
MENU_QUICK_SWITCH = 0x00200000,
/** User wants to jump to custom command. */
MENU_CUSTOM_COMMAND = 0x00800000,
/** Go to the previous menu. */
MENU_PREVIOUS = 0x00400000,
/** Go to the complete. */
MENU_COMPLETE = 0x01000000,
/** Bindings specifics */
MENU_CUSTOM_ACTION = 0x10000000,
/** Mask */
MENU_LOWER_MASK = 0x0000FFFF
typedef enum {
/** Entry is selected. */
MENU_OK = 0x00010000,
/** User canceled the operation. (e.g. pressed escape) */
MENU_CANCEL = 0x00020000,
/** User requested a mode switch */
MENU_NEXT = 0x00040000,
/** Custom (non-matched) input was entered. */
MENU_CUSTOM_INPUT = 0x00080000,
/** User wanted to delete entry from history. */
MENU_ENTRY_DELETE = 0x00100000,
/** User wants to jump to another switcher. */
MENU_QUICK_SWITCH = 0x00200000,
/** User wants to jump to custom command. */
MENU_CUSTOM_COMMAND = 0x00800000,
/** Go to the previous menu. */
MENU_PREVIOUS = 0x00400000,
/** Go to the complete. */
MENU_COMPLETE = 0x01000000,
/** Bindings specifics */
MENU_CUSTOM_ACTION = 0x10000000,
/** Mask */
MENU_LOWER_MASK = 0x0000FFFF
} MenuReturn;
/**
@ -96,14 +94,14 @@ typedef enum
*
* @returns FALSE if there was a failure, TRUE if successful
*/
int mode_init ( Mode *mode );
int mode_init(Mode *mode);
/**
* @param mode The mode to destroy
*
* Destroy the mode
*/
void mode_destroy ( Mode *mode );
void mode_destroy(Mode *mode);
/**
* @param mode The mode to query
@ -112,20 +110,24 @@ void mode_destroy ( Mode *mode );
*
* @returns an unsigned int with the number of entries.
*/
unsigned int mode_get_num_entries ( const Mode *mode );
unsigned int mode_get_num_entries(const Mode *mode);
/**
* @param mode The mode to query
* @param selected_line The entry to query
* @param state The state of the entry [out]
* @param attribute_list List of extra (pango) attribute to apply when displaying. [out][null]
* @param attribute_list List of extra (pango) attribute to apply when
* displaying. [out][null]
* @param get_entry If the should be returned.
*
* Returns the string as it should be displayed for the entry and the state of how it should be displayed.
* Returns the string as it should be displayed for the entry and the state of
* how it should be displayed.
*
* @returns allocated new string and state when get_entry is TRUE otherwise just the state.
* @returns allocated new string and state when get_entry is TRUE otherwise just
* the state.
*/
char * mode_get_display_value ( const Mode *mode, unsigned int selected_line, int *state, GList **attribute_list, int get_entry );
char *mode_get_display_value(const Mode *mode, unsigned int selected_line,
int *state, GList **attribute_list, int get_entry);
/**
* @param mode The mode to query
@ -136,17 +138,19 @@ char * mode_get_display_value ( const Mode *mode, unsigned int selected_line, in
*
* @returns allocated new cairo_surface_t if applicable
*/
cairo_surface_t * mode_get_icon ( const Mode *mode, unsigned int selected_line, int height );
cairo_surface_t *mode_get_icon(const Mode *mode, unsigned int selected_line,
int height);
/**
* @param mode The mode to query
* @param selected_line The entry to query
*
* Return a string that can be used for completion. It has should have no markup.
* Return a string that can be used for completion. It has should have no
* markup.
*
* @returns allocated string.
*/
char * mode_get_completion ( const Mode *mode, unsigned int selected_line );
char *mode_get_completion(const Mode *mode, unsigned int selected_line);
/**
* @param mode The mode to query
@ -158,7 +162,8 @@ char * mode_get_completion ( const Mode *mode, unsigned int selected_line );
*
* @returns the next #ModeMode.
*/
ModeMode mode_result ( Mode *mode, int menu_retv, char **input, unsigned int selected_line );
ModeMode mode_result(Mode *mode, int menu_retv, char **input,
unsigned int selected_line);
/**
* @param mode The mode to query
@ -169,7 +174,8 @@ ModeMode mode_result ( Mode *mode, int menu_retv, char **input, unsigned int sel
*
* @returns TRUE if matches
*/
int mode_token_match ( const Mode *mode, rofi_int_matcher **tokens, unsigned int selected_line );
int mode_token_match(const Mode *mode, rofi_int_matcher **tokens,
unsigned int selected_line);
/**
* @param mode The mode to query
@ -178,14 +184,14 @@ int mode_token_match ( const Mode *mode, rofi_int_matcher **tokens, unsigned int
*
* @returns the name of the mode.
*/
const char * mode_get_name ( const Mode *mode );
const char *mode_get_name(const Mode *mode);
/**
* @param mode The mode to query
*
* Free the resources allocated for this mode.
*/
void mode_free ( Mode **mode );
void mode_free(Mode **mode);
/**
* @param mode The mode to query
@ -193,7 +199,7 @@ void mode_free ( Mode **mode );
* Helper functions for mode.
* Get the private data object.
*/
void *mode_get_private_data ( const Mode *mode );
void *mode_get_private_data(const Mode *mode);
/**
* @param mode The mode to query
@ -202,7 +208,7 @@ void *mode_get_private_data ( const Mode *mode );
* Helper functions for mode.
* Set the private data object.
*/
void mode_set_private_data ( Mode *mode, void *pd );
void mode_set_private_data(Mode *mode, void *pd);
/**
* @param mode The mode to query
@ -211,14 +217,15 @@ void mode_set_private_data ( Mode *mode, void *pd );
*
* @return the user visible name of the mode
*/
const char *mode_get_display_name ( const Mode *mode );
const char *mode_get_display_name(const Mode *mode);
/**
* @param mode The mode to query
*
* Should be called once for each mode. This adds the display-name configuration option for the mode.
* Should be called once for each mode. This adds the display-name configuration
* option for the mode.
*/
void mode_set_config ( Mode *mode );
void mode_set_config(Mode *mode);
/**
* @param mode The mode to query
@ -229,16 +236,17 @@ void mode_set_config ( Mode *mode );
*
* @returns a newly allocated string
*/
char * mode_preprocess_input ( Mode *mode, const char *input );
char *mode_preprocess_input(Mode *mode, const char *input);
/**
* @param mode The mode to query
*
* Query the mode for a user display.
*
* @return a new allocated (valid pango markup) message to display (user should free).
* @return a new allocated (valid pango markup) message to display (user should
* free).
*/
char *mode_get_message ( const Mode *mode );
char *mode_get_message(const Mode *mode);
/**@}*/
G_END_DECLS
#endif

View file

@ -1,9 +1,9 @@
#ifndef ROFI_ICON_FETCHER_H
#define ROFI_ICON_FETCHER_H
#include <cairo.h>
#include <glib.h>
#include <stdint.h>
#include <cairo.h>
/**
* @defgroup ICONFETCHER IconFetcher
@ -16,25 +16,26 @@
/**
* Initialize the icon fetcher.
*/
void rofi_icon_fetcher_init ( void );
void rofi_icon_fetcher_init(void);
/**
* Destroy and free the memory used by the icon fetcher.
*/
void rofi_icon_fetcher_destroy ( void );
void rofi_icon_fetcher_destroy(void);
/**
* @param name The name of the icon to fetch.
* @param size The size of the icon to fetch.
*
* Query the icon-theme for icon with name and size.
* The returned icon will be the best match for the requested size, it should still be resized to the actual size.
* The returned icon will be the best match for the requested size, it should
* still be resized to the actual size.
*
* name can also be a full path, if prefixed with file://.
*
* @returns the uid identifying the request.
*/
uint32_t rofi_icon_fetcher_query ( const char *name, const int size );
uint32_t rofi_icon_fetcher_query(const char *name, const int size);
/**
* @param name The name of the icon to fetch.
@ -42,14 +43,16 @@ uint32_t rofi_icon_fetcher_query ( const char *name, const int size );
* @param hsize The height of the icon to fetch.
*
* Query the icon-theme for icon with name and size.
* The returned icon will be the best match for the requested size, it should still be resized to the actual size.
* For icons it will take the min of wsize and hsize.
* The returned icon will be the best match for the requested size, it should
* still be resized to the actual size. For icons it will take the min of wsize
* and hsize.
*
* name can also be a full path, if prefixed with file://.
*
* @returns the uid identifying the request.
*/
uint32_t rofi_icon_fetcher_query_advanced ( const char *name, const int wsize, const int hsize );
uint32_t rofi_icon_fetcher_query_advanced(const char *name, const int wsize,
const int hsize);
/**
* @param uid The unique id representing the matching request.
@ -58,7 +61,7 @@ uint32_t rofi_icon_fetcher_query_advanced ( const char *name, const int wsize, c
*
* @returns the surface with the icon, NULL when not found.
*/
cairo_surface_t * rofi_icon_fetcher_get ( const uint32_t uid );
cairo_surface_t *rofi_icon_fetcher_get(const uint32_t uid);
/**
* @param path the image path to check.
@ -67,6 +70,6 @@ cairo_surface_t * rofi_icon_fetcher_get ( const uint32_t uid );
*
* @returns true if image, false otherwise.
*/
gboolean rofi_icon_fetcher_file_is_image ( const char * const path );
gboolean rofi_icon_fetcher_file_is_image(const char *const path);
/** @} */
#endif // ROFI_ICON_FETCHER_H

View file

@ -1,6 +1,5 @@
#ifndef INCLUDE_ROFI_TYPES_H
#define INCLUDE_ROFI_TYPES_H
#include <glib.h>
#include <stdint.h>
G_BEGIN_DECLS
@ -8,232 +7,213 @@ G_BEGIN_DECLS
/**
* Type of property
*/
typedef enum
{
/** Integer */
P_INTEGER,
/** Double */
P_DOUBLE,
/** String */
P_STRING,
/** Character */
P_CHAR,
/** Boolean */
P_BOOLEAN,
/** Color */
P_COLOR,
/** Image */
P_IMAGE,
/** RofiPadding */
P_PADDING,
/** Link to global setting */
P_LINK,
/** Position */
P_POSITION,
/** Highlight */
P_HIGHLIGHT,
/** List */
P_LIST,
/** Orientation */
P_ORIENTATION,
/** Cursor */
P_CURSOR,
/** Inherit */
P_INHERIT,
/** Number of types. */
P_NUM_TYPES,
typedef enum {
/** Integer */
P_INTEGER,
/** Double */
P_DOUBLE,
/** String */
P_STRING,
/** Character */
P_CHAR,
/** Boolean */
P_BOOLEAN,
/** Color */
P_COLOR,
/** Image */
P_IMAGE,
/** RofiPadding */
P_PADDING,
/** Link to global setting */
P_LINK,
/** Position */
P_POSITION,
/** Highlight */
P_HIGHLIGHT,
/** List */
P_LIST,
/** Orientation */
P_ORIENTATION,
/** Cursor */
P_CURSOR,
/** Inherit */
P_INHERIT,
/** Number of types. */
P_NUM_TYPES,
} PropertyType;
/**
* This array maps PropertyType to a user-readable name.
* It is important this is kept in sync.
*/
extern const char * const PropertyTypeName[P_NUM_TYPES];
extern const char *const PropertyTypeName[P_NUM_TYPES];
/** Style of text highlight */
typedef enum
{
/** no highlight */
ROFI_HL_NONE = 0,
/** bold */
ROFI_HL_BOLD = 1,
/** underline */
ROFI_HL_UNDERLINE = 2,
/** strikethrough */
ROFI_HL_STRIKETHROUGH = 16,
/** small caps */
ROFI_HL_SMALL_CAPS = 32,
/** italic */
ROFI_HL_ITALIC = 4,
/** color */
ROFI_HL_COLOR = 8
typedef enum {
/** no highlight */
ROFI_HL_NONE = 0,
/** bold */
ROFI_HL_BOLD = 1,
/** underline */
ROFI_HL_UNDERLINE = 2,
/** strikethrough */
ROFI_HL_STRIKETHROUGH = 16,
/** small caps */
ROFI_HL_SMALL_CAPS = 32,
/** italic */
ROFI_HL_ITALIC = 4,
/** color */
ROFI_HL_COLOR = 8
} RofiHighlightStyle;
/** Style of line */
typedef enum
{
/** Solid line */
ROFI_HL_SOLID,
/** Dashed line */
ROFI_HL_DASH
typedef enum {
/** Solid line */
ROFI_HL_SOLID,
/** Dashed line */
ROFI_HL_DASH
} RofiLineStyle;
/**
* Distance unit type.
*/
typedef enum
{
/** PixelWidth in pixels. */
ROFI_PU_PX,
/** PixelWidth in millimeters. */
ROFI_PU_MM,
/** PixelWidth in EM. */
ROFI_PU_EM,
/** PixelWidget in percentage */
ROFI_PU_PERCENT,
/** PixelWidth in CH. */
ROFI_PU_CH,
typedef enum {
/** PixelWidth in pixels. */
ROFI_PU_PX,
/** PixelWidth in millimeters. */
ROFI_PU_MM,
/** PixelWidth in EM. */
ROFI_PU_EM,
/** PixelWidget in percentage */
ROFI_PU_PERCENT,
/** PixelWidth in CH. */
ROFI_PU_CH,
} RofiPixelUnit;
/**
* Structure representing a distance.
*/
typedef enum
{
ROFI_DISTANCE_MODIFIER_NONE,
ROFI_DISTANCE_MODIFIER_ADD,
ROFI_DISTANCE_MODIFIER_SUBTRACT,
ROFI_DISTANCE_MODIFIER_DIVIDE,
ROFI_DISTANCE_MODIFIER_MULTIPLY,
ROFI_DISTANCE_MODIFIER_MODULO,
ROFI_DISTANCE_MODIFIER_GROUP,
ROFI_DISTANCE_MODIFIER_MIN,
ROFI_DISTANCE_MODIFIER_MAX,
typedef enum {
ROFI_DISTANCE_MODIFIER_NONE,
ROFI_DISTANCE_MODIFIER_ADD,
ROFI_DISTANCE_MODIFIER_SUBTRACT,
ROFI_DISTANCE_MODIFIER_DIVIDE,
ROFI_DISTANCE_MODIFIER_MULTIPLY,
ROFI_DISTANCE_MODIFIER_MODULO,
ROFI_DISTANCE_MODIFIER_GROUP,
ROFI_DISTANCE_MODIFIER_MIN,
ROFI_DISTANCE_MODIFIER_MAX,
} RofiDistanceModifier;
typedef struct RofiDistanceUnit
{
/** Distance */
double distance;
/** Unit type of the distance */
RofiPixelUnit type;
typedef struct RofiDistanceUnit {
/** Distance */
double distance;
/** Unit type of the distance */
RofiPixelUnit type;
/** Type */
RofiDistanceModifier modtype;
/** Type */
RofiDistanceModifier modtype;
/** Modifier */
struct RofiDistanceUnit *left;
/** Modifier */
struct RofiDistanceUnit *left;
/** Modifier */
struct RofiDistanceUnit *right;
/** Modifier */
struct RofiDistanceUnit *right;
} RofiDistanceUnit;
typedef struct
{
/** Base */
RofiDistanceUnit base;
/** Style of the line (optional)*/
RofiLineStyle style;
typedef struct {
/** Base */
RofiDistanceUnit base;
/** Style of the line (optional)*/
RofiLineStyle style;
} RofiDistance;
/**
* Type of orientation.
*/
typedef enum
{
ROFI_ORIENTATION_VERTICAL,
ROFI_ORIENTATION_HORIZONTAL
typedef enum {
ROFI_ORIENTATION_VERTICAL,
ROFI_ORIENTATION_HORIZONTAL
} RofiOrientation;
/**
* Cursor type.
*/
typedef enum
{
ROFI_CURSOR_DEFAULT,
ROFI_CURSOR_POINTER,
ROFI_CURSOR_TEXT
typedef enum {
ROFI_CURSOR_DEFAULT,
ROFI_CURSOR_POINTER,
ROFI_CURSOR_TEXT
} RofiCursorType;
/**
* Represent the color in theme.
*/
typedef struct
{
/** red channel */
double red;
/** green channel */
double green;
/** blue channel */
double blue;
/** alpha channel */
double alpha;
typedef struct {
/** red channel */
double red;
/** green channel */
double green;
/** blue channel */
double blue;
/** alpha channel */
double alpha;
} ThemeColor;
/**
* Theme Image
*/
typedef enum
{
ROFI_IMAGE_URL,
ROFI_IMAGE_LINEAR_GRADIENT
} RofiImageType;
typedef enum { ROFI_IMAGE_URL, ROFI_IMAGE_LINEAR_GRADIENT } RofiImageType;
typedef enum
{
ROFI_DIRECTION_LEFT,
ROFI_DIRECTION_RIGHT,
ROFI_DIRECTION_TOP,
ROFI_DIRECTION_BOTTOM,
ROFI_DIRECTION_ANGLE,
typedef enum {
ROFI_DIRECTION_LEFT,
ROFI_DIRECTION_RIGHT,
ROFI_DIRECTION_TOP,
ROFI_DIRECTION_BOTTOM,
ROFI_DIRECTION_ANGLE,
} RofiDirection;
typedef enum
{
ROFI_SCALE_NONE,
ROFI_SCALE_BOTH,
ROFI_SCALE_HEIGHT,
ROFI_SCALE_WIDTH,
typedef enum {
ROFI_SCALE_NONE,
ROFI_SCALE_BOTH,
ROFI_SCALE_HEIGHT,
ROFI_SCALE_WIDTH,
} RofiScaleType;
typedef struct
{
RofiImageType type;
char *url;
RofiScaleType scaling;
int wsize;
int hsize;
typedef struct {
RofiImageType type;
char *url;
RofiScaleType scaling;
int wsize;
int hsize;
RofiDirection dir;
double angle;
/** colors */
GList *colors;
RofiDirection dir;
double angle;
/** colors */
GList *colors;
/** cached image */
uint32_t surface_id;
/** cached image */
uint32_t surface_id;
} RofiImage;
/**
* RofiPadding
*/
typedef struct
{
RofiDistance top;
RofiDistance right;
RofiDistance bottom;
RofiDistance left;
typedef struct {
RofiDistance top;
RofiDistance right;
RofiDistance bottom;
RofiDistance left;
} RofiPadding;
/**
* Theme highlight.
*/
typedef struct
{
/** style to display */
RofiHighlightStyle style;
/** Color */
ThemeColor color;
typedef struct {
/** style to display */
RofiHighlightStyle style;
/** Color */
ThemeColor color;
} RofiHighlightColorStyle;
/**
@ -245,100 +225,93 @@ typedef struct
*
* @ingroup CONFIGURATION
*/
typedef enum
{
/** Center */
WL_CENTER = 0,
/** Top middle */
WL_NORTH = 1,
/** Middle right */
WL_EAST = 2,
/** Bottom middle */
WL_SOUTH = 4,
/** Middle left */
WL_WEST = 8,
/** Left top corner. */
WL_NORTH_WEST = WL_NORTH | WL_WEST,
/** Top right */
WL_NORTH_EAST = WL_NORTH | WL_EAST,
/** Bottom right */
WL_SOUTH_EAST = WL_SOUTH | WL_EAST,
/** Bottom left */
WL_SOUTH_WEST = WL_SOUTH | WL_WEST,
typedef enum {
/** Center */
WL_CENTER = 0,
/** Top middle */
WL_NORTH = 1,
/** Middle right */
WL_EAST = 2,
/** Bottom middle */
WL_SOUTH = 4,
/** Middle left */
WL_WEST = 8,
/** Left top corner. */
WL_NORTH_WEST = WL_NORTH | WL_WEST,
/** Top right */
WL_NORTH_EAST = WL_NORTH | WL_EAST,
/** Bottom right */
WL_SOUTH_EAST = WL_SOUTH | WL_EAST,
/** Bottom left */
WL_SOUTH_WEST = WL_SOUTH | WL_WEST,
} WindowLocation;
typedef union _PropertyValue
{
/** integer */
int i;
/** Double */
double f;
/** String */
char *s;
/** Character */
char c;
/** boolean */
gboolean b;
/** Color */
ThemeColor color;
/** RofiPadding */
RofiPadding padding;
/** Reference */
struct
{
/** Name */
char *name;
/** Cached looked up ref */
struct Property *ref;
/** Property default */
struct Property *def_value;
} link;
/** Highlight Style */
RofiHighlightColorStyle highlight;
/** Image */
RofiImage image;
/** List */
GList *list;
typedef union _PropertyValue {
/** integer */
int i;
/** Double */
double f;
/** String */
char *s;
/** Character */
char c;
/** boolean */
gboolean b;
/** Color */
ThemeColor color;
/** RofiPadding */
RofiPadding padding;
/** Reference */
struct {
/** Name */
char *name;
/** Cached looked up ref */
struct Property *ref;
/** Property default */
struct Property *def_value;
} link;
/** Highlight Style */
RofiHighlightColorStyle highlight;
/** Image */
RofiImage image;
/** List */
GList *list;
} PropertyValue;
/**
* Property structure.
*/
typedef struct Property
{
/** Name of property */
char *name;
/** Type of property. */
PropertyType type;
/** Value */
PropertyValue value;
typedef struct Property {
/** Name of property */
char *name;
/** Type of property. */
PropertyType type;
/** Value */
PropertyValue value;
} Property;
/**
* Structure to hold a range.
*/
typedef struct rofi_range_pair
{
int start;
int stop;
typedef struct rofi_range_pair {
int start;
int stop;
} rofi_range_pair;
/**
* Internal structure for matching.
*/
typedef struct rofi_int_matcher_t
{
GRegex *regex;
gboolean invert;
typedef struct rofi_int_matcher_t {
GRegex *regex;
gboolean invert;
} rofi_int_matcher;
/**
* Structure with data to process by each worker thread.
* TODO: Make this more generic wrapper.
*/
typedef struct _thread_state
{
void ( *callback )( struct _thread_state *t, gpointer data );
typedef struct _thread_state {
void (*callback)(struct _thread_state *t, gpointer data);
} thread_state;
extern GThreadPool *tpool;

View file

@ -27,15 +27,15 @@
#ifndef ROFI_MAIN_H
#define ROFI_MAIN_H
#include <xcb/xcb.h>
#include <xkbcommon/xkbcommon.h>
#include <glib.h>
#include <string.h>
#include <stdlib.h>
#include "rofi-types.h"
#include "keyb.h"
#include "mode.h"
#include "rofi-types.h"
#include "view.h"
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <xcb/xcb.h>
#include <xkbcommon/xkbcommon.h>
/**
* @defgroup Main Main
@ -52,62 +52,64 @@ extern const char *cache_dir;
*
* @returns the number of enabled modi.
*/
unsigned int rofi_get_num_enabled_modi ( void );
unsigned int rofi_get_num_enabled_modi(void);
/**
* @param index The mode to return. (should be smaller then rofi_get_num_enabled_mode)
* @param index The mode to return. (should be smaller then
* rofi_get_num_enabled_mode)
*
* Get an enabled mode handle.
*
* @returns a Mode handle.
*/
const Mode * rofi_get_mode ( unsigned int index );
const Mode *rofi_get_mode(unsigned int index);
/**
* @param str A GString with an error message to display.
*
* Queue an error.
*/
void rofi_add_error_message ( GString *str );
void rofi_add_error_message(GString *str);
void rofi_clear_error_messages ( void );
void rofi_clear_error_messages(void);
/**
* @param code the code to return
*
* Return value are used for integrating dmenu rofi in scripts.
* This function sets the code that rofi will return on exit.
*/
void rofi_set_return_code ( int code );
void rofi_set_return_code(int code);
void rofi_quit_main_loop ( void );
void rofi_quit_main_loop(void);
/**
* @param name Search for mode with this name.
*
* @return returns Mode * when found, NULL if not.
*/
Mode * rofi_collect_modi_search ( const char *name );
Mode *rofi_collect_modi_search(const char *name);
/** Reset terminal */
#define color_reset "\033[0m"
#define color_reset "\033[0m"
/** Set terminal text bold */
#define color_bold "\033[1m"
#define color_bold "\033[1m"
/** Set terminal text italic */
#define color_italic "\033[2m"
#define color_italic "\033[2m"
/** Set terminal foreground text green */
#define color_green "\033[0;32m"
#define color_green "\033[0;32m"
/** Set terminal foreground text red */
#define color_red "\033[0;31m"
#define color_red "\033[0;31m"
/** Appends instructions on how to report an error. */
#define ERROR_MSG( a ) a "\n" \
"If you suspect this is caused by a bug in rofi,\n" \
"please report the following information to rofi's github page:\n" \
" * The generated commandline output when the error occurred.\n" \
" * Output of -dump-xresource\n" \
" * Steps to reproduce\n" \
" * The version of rofi you are running\n\n" \
#define ERROR_MSG(a) \
a "\n" \
"If you suspect this is caused by a bug in rofi,\n" \
"please report the following information to rofi's github page:\n" \
" * The generated commandline output when the error occurred.\n" \
" * Output of -dump-xresource\n" \
" * Steps to reproduce\n" \
" * The version of rofi you are running\n\n" \
" <i>https://github.com/davatorium/rofi/</i>"
/** Indicates if ERROR_MSG uses pango markup */
#define ERROR_MSG_MARKUP TRUE
#define ERROR_MSG_MARKUP TRUE
/**@}*/
#endif

View file

@ -35,166 +35,159 @@
*
* @ingroup CONFIGURATION
*/
typedef enum
{
MM_NORMAL = 0,
MM_REGEX = 1,
MM_GLOB = 2,
MM_FUZZY = 3,
MM_PREFIX = 4
typedef enum {
MM_NORMAL = 0,
MM_REGEX = 1,
MM_GLOB = 2,
MM_FUZZY = 3,
MM_PREFIX = 4
} MatchingMethod;
/**
* Possible sorting methods for listview.
*/
typedef enum
{
SORT_NORMAL = 0,
SORT_FZF = 1
} SortingMethod;
typedef enum { SORT_NORMAL = 0, SORT_FZF = 1 } SortingMethod;
typedef enum
{
DISPLAY_XCB,
DISPLAY_WAYLAND,
typedef enum {
DISPLAY_XCB,
DISPLAY_WAYLAND,
} DisplayBackend;
/**
* Settings structure holding all (static) configurable options.
* @ingroup CONFIGURATION
*/
typedef struct
{
/** List of enabled modi */
char *modi;
/** Font string (pango format) */
char * menu_font;
typedef struct {
/** List of enabled modi */
char *modi;
/** Font string (pango format) */
char *menu_font;
/** Whether to load and show icons */
gboolean show_icons;
/** Whether to load and show icons */
gboolean show_icons;
/** Terminal to use */
char * terminal_emulator;
/** SSH client to use */
char * ssh_client;
/** Command to execute when ssh session is selected */
char * ssh_command;
/** Command for executing an application */
char * run_command;
/** Command for executing an application in a terminal */
char * run_shell_command;
/** Command for listing executables */
char * run_list_command;
/** Command for window */
char * window_command;
/** Window fields to match in window mode */
char * window_match_fields;
/** Theme for icons */
char * icon_theme;
/** Terminal to use */
char *terminal_emulator;
/** SSH client to use */
char *ssh_client;
/** Command to execute when ssh session is selected */
char *ssh_command;
/** Command for executing an application */
char *run_command;
/** Command for executing an application in a terminal */
char *run_shell_command;
/** Command for listing executables */
char *run_list_command;
/** Command for window */
char *window_command;
/** Window fields to match in window mode */
char *window_match_fields;
/** Theme for icons */
char *icon_theme;
/** Backend */
DisplayBackend backend;
/** Backend */
DisplayBackend backend;
/** Windows location/gravity */
WindowLocation location;
/** Y offset */
int y_offset;
/** X offset */
int x_offset;
/** Always should config.menu_lines lines, even if less lines are available */
unsigned int fixed_num_lines;
/** Do not use history */
unsigned int disable_history;
/** Programs ignored for history */
char * ignored_prefixes;
/** Toggle to enable sorting. */
unsigned int sort;
/** Sorting method. */
SortingMethod sorting_method_enum;
/** Sorting method. */
char * sorting_method;
/** Windows location/gravity */
WindowLocation location;
/** Y offset */
int y_offset;
/** X offset */
int x_offset;
/** Always should config.menu_lines lines, even if less lines are available */
unsigned int fixed_num_lines;
/** Do not use history */
unsigned int disable_history;
/** Programs ignored for history */
char *ignored_prefixes;
/** Toggle to enable sorting. */
unsigned int sort;
/** Sorting method. */
SortingMethod sorting_method_enum;
/** Sorting method. */
char *sorting_method;
/** Desktop entries to match in drun */
char * drun_match_fields;
/** Only show entries in this category */
char * drun_categories;
/** Desktop entry show actions */
unsigned int drun_show_actions;
/** Desktop format display */
char * drun_display_format;
/** Desktop Link launch command */
char * drun_url_launcher;
/** Desktop entries to match in drun */
char *drun_match_fields;
/** Only show entries in this category */
char *drun_categories;
/** Desktop entry show actions */
unsigned int drun_show_actions;
/** Desktop format display */
char *drun_display_format;
/** Desktop Link launch command */
char *drun_url_launcher;
/** Search case sensitivity */
unsigned int case_sensitive;
/** Cycle through in the element list */
unsigned int cycle;
/** Height of an element in number of rows */
int element_height;
/** Sidebar mode, show the modi */
unsigned int sidebar_mode;
/** Mouse hover automatically selects */
gboolean hover_select;
/** Lazy filter limit. */
unsigned int lazy_filter_limit;
/** Auto select. */
unsigned int auto_select;
/** Hosts file parsing */
unsigned int parse_hosts;
/** Knonw_hosts file parsing */
unsigned int parse_known_hosts;
/** Combi Modes */
char *combi_modi;
char *matching;
MatchingMethod matching_method;
unsigned int tokenize;
/** Monitors */
char *monitor;
/** filter */
char *filter;
/** dpi */
int dpi;
/** Number threads (1 to disable) */
unsigned int threads;
unsigned int scroll_method;
/** Search case sensitivity */
unsigned int case_sensitive;
/** Cycle through in the element list */
unsigned int cycle;
/** Height of an element in number of rows */
int element_height;
/** Sidebar mode, show the modi */
unsigned int sidebar_mode;
/** Mouse hover automatically selects */
gboolean hover_select;
/** Lazy filter limit. */
unsigned int lazy_filter_limit;
/** Auto select. */
unsigned int auto_select;
/** Hosts file parsing */
unsigned int parse_hosts;
/** Knonw_hosts file parsing */
unsigned int parse_known_hosts;
/** Combi Modes */
char *combi_modi;
char *matching;
MatchingMethod matching_method;
unsigned int tokenize;
/** Monitors */
char *monitor;
/** filter */
char *filter;
/** dpi */
int dpi;
/** Number threads (1 to disable) */
unsigned int threads;
unsigned int scroll_method;
char *window_format;
/** Click outside the window to exit */
int click_to_exit;
char *window_format;
/** Click outside the window to exit */
int click_to_exit;
char *theme;
/** Path where plugins can be found. */
char * plugin_path;
char *theme;
/** Path where plugins can be found. */
char *plugin_path;
/** Maximum history length per mode. */
unsigned int max_history_size;
gboolean combi_hide_mode_prefix;
/** Maximum history length per mode. */
unsigned int max_history_size;
gboolean combi_hide_mode_prefix;
char matching_negate_char;
char matching_negate_char;
/** Cache directory. */
char *cache_dir;
/** Cache directory. */
char *cache_dir;
/** Window Thumbnails */
gboolean window_thumbnail;
/** Window Thumbnails */
gboolean window_thumbnail;
/** drun cache */
gboolean drun_use_desktop_cache;
gboolean drun_reload_desktop_cache;
/** drun cache */
gboolean drun_use_desktop_cache;
gboolean drun_reload_desktop_cache;
/** Benchmark */
gboolean benchmark_ui;
/** Benchmark */
gboolean benchmark_ui;
gboolean normalize_match;
/** Steal focus */
gboolean steal_focus;
/** fallback icon */
char *application_fallback_icon;
gboolean normalize_match;
/** Steal focus */
gboolean steal_focus;
/** fallback icon */
char *application_fallback_icon;
} Settings;
#define DEFAULT_MENU_LINES 15
#define DEFAULT_MENU_LINES 15
#define DEFAULT_MENU_COLUMNS 1
#define DEFAULT_MENU_WIDTH 50.0f
#define DEFAULT_MENU_WIDTH 50.0f
/** Global Settings structure. */
extern Settings config;

View file

@ -27,59 +27,56 @@
#ifndef THEME_H
#define THEME_H
#include <glib.h>
#include <cairo.h>
#include <widgets/widget.h>
#include "rofi-types.h"
#include <cairo.h>
#include <glib.h>
#include <widgets/widget.h>
/**
* Describe the media constraint type.
*/
typedef enum
{
/** Minimum width constraint. */
THEME_MEDIA_TYPE_MIN_WIDTH,
/** Maximum width constraint. */
THEME_MEDIA_TYPE_MAX_WIDTH,
/** Minimum height constraint. */
THEME_MEDIA_TYPE_MIN_HEIGHT,
/** Maximum height constraint. */
THEME_MEDIA_TYPE_MAX_HEIGHT,
/** Monitor id constraint. */
THEME_MEDIA_TYPE_MON_ID,
/** Minimum aspect ratio constraint. */
THEME_MEDIA_TYPE_MIN_ASPECT_RATIO,
/** Maximum aspect ratio constraint. */
THEME_MEDIA_TYPE_MAX_ASPECT_RATIO,
/** Invalid entry. */
THEME_MEDIA_TYPE_INVALID,
typedef enum {
/** Minimum width constraint. */
THEME_MEDIA_TYPE_MIN_WIDTH,
/** Maximum width constraint. */
THEME_MEDIA_TYPE_MAX_WIDTH,
/** Minimum height constraint. */
THEME_MEDIA_TYPE_MIN_HEIGHT,
/** Maximum height constraint. */
THEME_MEDIA_TYPE_MAX_HEIGHT,
/** Monitor id constraint. */
THEME_MEDIA_TYPE_MON_ID,
/** Minimum aspect ratio constraint. */
THEME_MEDIA_TYPE_MIN_ASPECT_RATIO,
/** Maximum aspect ratio constraint. */
THEME_MEDIA_TYPE_MAX_ASPECT_RATIO,
/** Invalid entry. */
THEME_MEDIA_TYPE_INVALID,
} ThemeMediaType;
/**
* Theme Media description.
*/
typedef struct ThemeMedia
{
ThemeMediaType type;
double value;
typedef struct ThemeMedia {
ThemeMediaType type;
double value;
} ThemeMedia;
/**
* ThemeWidget.
*/
typedef struct ThemeWidget
{
int set;
char *name;
typedef struct ThemeWidget {
int set;
char *name;
unsigned int num_widgets;
struct ThemeWidget **widgets;
unsigned int num_widgets;
struct ThemeWidget **widgets;
ThemeMedia *media;
ThemeMedia *media;
GHashTable *properties;
GHashTable *properties;
struct ThemeWidget *parent;
struct ThemeWidget *parent;
} ThemeWidget;
/**
@ -102,15 +99,16 @@ extern ThemeWidget *rofi_configuration;
*
* @returns handle to the new entry.
*/
ThemeWidget *rofi_theme_find_or_create_name ( ThemeWidget *base, const char *name );
ThemeWidget *rofi_theme_find_or_create_name(ThemeWidget *base,
const char *name);
/**
* @param widget The widget handle.
*
* Print out the widget to the commandline.
*/
void rofi_theme_print ( ThemeWidget *widget );
void rofi_theme_print_index ( ThemeWidget *widget, int index );
void rofi_theme_print(ThemeWidget *widget);
void rofi_theme_print_index(ThemeWidget *widget, int index);
/**
* @param type The type of the property to create.
@ -119,27 +117,27 @@ void rofi_theme_print_index ( ThemeWidget *widget, int index );
*
* @returns a new property.
*/
Property *rofi_theme_property_create ( PropertyType type );
Property *rofi_theme_property_create(PropertyType type);
/**
* @param p The property to free.
*
* Free the content of the property.
*/
void rofi_theme_property_free ( Property *p );
void rofi_theme_property_free(Property *p);
/**
* @param p The property to free.
*
* @returns a copy of p
*/
Property* rofi_theme_property_copy ( const Property *p );
Property *rofi_theme_property_copy(const Property *p);
/**
* @param widget
*
* Free the widget and alll children.
*/
void rofi_theme_free ( ThemeWidget *widget );
void rofi_theme_free(ThemeWidget *widget);
/**
* @param file filename to parse.
@ -148,7 +146,7 @@ void rofi_theme_free ( ThemeWidget *widget );
*
* @returns returns TRUE when error.
*/
gboolean rofi_theme_parse_file ( const char *file );
gboolean rofi_theme_parse_file(const char *file);
/**
* @param string to parse.
@ -157,7 +155,7 @@ gboolean rofi_theme_parse_file ( const char *file );
*
* @returns returns TRUE when error.
*/
gboolean rofi_theme_parse_string ( const char *string );
gboolean rofi_theme_parse_string(const char *string);
/**
* @param widget The widget handle.
@ -165,7 +163,7 @@ gboolean rofi_theme_parse_string ( const char *string );
*
* Merge properties with widgets current property.
*/
void rofi_theme_widget_add_properties ( ThemeWidget *widget, GHashTable *table );
void rofi_theme_widget_add_properties(ThemeWidget *widget, GHashTable *table);
/**
* Public API
@ -180,7 +178,8 @@ void rofi_theme_widget_add_properties ( ThemeWidget *widget, GHashTable *table )
*
* @returns The distance value of this property for this widget.
*/
RofiDistance rofi_theme_get_distance ( const widget *widget, const char *property, int def );
RofiDistance rofi_theme_get_distance(const widget *widget, const char *property,
int def);
/**
* @param widget The widget to query
@ -191,7 +190,7 @@ RofiDistance rofi_theme_get_distance ( const widget *widget, const char *propert
*
* @returns The integer value of this property for this widget.
*/
int rofi_theme_get_integer ( const widget *widget, const char *property, int def );
int rofi_theme_get_integer(const widget *widget, const char *property, int def);
/**
* @param widget The widget to query
@ -202,7 +201,8 @@ int rofi_theme_get_integer ( const widget *widget, const char *property, int def
*
* @returns The position value of this property for this widget.
*/
int rofi_theme_get_position ( const widget *widget, const char *property, int def );
int rofi_theme_get_position(const widget *widget, const char *property,
int def);
/**
* @param widget The widget to query
@ -213,7 +213,7 @@ int rofi_theme_get_position ( const widget *widget, const char *property, int de
*
* @returns The boolean value of this property for this widget.
*/
int rofi_theme_get_boolean ( const widget *widget, const char *property, int def );
int rofi_theme_get_boolean(const widget *widget, const char *property, int def);
/**
* @param widget The widget to query
@ -224,7 +224,9 @@ int rofi_theme_get_boolean ( const widget *widget, const char *property, int def
*
* @returns The orientation of this property for this widget or %def not found.
*/
RofiOrientation rofi_theme_get_orientation ( const widget *widget, const char *property, RofiOrientation def );
RofiOrientation rofi_theme_get_orientation(const widget *widget,
const char *property,
RofiOrientation def);
/**
* @param widget The widget to query
@ -235,7 +237,9 @@ RofiOrientation rofi_theme_get_orientation ( const widget *widget, const char *p
*
* @returns The cursor for this widget or %def if not found.
*/
RofiCursorType rofi_theme_get_cursor_type ( const widget *widget, const char *property, RofiCursorType def );
RofiCursorType rofi_theme_get_cursor_type(const widget *widget,
const char *property,
RofiCursorType def);
/**
* @param widget The widget to query
* @param property The property to query.
@ -245,7 +249,8 @@ RofiCursorType rofi_theme_get_cursor_type ( const widget *widget, const char *pr
*
* @returns The string value of this property for this widget.
*/
const char *rofi_theme_get_string ( const widget *widget, const char *property, const char *def );
const char *rofi_theme_get_string(const widget *widget, const char *property,
const char *def);
/**
* @param widget The widget to query
@ -256,7 +261,8 @@ const char *rofi_theme_get_string ( const widget *widget, const char *property,
*
* @returns The double value of this property for this widget.
*/
double rofi_theme_get_double ( const widget *widget, const char *property, double def );
double rofi_theme_get_double(const widget *widget, const char *property,
double def);
/**
* @param widget The widget to query
@ -266,7 +272,8 @@ double rofi_theme_get_double ( const widget *widget, const char *property, doubl
* Obtain the color of the widget and applies this to the drawable d.
*
*/
void rofi_theme_get_color ( const widget *widget, const char *property, cairo_t *d );
void rofi_theme_get_color(const widget *widget, const char *property,
cairo_t *d);
/**
* @param widget The widget to query
@ -277,7 +284,8 @@ void rofi_theme_get_color ( const widget *widget, const char *property, cairo_t
*
* @return true if image is set.
*/
gboolean rofi_theme_get_image ( const widget *widget, const char *property, cairo_t *d );
gboolean rofi_theme_get_image(const widget *widget, const char *property,
cairo_t *d);
/**
* @param widget The widget to query
@ -286,7 +294,7 @@ gboolean rofi_theme_get_image ( const widget *widget, const char *property, cair
* Check if a rofi theme has a property set.
*
*/
gboolean rofi_theme_has_property ( const widget *widget, const char *property );
gboolean rofi_theme_has_property(const widget *widget, const char *property);
/**
* @param widget The widget to query
@ -297,7 +305,8 @@ gboolean rofi_theme_has_property ( const widget *widget, const char *property );
*
* @returns The padding of this property for this widget.
*/
RofiPadding rofi_theme_get_padding ( const widget *widget, const char *property, RofiPadding pad );
RofiPadding rofi_theme_get_padding(const widget *widget, const char *property,
RofiPadding pad);
/**
* @param widget The widget to query
@ -308,7 +317,9 @@ RofiPadding rofi_theme_get_padding ( const widget *widget, const char *property,
*
* @returns The highlight of this property for this widget.
*/
RofiHighlightColorStyle rofi_theme_get_highlight ( widget *widget, const char *property, RofiHighlightColorStyle th );
RofiHighlightColorStyle rofi_theme_get_highlight(widget *widget,
const char *property,
RofiHighlightColorStyle th);
/**
* @param d The distance handle.
@ -317,14 +328,14 @@ RofiHighlightColorStyle rofi_theme_get_highlight ( widget *widget, const char *p
* Convert RofiDistance into pixels.
* @returns the number of pixels this distance represents.
*/
int distance_get_pixel ( RofiDistance d, RofiOrientation ori );
int distance_get_pixel(RofiDistance d, RofiOrientation ori);
/**
* @param d The distance handle.
* @param draw The cairo drawable.
*
* Set linestyle.
*/
void distance_get_linestyle ( RofiDistance d, cairo_t *draw );
void distance_get_linestyle(RofiDistance d, cairo_t *draw);
/**
* Low-level functions.
@ -335,24 +346,30 @@ void distance_get_linestyle ( RofiDistance d, cairo_t *draw );
* @param state The state of the element.
* @param exact If the match should be exact, or parent can be included.
*
* Find the theme element. If not exact, the closest specified element is returned.
* Find the theme element. If not exact, the closest specified element is
* returned.
*
* @returns the ThemeWidget if found, otherwise NULL.
*/
ThemeWidget *rofi_theme_find_widget ( const char *name, const char *state, gboolean exact );
ThemeWidget *rofi_config_find_widget ( const char *name, const char *state, gboolean exact );
ThemeWidget *rofi_theme_find_widget(const char *name, const char *state,
gboolean exact);
ThemeWidget *rofi_config_find_widget(const char *name, const char *state,
gboolean exact);
/**
* @param widget The widget to find the property on.
* @param type The %PropertyType to find.
* @param property The property to find.
* @param exact If the property should only be found on this widget, or on parents if not found.
* @param exact If the property should only be found on this widget, or on
* parents if not found.
*
* Find the property on the widget. If not exact, the parents are searched recursively until match is found.
* Find the property on the widget. If not exact, the parents are searched
* recursively until match is found.
*
* @returns the Property if found, otherwise NULL.
*/
Property *rofi_theme_find_property ( ThemeWidget *widget, PropertyType type, const char *property, gboolean exact );
Property *rofi_theme_find_property(ThemeWidget *widget, PropertyType type,
const char *property, gboolean exact);
/**
* @param widget The widget to query
@ -361,20 +378,21 @@ Property *rofi_theme_find_property ( ThemeWidget *widget, PropertyType type, con
*
* Obtain list of elements (strings) of the widget.
*
* @returns a GList holding the names in the list of this property for this widget.
* @returns a GList holding the names in the list of this property for this
* widget.
*/
GList *rofi_theme_get_list ( const widget *widget, const char * property, const char *defaults );
GList *rofi_theme_get_list(const widget *widget, const char *property,
const char *defaults);
/**
* Checks if a theme is set, or is empty.
* @returns TRUE when empty.
*/
gboolean rofi_theme_is_empty ( void );
gboolean rofi_theme_is_empty(void);
/**
* Reset the current theme.
*/
void rofi_theme_reset ( void );
void rofi_theme_reset(void);
/**
* @param file File name to prepare.
@ -384,12 +402,12 @@ void rofi_theme_reset ( void );
*
* @returns full path to file.
*/
char * rofi_theme_parse_prepare_file ( const char *file, const char *parent_file );
char *rofi_theme_parse_prepare_file(const char *file, const char *parent_file);
/**
* Process conditionals.
*/
void rofi_theme_parse_process_conditionals ( void );
void rofi_theme_parse_process_conditionals(void);
/**
* @param parent target theme tree
@ -397,27 +415,27 @@ void rofi_theme_parse_process_conditionals ( void );
*
* Merge all the settings from child into parent.
*/
void rofi_theme_parse_merge_widgets ( ThemeWidget *parent, ThemeWidget *child );
void rofi_theme_parse_merge_widgets(ThemeWidget *parent, ThemeWidget *child);
/**
* @param type the media type to parse.
*
* Returns the media type described by type.
*/
ThemeMediaType rofi_theme_parse_media_type ( const char *type );
ThemeMediaType rofi_theme_parse_media_type(const char *type);
/**
* @param distance The distance object to copy.
*
* @returns a copy of the distance.
*/
RofiDistance rofi_theme_property_copy_distance ( RofiDistance const distance );
RofiDistance rofi_theme_property_copy_distance(RofiDistance const distance);
/**
* @param filename The file to validate.
*
* @returns the program exit code.
*/
int rofi_theme_rasi_validate ( const char *filename );
int rofi_theme_rasi_validate(const char *filename);
#endif

View file

@ -32,13 +32,12 @@
*/
#ifndef ROFI_TIMINGS_H
#define ROFI_TIMINGS_H
#include <config.h>
/**
* Init the timestamping mechanism .
* implementation.
*/
void rofi_timings_init ( void );
void rofi_timings_init(void);
/**
* @param file filename tick originates from
* @param str function name.
@ -47,30 +46,31 @@ void rofi_timings_init ( void );
*
* Report a tick.
*/
void rofi_timings_tick ( const char *file, char const *str, int line, char const *msg );
void rofi_timings_tick(const char *file, char const *str, int line,
char const *msg);
/**
* Stop the timestamping mechanism
*/
void rofi_timings_quit ( void );
void rofi_timings_quit(void);
/**
* Start timestamping mechanism.
* Call to this function is time 0.
*/
#define TIMINGS_START() rofi_timings_init ()
#define TIMINGS_START() rofi_timings_init()
/**
* Report current time since TIMINGS_START
*/
#define TICK() rofi_timings_tick ( __FILE__, __func__, __LINE__, "" )
#define TICK() rofi_timings_tick(__FILE__, __func__, __LINE__, "")
/**
* @param a an string
* Report current time since TIMINGS_START
*/
#define TICK_N( a ) rofi_timings_tick ( __FILE__, __func__, __LINE__, a )
#define TICK_N(a) rofi_timings_tick(__FILE__, __func__, __LINE__, a)
/**
* Stop timestamping mechanism.
*/
#define TIMINGS_STOP() rofi_timings_quit ()
#define TIMINGS_STOP() rofi_timings_quit()
#else
@ -91,7 +91,7 @@ void rofi_timings_quit ( void );
* @param a an string
* Report current time since TIMINGS_START
*/
#define TICK_N( a )
#define TICK_N(a)
#endif // ROFI_TIMINGS_H
/**@}*/

View file

@ -27,15 +27,16 @@
#ifndef ROFI_VIEW_INTERNAL_H
#define ROFI_VIEW_INTERNAL_H
#include "widgets/container.h"
#include "widgets/widget.h"
#include "widgets/textbox.h"
#include "keyb.h"
#include "mode.h"
#include "theme.h"
#include "widgets/box.h"
#include "widgets/container.h"
#include "widgets/icon.h"
#include "widgets/listview.h"
#include "keyb.h"
#include "widgets/textbox.h"
#include "widgets/widget.h"
#include "xcb.h"
#include "theme.h"
#ifdef ENABLE_WAYLAND
#include "wayland.h"
@ -48,164 +49,161 @@
*/
// State of the menu.
struct RofiViewState
{
/** #Mode bound to to this view. */
Mode *sw;
struct RofiViewState {
/** #Mode bound to to this view. */
Mode *sw;
/** Flag indicating if view needs to be refiltered. */
int refilter;
/** Widget representing the main container. */
box *main_window;
/** #textbox showing the prompt in the input bar. */
textbox *prompt;
/** #textbox with the user input in the input bar. */
textbox *text;
/** #textbox showing the state of the case sensitive and sortng. */
textbox *case_indicator;
/** Flag indicating if view needs to be refiltered. */
int refilter;
/** Widget representing the main container. */
box *main_window;
/** #textbox showing the prompt in the input bar. */
textbox *prompt;
/** #textbox with the user input in the input bar. */
textbox *text;
/** #textbox showing the state of the case sensitive and sortng. */
textbox *case_indicator;
/** #listview holding the displayed elements. */
listview *list_view;
/** #textbox widget showing the overlay. */
textbox *overlay;
/** #container holding the message box */
container *mesg_box;
/** #textbox containing the message entry */
textbox *mesg_tb;
/** #listview holding the displayed elements. */
listview *list_view;
/** #textbox widget showing the overlay. */
textbox *overlay;
/** #container holding the message box */
container *mesg_box;
/** #textbox containing the message entry */
textbox *mesg_tb;
/** Array with the levenshtein distance for each element. */
int *distance;
/** Array with the translation between the filtered and unfiltered list. */
unsigned int *line_map;
/** number of (unfiltered) elements to show. */
unsigned int num_lines;
/** Array with the levenshtein distance for each element. */
int *distance;
/** Array with the translation between the filtered and unfiltered list. */
unsigned int *line_map;
/** number of (unfiltered) elements to show. */
unsigned int num_lines;
/** number of (filtered) elements to show. */
unsigned int filtered_lines;
/** number of (filtered) elements to show. */
unsigned int filtered_lines;
/** Previously called key action. */
KeyBindingAction prev_action;
/** Time previous key action was executed. */
xcb_timestamp_t last_button_press;
/** Previously called key action. */
KeyBindingAction prev_action;
/** Time previous key action was executed. */
xcb_timestamp_t last_button_press;
/** Indicate view should terminate */
int quit;
/** Indicate if we should absorb the key release */
int skip_absorb;
/** The selected line (in the unfiltered list) */
unsigned int selected_line;
/** The return state of the view */
MenuReturn retv;
/** Monitor #workarea the view is displayed on */
workarea mon;
/** Indicate view should terminate */
int quit;
/** Indicate if we should absorb the key release */
int skip_absorb;
/** The selected line (in the unfiltered list) */
unsigned int selected_line;
/** The return state of the view */
MenuReturn retv;
/** Monitor #workarea the view is displayed on */
workarea mon;
/** #box holding the different modi buttons */
box *sidebar_bar;
/** number of modi to display */
unsigned int num_modi;
/** Array of #textbox that act as buttons for switching modi */
textbox **modi;
/** #box holding the different modi buttons */
box *sidebar_bar;
/** number of modi to display */
unsigned int num_modi;
/** Array of #textbox that act as buttons for switching modi */
textbox **modi;
/** Total rows. */
textbox *tb_total_rows;
/** filtered rows */
textbox *tb_filtered_rows;
/** Total rows. */
textbox *tb_total_rows;
/** filtered rows */
textbox *tb_filtered_rows;
/** Settings of the menu */
MenuFlags menu_flags;
/** If mouse was within view previously */
int mouse_seen;
/** Flag indicating if view needs to be reloaded. */
int reload;
/** The function to be called when finalizing this view */
void ( *finalize )( struct RofiViewState *state );
/** Settings of the menu */
MenuFlags menu_flags;
/** If mouse was within view previously */
int mouse_seen;
/** Flag indicating if view needs to be reloaded. */
int reload;
/** The function to be called when finalizing this view */
void (*finalize)(struct RofiViewState *state);
/** Width of the view */
int width;
/** Height of the view */
int height;
/** X position of the view */
int x;
/** Y position of the view */
int y;
/** Width of the view */
int width;
/** Height of the view */
int height;
/** X position of the view */
int x;
/** Y position of the view */
int y;
#ifdef ENABLE_WAYLAND
/** wayland */
display_buffer_pool *pool;
gboolean frame_callback;
/** wayland */
display_buffer_pool *pool;
gboolean frame_callback;
#endif
/** Position and target of the mouse. */
struct
{
/** X position */
int x;
/** Y position */
int y;
/** Widget being targeted. */
widget *motion_target;
} mouse;
/** Position and target of the mouse. */
struct {
/** X position */
int x;
/** Y position */
int y;
/** Widget being targeted. */
widget *motion_target;
} mouse;
/** Regexs used for matching */
rofi_int_matcher **tokens;
/** Regexs used for matching */
rofi_int_matcher **tokens;
};
/** @} */
typedef struct _view_proxy
{
void ( *update )( RofiViewState *state, gboolean qr );
void ( *maybe_update )( RofiViewState *state );
void ( *temp_configure_notify )( RofiViewState *state, xcb_configure_notify_event_t *xce );
void ( *temp_click_to_exit )( RofiViewState *state, xcb_window_t target );
void ( *frame_callback )( void );
typedef struct _view_proxy {
void (*update)(RofiViewState *state, gboolean qr);
void (*maybe_update)(RofiViewState *state);
void (*temp_configure_notify)(RofiViewState *state,
xcb_configure_notify_event_t *xce);
void (*temp_click_to_exit)(RofiViewState *state, xcb_window_t target);
void (*frame_callback)(void);
void ( *queue_redraw )( void );
void (*queue_redraw)(void);
void ( *set_window_title )( const char * title );
void ( *calculate_window_position )( RofiViewState *state );
void ( *calculate_window_width )( RofiViewState *state );
int ( *calculate_window_height )( RofiViewState *state );
void ( *window_update_size )( RofiViewState *state );
void ( *set_cursor )( RofiCursorType type );
void ( *ping_mouse )( RofiViewState *state );
void (*set_window_title)(const char *title);
void (*calculate_window_position)(RofiViewState *state);
void (*calculate_window_width)(RofiViewState *state);
int (*calculate_window_height)(RofiViewState *state);
void (*window_update_size)(RofiViewState *state);
void (*set_cursor)(RofiCursorType type);
void (*ping_mouse)(RofiViewState *state);
void ( *cleanup )( void );
void ( *hide )( void );
void ( *reload )( void );
void ( *__create_window )( MenuFlags menu_flags );
xcb_window_t ( *get_window )( void );
void (*cleanup)(void);
void (*hide)(void);
void (*reload)(void);
void (*__create_window)(MenuFlags menu_flags);
xcb_window_t (*get_window)(void);
void ( *get_current_monitor )( int *width, int *height );
void ( *capture_screenshot )( void );
void (*get_current_monitor)(int *width, int *height);
void (*capture_screenshot)(void);
void ( *set_size )( RofiViewState * state, gint width, gint height );
void ( *get_size )( RofiViewState * state, gint *width, gint *height );
void (*set_size)(RofiViewState *state, gint width, gint height);
void (*get_size)(RofiViewState *state, gint *width, gint *height);
void ( *pool_refresh )( );
void (*pool_refresh)();
} view_proxy;
/**
* Structure holding cached state.
*/
struct _rofi_view_cache_state
{
/** main x11 windows */
xcb_window_t main_window;
/** Main flags */
MenuFlags flags;
/** List of stacked views */
GQueue views;
/** User timeout */
guint user_timeout;
struct _rofi_view_cache_state {
/** main x11 windows */
xcb_window_t main_window;
/** Main flags */
MenuFlags flags;
/** List of stacked views */
GQueue views;
/** User timeout */
guint user_timeout;
};
extern struct _rofi_view_cache_state CacheState;
void rofi_view_update ( struct RofiViewState *state, gboolean qr );
void rofi_view_calculate_window_position ( struct RofiViewState *state );
void rofi_view_calculate_window_width ( struct RofiViewState *state );
int rofi_view_calculate_window_height ( struct RofiViewState *state );
void rofi_view_window_update_size ( struct RofiViewState * state );
void rofi_view_refilter ( struct RofiViewState *state );
void rofi_view_set_window_title ( const char * title );
void rofi_view_update(struct RofiViewState *state, gboolean qr);
void rofi_view_calculate_window_position(struct RofiViewState *state);
void rofi_view_calculate_window_width(struct RofiViewState *state);
int rofi_view_calculate_window_height(struct RofiViewState *state);
void rofi_view_window_update_size(struct RofiViewState *state);
void rofi_view_refilter(struct RofiViewState *state);
void rofi_view_set_window_title(const char *title);
#endif

View file

@ -27,7 +27,9 @@
#ifndef ROFI_VIEW_H
#define ROFI_VIEW_H
#include "mode.h"
#include <xcb/xcb.h>
/**
* @defgroup View View
@ -44,18 +46,17 @@
* @{
*/
typedef struct RofiViewState RofiViewState;
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,
/** INDICATOR */
MENU_INDICATOR = 8,
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,
/** INDICATOR */
MENU_INDICATOR = 8,
} MenuFlags;
/**
@ -68,14 +69,16 @@ typedef enum
*
* @returns The command issued (see MenuReturn)
*/
RofiViewState *rofi_view_create ( Mode *sw, const char *input, MenuFlags menu_flags, void ( *finalize )( RofiViewState * ) );
RofiViewState *rofi_view_create(Mode *sw, const char *input,
MenuFlags menu_flags,
void (*finalize)(RofiViewState *));
/**
* @param state The Menu Handle
*
* Check if a finalize function is set, and if sets executes it.
*/
void rofi_view_finalize ( RofiViewState *state );
void rofi_view_finalize(RofiViewState *state);
/**
* @param state the Menu handle
@ -84,7 +87,7 @@ void rofi_view_finalize ( RofiViewState *state );
*
* @returns the return value
*/
MenuReturn rofi_view_get_return_value ( const RofiViewState *state );
MenuReturn rofi_view_get_return_value(const RofiViewState *state);
/**
* @param state the Menu handle
*
@ -92,14 +95,14 @@ MenuReturn rofi_view_get_return_value ( const RofiViewState *state );
*
* @return the next position.
*/
unsigned int rofi_view_get_next_position ( const RofiViewState *state );
unsigned int rofi_view_get_next_position(const RofiViewState *state);
/**
* @param state the Menu handle
* @param text The text to add to the input box
*
* Update the state if needed.
*/
void rofi_view_handle_text ( RofiViewState *state, char *text );
void rofi_view_handle_text(RofiViewState *state, char *text);
/**
* @param state the Menu handle
* @param x The X coordinates of the motion
@ -108,31 +111,33 @@ void rofi_view_handle_text ( RofiViewState *state, char *text );
*
* Update the state if needed.
*/
void rofi_view_handle_mouse_motion ( RofiViewState *state, gint x, gint y, gboolean find_mouse_target );
void rofi_view_handle_mouse_motion(RofiViewState *state, gint x, gint y,
gboolean find_mouse_target);
/**
* @param state the Menu handle
*
* Update the state if needed.
*/
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 );
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);
/**
* Update the state if needed.
*/
void rofi_view_frame_callback ( void );
void rofi_view_frame_callback(void);
/**
* @param state the Menu handle
*
* @returns returns if this state is completed.
*/
unsigned int rofi_view_get_completed ( const RofiViewState *state );
unsigned int rofi_view_get_completed(const RofiViewState *state);
/**
* @param state the Menu handle
*
* @returns the raw user input.
*/
const char * rofi_view_get_user_input ( const RofiViewState *state );
const char *rofi_view_get_user_input(const RofiViewState *state);
/**
* @param state The Menu Handle
@ -140,7 +145,8 @@ const char * rofi_view_get_user_input ( const RofiViewState *state );
*
* Select a line.
*/
void rofi_view_set_selected_line ( RofiViewState *state, unsigned int selected_line );
void rofi_view_set_selected_line(RofiViewState *state,
unsigned int selected_line);
/**
* @param state The Menu Handle
@ -149,14 +155,14 @@ void rofi_view_set_selected_line ( RofiViewState *state, unsigned int selected_l
*
* @returns the selected line or UINT32_MAX if none selected.
*/
unsigned int rofi_view_get_selected_line ( const RofiViewState *state );
unsigned int rofi_view_get_selected_line(const RofiViewState *state);
/**
* @param state The Menu Handle
*
* Restart the menu so it can be displayed again.
* Resets RofiViewState::quit and RofiViewState::retv.
*/
void rofi_view_restart ( RofiViewState *state );
void rofi_view_restart(RofiViewState *state);
/**
* @param state The handle to the view
@ -165,7 +171,8 @@ void rofi_view_restart ( RofiViewState *state );
*
* @returns TRUE if action was handled.
*/
gboolean rofi_view_trigger_action ( RofiViewState *state, BindingsScope scope, guint action );
gboolean rofi_view_trigger_action(RofiViewState *state, BindingsScope scope,
guint action);
/**
* @param state The handle to the view
@ -173,7 +180,7 @@ gboolean rofi_view_trigger_action ( RofiViewState *state, BindingsScope scope, g
* Free's the memory allocated for this handle.
* After a call to this function, state is invalid and can no longer be used.
*/
void rofi_view_free ( RofiViewState *state );
void rofi_view_free(RofiViewState *state);
/** @} */
/**
* @defgroup ViewGlobal ViewGlobal
@ -189,7 +196,7 @@ void rofi_view_free ( RofiViewState *state );
*
* @returns the active view handle or NULL
*/
RofiViewState * rofi_view_get_active ( void );
RofiViewState *rofi_view_get_active(void);
/**
* @param state the new active view handle.
@ -199,7 +206,7 @@ RofiViewState * rofi_view_get_active ( void );
*
*/
void rofi_view_set_active ( RofiViewState *state );
void rofi_view_set_active(RofiViewState *state);
/**
* @param state remove view handle.
@ -208,27 +215,27 @@ void rofi_view_set_active ( RofiViewState *state );
* stack.
*
*/
void rofi_view_remove_active ( RofiViewState *state );
void rofi_view_remove_active(RofiViewState *state);
/**
* @param msg The error message to show.
* @param markup The error message uses pango markup.
*
* The error message to show.
*/
int rofi_view_error_dialog ( const char *msg, int markup );
int rofi_view_error_dialog(const char *msg, int markup);
/**
* Queue a redraw.
* This triggers a X11 Expose Event.
*/
void rofi_view_queue_redraw ( void );
void rofi_view_queue_redraw(void);
void rofi_view_calculate_window_position ( RofiViewState *state );
void rofi_view_calculate_window_position(RofiViewState *state);
/**
* Cleanup internal data of the view.
*/
void rofi_view_cleanup ( void );
void rofi_view_cleanup(void);
/**
* @param state The handle to the view
@ -237,12 +244,12 @@ void rofi_view_cleanup ( void );
*
* @returns the mode currently displayed by the view
*/
Mode * rofi_view_get_mode ( RofiViewState *state );
Mode *rofi_view_get_mode(RofiViewState *state);
/**
* Unmap the current view.
*/
void rofi_view_hide ( void );
void rofi_view_hide(void);
/**
* Indicate the current view needs to reload its data.
@ -250,7 +257,7 @@ void rofi_view_hide ( void );
*
* The reloading happens 'lazy', multiple calls might be handled at once.
*/
void rofi_view_reload ( void );
void rofi_view_reload(void);
/**
* @param state The handle to the view
@ -258,7 +265,7 @@ void rofi_view_reload ( void );
*
* Change the current view to show a different mode.
*/
void rofi_view_switch_mode ( RofiViewState *state, Mode *mode );
void rofi_view_switch_mode(RofiViewState *state, Mode *mode);
/**
* @param state The handle to the view
@ -266,14 +273,14 @@ void rofi_view_switch_mode ( RofiViewState *state, Mode *mode );
*
* Overlays text over the current view. Passing NULL for text hides the overlay.
*/
void rofi_view_set_overlay ( RofiViewState *state, const char *text );
void rofi_view_set_overlay(RofiViewState *state, const char *text);
/**
* @param state The handle to the view.
*
* Clears the user entry box, set selected to 0.
*/
void rofi_view_clear_input ( RofiViewState *state );
void rofi_view_clear_input(RofiViewState *state);
/**
* @param menu_flags The state of the new window.
@ -281,33 +288,33 @@ void rofi_view_clear_input ( RofiViewState *state );
* Creates the internal 'Cached' window that gets reused between views.
* TODO: Internal call to view exposed.
*/
void __create_window ( MenuFlags menu_flags );
void __create_window(MenuFlags menu_flags);
/**
* Get the handle of the main window.
*
* @returns the xcb_window_t for rofi's view or XCB_WINDOW_NONE.
*/
xcb_window_t rofi_view_get_window ( void );
xcb_window_t rofi_view_get_window(void);
/** @} */
/***
* @defgroup ViewThreadPool ViewThreadPool
* @ingroup View
*
* The view can (optionally) keep a set of worker threads around to parallize work.
* This includes filtering and sorting.
* The view can (optionally) keep a set of worker threads around to parallize
* work. This includes filtering and sorting.
*
* @{
*/
/**
* Initialize the threadpool
*/
void rofi_view_workers_initialize ( void );
void rofi_view_workers_initialize(void);
/**
* Stop all threads and free the resources used by the threadpool
*/
void rofi_view_workers_finalize ( void );
void rofi_view_workers_finalize(void);
/**
* @param width the width of the monitor.
@ -316,32 +323,32 @@ void rofi_view_workers_finalize ( void );
* Return the current monitor workarea.
*
*/
void rofi_view_get_current_monitor ( int *width, int *height );
void rofi_view_get_current_monitor(int *width, int *height);
/**
* Takes a screenshot.
*/
void rofi_capture_screenshot ( void );
void rofi_capture_screenshot(void);
/**
* Set the window title.
*/
void rofi_view_set_window_title ( const char * title );
void rofi_view_set_window_title(const char *title);
/**
* set ellipsize mode to start.
*/
void rofi_view_ellipsize_start ( RofiViewState *state );
void rofi_view_ellipsize_start(RofiViewState *state);
void rofi_view_set_size ( RofiViewState * state, gint width, gint height );
void rofi_view_set_size(RofiViewState *state, gint width, gint height);
void rofi_view_get_size ( RofiViewState * state, gint *width, gint *height );
void rofi_view_get_size(RofiViewState *state, gint *width, gint *height);
void rofi_view_ping_mouse ( RofiViewState *state );
void rofi_view_ping_mouse(RofiViewState *state);
void rofi_view_set_window_title ( const char * title );
void rofi_view_pool_refresh ( void );
void rofi_view_set_window_title(const char *title);
void rofi_view_pool_refresh(void);
void rofi_view_set_cursor ( RofiCursorType type );
void rofi_view_set_cursor(RofiCursorType type);
struct _view_proxy;
@ -351,7 +358,7 @@ extern const struct _view_proxy *xcb_view_proxy;
extern const struct _view_proxy *wayland_view_proxy;
#endif
void view_init ( const struct _view_proxy *view_in );
void view_init(const struct _view_proxy *view_in);
/** @} */
#endif

View file

@ -1,112 +1,104 @@
#ifndef ROFI_WAYLAND_INTERNAL_H
#define ROFI_WAYLAND_INTERNAL_H
#include <glib.h>
#include <cairo.h>
#include <xkbcommon/xkbcommon.h>
#include <xcb/xkb.h>
#include <wayland-client.h>
#include <glib.h>
#include <libgwater-wayland.h>
#include <nkutils-bindings.h>
#include <wayland-client.h>
#include <xcb/xkb.h>
#include <xkbcommon/xkbcommon.h>
#include "wayland.h"
typedef enum
{
WAYLAND_GLOBAL_COMPOSITOR,
WAYLAND_GLOBAL_SHM,
WAYLAND_GLOBAL_LAYER_SHELL,
_WAYLAND_GLOBAL_SIZE,
typedef enum {
WAYLAND_GLOBAL_COMPOSITOR,
WAYLAND_GLOBAL_SHM,
WAYLAND_GLOBAL_LAYER_SHELL,
_WAYLAND_GLOBAL_SIZE,
} wayland_global_name;
typedef struct
{
uint32_t button;
char modifiers;
gint x, y;
gboolean pressed;
guint32 time;
typedef struct {
uint32_t button;
char modifiers;
gint x, y;
gboolean pressed;
guint32 time;
} widget_button_event;
typedef struct
{
gint x, y;
guint32 time;
typedef struct {
gint x, y;
guint32 time;
} widget_motion_event;
typedef struct _wayland_seat wayland_seat;
typedef struct
{
GMainLoop *main_loop;
GWaterWaylandSource *main_loop_source;
struct wl_display *display;
struct wl_registry *registry;
uint32_t global_names[_WAYLAND_GLOBAL_SIZE];
struct wl_compositor *compositor;
struct zww_launcher_menu_v1 *launcher_menu;
struct zww_window_switcher_v1 *window_switcher;
typedef struct {
GMainLoop *main_loop;
GWaterWaylandSource *main_loop_source;
struct wl_display *display;
struct wl_registry *registry;
uint32_t global_names[_WAYLAND_GLOBAL_SIZE];
struct wl_compositor *compositor;
struct zww_launcher_menu_v1 *launcher_menu;
struct zww_window_switcher_v1 *window_switcher;
struct zwlr_layer_shell_v1 *layer_shell;
struct zwlr_layer_shell_v1 *layer_shell;
struct wl_shm *shm;
size_t buffer_count;
struct
{
char *theme_name;
char **name;
struct wl_cursor_theme *theme;
struct wl_cursor *cursor;
struct wl_cursor_image *image;
struct wl_surface *surface;
struct wl_callback *frame_cb;
} cursor;
GHashTable *seats;
GHashTable *seats_by_name;
wayland_seat *last_seat;
GHashTable *outputs;
struct wl_surface *surface;
struct zwlr_layer_surface_v1* wlr_surface;
struct wl_callback *frame_cb;
size_t scales[3];
int32_t scale;
NkBindingsSeat *bindings_seat;
struct wl_shm *shm;
size_t buffer_count;
struct {
char *theme_name;
char **name;
struct wl_cursor_theme *theme;
struct wl_cursor *cursor;
struct wl_cursor_image *image;
struct wl_surface *surface;
struct wl_callback *frame_cb;
} cursor;
GHashTable *seats;
GHashTable *seats_by_name;
wayland_seat *last_seat;
GHashTable *outputs;
struct wl_surface *surface;
struct zwlr_layer_surface_v1 *wlr_surface;
struct wl_callback *frame_cb;
size_t scales[3];
int32_t scale;
NkBindingsSeat *bindings_seat;
uint32_t layer_width;
uint32_t layer_height;
uint32_t layer_width;
uint32_t layer_height;
} wayland_stuff;
struct _wayland_seat
{
wayland_stuff *context;
uint32_t global_name;
struct wl_seat *seat;
gchar *name;
struct
{
xkb_keycode_t key;
GSource *source;
int32_t rate;
int32_t delay;
} repeat;
uint32_t serial;
struct wl_keyboard *keyboard;
struct wl_pointer *pointer;
widget_button_event button;
widget_motion_event motion;
struct
{
gint vertical;
gint horizontal;
} wheel;
struct _wayland_seat {
wayland_stuff *context;
uint32_t global_name;
struct wl_seat *seat;
gchar *name;
struct {
xkb_keycode_t key;
GSource *source;
int32_t rate;
int32_t delay;
} repeat;
uint32_t serial;
struct wl_keyboard *keyboard;
struct wl_pointer *pointer;
widget_button_event button;
widget_motion_event motion;
struct {
gint vertical;
gint horizontal;
} wheel;
};
/* Supported interface versions */
#define WL_COMPOSITOR_INTERFACE_VERSION 3
#define WL_SHM_INTERFACE_VERSION 1
#define WL_SEAT_INTERFACE_VERSION 5
#define WL_OUTPUT_INTERFACE_VERSION 2
#define WL_LAYER_SHELL_INTERFACE_VERSION 1
#define WL_COMPOSITOR_INTERFACE_VERSION 3
#define WL_SHM_INTERFACE_VERSION 1
#define WL_SEAT_INTERFACE_VERSION 5
#define WL_OUTPUT_INTERFACE_VERSION 2
#define WL_LAYER_SHELL_INTERFACE_VERSION 1
extern wayland_stuff *wayland;

View file

@ -28,8 +28,8 @@
#ifndef ROFI_WAYLAND_H
#define ROFI_WAYLAND_H
#include <glib.h>
#include <cairo.h>
#include <glib.h>
#include "display.h"
@ -40,7 +40,7 @@ void display_buffer_pool_free(display_buffer_pool *pool);
cairo_surface_t *display_buffer_pool_get_next_buffer(display_buffer_pool *pool);
void display_surface_commit(cairo_surface_t *surface);
gboolean display_get_surface_dimensions ( int *width, int *height );
void display_set_surface_dimensions ( int width, int height, int loc );
gboolean display_get_surface_dimensions(int *width, int *height);
void display_set_surface_dimensions(int width, int height, int loc);
#endif

View file

@ -28,16 +28,18 @@
#ifndef ROFI_HBOX_H
#define ROFI_HBOX_H
#include "rofi-types.h"
#include "widget.h"
#include "rofi-types.h"
/**
* @defgroup box box
* @ingroup widget
*
* Widget used to pack multiple widgets either horizontally or vertically.
* It supports packing widgets horizontally or vertically. Child widgets are always
* expanded to the maximum size in the opposite direction of the packing direction.
* e.g. vertically packed widgets use the full box width.
* It supports packing widgets horizontally or vertically. Child widgets are
* always expanded to the maximum size in the opposite direction of the packing
* direction. e.g. vertically packed widgets use the full box width.
*
* @{
*/
@ -54,7 +56,7 @@ typedef struct _box box;
*
* @returns a newly created box, free with #widget_free
*/
box * box_create ( widget *parent, const char *name, RofiOrientation type );
box *box_create(widget *parent, const char *name, RofiOrientation type);
/**
* @param box Handle to the box widget.
@ -63,6 +65,6 @@ box * box_create ( widget *parent, const char *name, RofiOrientation type );
*
* Add a widget to the box.
*/
void box_add ( box *box, widget *child, gboolean expand );
void box_add(box *box, widget *child, gboolean expand);
/**@}*/
#endif // ROFI_HBOX_H

View file

@ -49,7 +49,7 @@ typedef struct _container container;
*
* @returns a newly created container, free with #widget_free
*/
container * container_create ( widget *parent, const char *name );
container *container_create(widget *parent, const char *name);
/**
* @param container Handle to the container widget.
@ -57,6 +57,6 @@ container * container_create ( widget *parent, const char *name );
*
* Add a widget to the container.
*/
void container_add ( container *container, widget *child );
void container_add(container *container, widget *child);
/**@}*/
#endif // ROFI_CONTAINER_H

View file

@ -49,19 +49,19 @@ typedef struct _icon icon;
*
* @returns a newly created icon, free with #widget_free
*/
icon * icon_create ( widget *parent, const char *name );
icon *icon_create(widget *parent, const char *name);
/**
* @param icon The icon widget handle.
* @param size The size of the icon.
*
*/
void icon_set_size ( widget *icon, const int size );
void icon_set_size(widget *icon, const int size);
/**
* @param icon The icon widget handle.
* @param surf The surface to display.
*/
void icon_set_surface ( icon *icon, cairo_surface_t *surf );
void icon_set_surface(icon *icon, cairo_surface_t *surf);
/**@}*/
#endif // ROFI_ICON_H

View file

@ -28,6 +28,8 @@
#ifndef ROFI_LISTVIEW_H
#define ROFI_LISTVIEW_H
#include "widgets/textbox.h"
/**
* @defgroup listview listview
* @ingroup widget
@ -44,29 +46,31 @@ typedef struct _listview listview;
/**
* The scrolling type used in the list view
*/
typedef enum
{
/** Flip through the pages. */
LISTVIEW_SCROLL_PER_PAGE,
/** keep selected item centered */
LISTVIEW_SCROLL_CONTINIOUS
typedef enum {
/** Flip through the pages. */
LISTVIEW_SCROLL_PER_PAGE,
/** keep selected item centered */
LISTVIEW_SCROLL_CONTINIOUS
} ScrollType;
/**
* @param tb The textbox to set
* @param entry The position of the textbox
* @param udata User data
* @param type The textbox font style to apply to this entry (normal, selected, alternative row)
* @param type The textbox font style to apply to this entry (normal, selected,
* alternative row)
* @param full If true Set both text and style.
*
* Update callback, this is called to set the value of each (visible) element.
*/
typedef void ( *listview_update_callback )( textbox *tb, icon *ico, unsigned int entry, void *udata, TextBoxFontType *type, gboolean full );
typedef void (*listview_update_callback)(textbox *tb, icon *ico,
unsigned int entry, void *udata,
TextBoxFontType *type, gboolean full);
/**
* Callback when a element is activated.
*/
typedef void ( *listview_mouse_activated_cb )( listview *, gboolean, void * );
typedef void (*listview_mouse_activated_cb)(listview *, gboolean, void *);
/**
* @param parent The widget's parent.
@ -78,7 +82,9 @@ typedef void ( *listview_mouse_activated_cb )( listview *, gboolean, void * );
*
* @returns a new listview
*/
listview *listview_create ( widget *parent, const char *name, listview_update_callback cb, void *udata, unsigned int eh, gboolean reverse );
listview *listview_create(widget *parent, const char *name,
listview_update_callback cb, void *udata,
unsigned int eh, gboolean reverse);
/**
* @param lv The listview handle
@ -86,7 +92,7 @@ listview *listview_create ( widget *parent, const char *name, listview_update_ca
*
* Set the maximum number of elements to display.
*/
void listview_set_num_elements ( listview *lv, unsigned int rows );
void listview_set_num_elements(listview *lv, unsigned int rows);
/**
* @param lv The listview handle
@ -94,7 +100,7 @@ void listview_set_num_elements ( listview *lv, unsigned int rows );
*
* Select the row, if selected > the number of rows, it selects the last one.
*/
void listview_set_selected ( listview *lv, unsigned int selected );
void listview_set_selected(listview *lv, unsigned int selected);
/**
* @param lv The listview handle
@ -103,7 +109,7 @@ void listview_set_selected ( listview *lv, unsigned int selected );
*
* @returns the selected row.
*/
unsigned int listview_get_selected ( listview *lv );
unsigned int listview_get_selected(listview *lv);
/**
* @param lv The listview handle
@ -111,14 +117,14 @@ unsigned int listview_get_selected ( listview *lv );
* Move the selection one row up.
* - Wrap around.
*/
void listview_nav_up ( listview *lv );
void listview_nav_up(listview *lv);
/**
* @param lv listview handle.
*
* Move the selection one row down.
* - Wrap around.
*/
void listview_nav_down ( listview *lv );
void listview_nav_down(listview *lv);
/**
* @param lv The listview handle
*
@ -126,14 +132,14 @@ void listview_nav_down ( listview *lv );
* - No wrap around.
* - Do not move to top row when at start.
*/
void listview_nav_right ( listview *lv );
void listview_nav_right(listview *lv);
/**
* @param lv The listview handle
*
* Move the selection one column to the left.
* - No wrap around.
*/
void listview_nav_left ( listview *lv );
void listview_nav_left(listview *lv);
/**
* @param lv The listview handle
*
@ -141,7 +147,7 @@ void listview_nav_left ( listview *lv );
* - No wrap around.
* - Clip at top/bottom
*/
void listview_nav_page_next ( listview *lv );
void listview_nav_page_next(listview *lv);
/**
* @param lv The listview handle
@ -150,7 +156,7 @@ void listview_nav_page_next ( listview *lv );
* - No wrap around.
* - Clip at top/bottom
*/
void listview_nav_page_prev ( listview *lv );
void listview_nav_page_prev(listview *lv);
/**
* @param lv Handler to the listview object
@ -158,14 +164,14 @@ void listview_nav_page_prev ( listview *lv );
*
* Hide the scrollbar.
*/
void listview_set_show_scrollbar ( listview *lv, gboolean enabled );
void listview_set_show_scrollbar(listview *lv, gboolean enabled);
/**
* @param lv Handler to the listview object
* @param width Width in pixels
*
* Set the width of the scrollbar
*/
void listview_set_scrollbar_width ( listview *lv, unsigned int width );
void listview_set_scrollbar_width(listview *lv, unsigned int width);
/**
* @param lv Handler to the listview object
@ -173,14 +179,15 @@ void listview_set_scrollbar_width ( listview *lv, unsigned int width );
*
* Set cycle mode. On last entry go to first.
*/
void listview_set_cycle ( listview *lv, gboolean cycle );
void listview_set_cycle(listview *lv, gboolean cycle);
/**
* @param lv Handler to the listview object
* @param type ScrollType
*
* Set the scroll type ScrollType::LISTVIEW_SCROLL_CONTINIOUS or ScrollType::LISTVIEW_SCROLL_PER_PAGE
* Set the scroll type ScrollType::LISTVIEW_SCROLL_CONTINIOUS or
* ScrollType::LISTVIEW_SCROLL_PER_PAGE
*/
void listview_set_scroll_type ( listview *lv, ScrollType type );
void listview_set_scroll_type(listview *lv, ScrollType type);
/**
* @param lv Handler to the listview object
@ -189,21 +196,23 @@ void listview_set_scroll_type ( listview *lv, ScrollType type );
*
* Set the mouse activated callback.
*/
void listview_set_mouse_activated_cb ( listview *lv, listview_mouse_activated_cb cb, void *udata );
void listview_set_mouse_activated_cb(listview *lv,
listview_mouse_activated_cb cb,
void *udata);
/**
* @param lv Handler to the listview object
* @param enable boolean to enable/disable multi-select
*
* Enable,disable multi-select.
*/
void listview_set_multi_select ( listview *lv, gboolean enable );
void listview_set_multi_select(listview *lv, gboolean enable);
/**
* @param lv Handler to the listview object.
* @param num_lines the maximum number of lines to display.
*
* Set the maximum number of lines to display.
*/
void listview_set_num_lines ( listview *lv, unsigned int num_lines );
void listview_set_num_lines(listview *lv, unsigned int num_lines);
/**
* @param lv Handler to the listview object.
@ -212,7 +221,7 @@ void listview_set_num_lines ( listview *lv, unsigned int num_lines );
*
* @returns get the number of lines to display.
*/
unsigned int listview_get_num_lines ( listview *lv );
unsigned int listview_get_num_lines(listview *lv);
/**
* @param lv Handler to the listview object.
@ -221,14 +230,14 @@ unsigned int listview_get_num_lines ( listview *lv );
*
* @returns get fixed-height.
*/
gboolean listview_get_fixed_num_lines ( listview *lv );
gboolean listview_get_fixed_num_lines(listview *lv);
/**
* @param lv Handler to the listview object.
*
* Set fixed num lines mode.
*/
void listview_set_fixed_num_lines ( listview *lv );
void listview_set_fixed_num_lines(listview *lv);
/**
* @param lv Handler to the listview object.
@ -236,14 +245,14 @@ void listview_set_fixed_num_lines ( listview *lv );
*
* Set the maximum number of lines to display.
*/
void listview_set_max_lines ( listview *lv, unsigned int max_lines );
void listview_set_max_lines(listview *lv, unsigned int max_lines);
/**
* @param lv Handler to the listview object.
*
* Set ellipsize mode.
*/
void listview_toggle_ellipsizing ( listview *lv );
void listview_toggle_ellipsizing(listview *lv);
/**
* @param lv Handler to the listview object.
@ -251,7 +260,7 @@ void listview_toggle_ellipsizing ( listview *lv );
* Set ellipsize mode to start.
*/
void listview_set_ellipsize_start ( listview *lv );
void listview_set_ellipsize_start(listview *lv);
/** @} */
#endif // ROFI_LISTVIEW_H

View file

@ -27,9 +27,9 @@
#ifndef ROFI_SCROLLBAR_H
#define ROFI_SCROLLBAR_H
#include <cairo.h>
#include "widgets/widget.h"
#include "widgets/widget-internal.h"
#include "widgets/widget.h"
#include <cairo.h>
/**
* @defgroup Scrollbar Scrollbar
@ -40,13 +40,12 @@
/**
* Internal structure for the scrollbar.
*/
typedef struct _scrollbar
{
widget widget;
unsigned int length;
unsigned int pos;
unsigned int pos_length;
RofiDistance width;
typedef struct _scrollbar {
widget widget;
unsigned int length;
unsigned int pos;
unsigned int pos_length;
RofiDistance width;
} scrollbar;
/**
@ -57,7 +56,7 @@ typedef struct _scrollbar
*
* @returns the scrollbar object.
*/
scrollbar *scrollbar_create ( widget *parent, const char *name );
scrollbar *scrollbar_create(widget *parent, const char *name);
/**
* @param sb scrollbar object
@ -65,7 +64,7 @@ scrollbar *scrollbar_create ( widget *parent, const char *name );
*
* set the length of the handle relative to the max value of bar.
*/
void scrollbar_set_handle_length ( scrollbar *sb, unsigned int pos_length );
void scrollbar_set_handle_length(scrollbar *sb, unsigned int pos_length);
/**
* @param sb scrollbar object
@ -73,7 +72,7 @@ void scrollbar_set_handle_length ( scrollbar *sb, unsigned int pos_length );
*
* set the position of the handle relative to the set max value of bar.
*/
void scrollbar_set_handle ( scrollbar *sb, unsigned int pos );
void scrollbar_set_handle(scrollbar *sb, unsigned int pos);
/**
* @param sb scrollbar object
@ -81,7 +80,7 @@ void scrollbar_set_handle ( scrollbar *sb, unsigned int pos );
*
* set the max value of the bar.
*/
void scrollbar_set_max_value ( scrollbar *sb, unsigned int max );
void scrollbar_set_max_value(scrollbar *sb, unsigned int max);
/**
* @param sb scrollbar object
@ -89,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
*/
guint scrollbar_scroll_get_line ( const scrollbar *sb, int y );
guint scrollbar_scroll_get_line(const scrollbar *sb, int y);
/**@}*/
#endif // ROFI_SCROLLBAR_H

View file

@ -28,14 +28,14 @@
#ifndef ROFI_TEXTBOX_H
#define ROFI_TEXTBOX_H
#include <xkbcommon/xkbcommon.h>
#include <pango/pango.h>
#include <pango/pango-fontmap.h>
#include <pango/pangocairo.h>
#include <cairo.h>
#include "widgets/widget.h"
#include "widgets/widget-internal.h"
#include "keyb.h"
#include "widgets/widget-internal.h"
#include "widgets/widget.h"
#include <cairo.h>
#include <pango/pango-fontmap.h>
#include <pango/pango.h>
#include <pango/pangocairo.h>
#include <xkbcommon/xkbcommon.h>
/**
* @defgroup Textbox Textbox
@ -44,83 +44,80 @@
* @{
*/
/** Cache to hold font descriptions. This it to avoid having to lookup each time. */
typedef struct TBFontConfig
{
/** Font description */
PangoFontDescription *pfd;
/** Font metrics */
PangoFontMetrics *metrics;
/** height */
double height;
}TBFontConfig;
/** Cache to hold font descriptions. This it to avoid having to lookup each
* time. */
typedef struct TBFontConfig {
/** Font description */
PangoFontDescription *pfd;
/** Font metrics */
PangoFontMetrics *metrics;
/** height */
double height;
} TBFontConfig;
/**
* Internal structure of a textbox widget.
* TODO make this internal to textbox
*/
typedef struct
{
widget widget;
unsigned long flags;
short cursor;
char *text;
const char *placeholder;
int show_placeholder;
PangoLayout *layout;
int tbft;
int markup;
int changed;
typedef struct {
widget widget;
unsigned long flags;
short cursor;
char *text;
const char *placeholder;
int show_placeholder;
PangoLayout *layout;
int tbft;
int markup;
int changed;
int blink;
guint blink_timeout;
int blink;
guint blink_timeout;
double yalign;
double xalign;
double yalign;
double xalign;
TBFontConfig *tbfc;
TBFontConfig *tbfc;
PangoEllipsizeMode emode;
//
const char *theme_name;
PangoEllipsizeMode emode;
//
const char *theme_name;
} textbox;
/**
* Flags for configuring textbox behaviour and looks during creation.
*/
typedef enum
{
TB_AUTOHEIGHT = 1 << 0,
TB_AUTOWIDTH = 1 << 1,
TB_EDITABLE = 1 << 19,
TB_MARKUP = 1 << 20,
TB_WRAP = 1 << 21,
TB_PASSWORD = 1 << 22,
TB_INDICATOR = 1 << 23,
typedef enum {
TB_AUTOHEIGHT = 1 << 0,
TB_AUTOWIDTH = 1 << 1,
TB_EDITABLE = 1 << 19,
TB_MARKUP = 1 << 20,
TB_WRAP = 1 << 21,
TB_PASSWORD = 1 << 22,
TB_INDICATOR = 1 << 23,
} TextboxFlags;
/**
* Flags indicating current state of the textbox.
*/
typedef enum
{
/** Normal */
NORMAL = 0,
/** Text in box is urgent. */
URGENT = 1,
/** Text in box is active. */
ACTIVE = 2,
/** Text in box is selected. */
SELECTED = 4,
/** Text in box has pango markup. */
MARKUP = 8,
typedef enum {
/** Normal */
NORMAL = 0,
/** Text in box is urgent. */
URGENT = 1,
/** Text in box is active. */
ACTIVE = 2,
/** Text in box is selected. */
SELECTED = 4,
/** Text in box has pango markup. */
MARKUP = 8,
/** Text is on an alternate row */
ALT = 16,
/** Render font highlighted (inverted colors.) */
HIGHLIGHT = 32,
/** Mask for alternate and highlighted */
FMOD_MASK = ( ALT | HIGHLIGHT ),
/** Mask of bits indicating state */
STATE_MASK = ~( SELECTED | MARKUP | ALT | HIGHLIGHT )
/** Text is on an alternate row */
ALT = 16,
/** Render font highlighted (inverted colors.) */
HIGHLIGHT = 32,
/** Mask for alternate and highlighted */
FMOD_MASK = (ALT | HIGHLIGHT),
/** Mask of bits indicating state */
STATE_MASK = ~(SELECTED | MARKUP | ALT | HIGHLIGHT)
} TextBoxFontType;
/**
@ -138,15 +135,16 @@ typedef enum
* free with #widget_free
* @returns a new #textbox
*/
textbox* textbox_create ( widget *parent, WidgetType type, const char *name, TextboxFlags flags,
TextBoxFontType tbft, const char *text, double xalign, double yalign );
textbox *textbox_create(widget *parent, WidgetType type, const char *name,
TextboxFlags flags, TextBoxFontType tbft,
const char *text, double xalign, double yalign);
/**
* @param tb Handle to the textbox
* @param tbft The style of font to render.
*
* Set the font render style.
*/
void textbox_font ( textbox *tb, TextBoxFontType tbft );
void textbox_font(textbox *tb, TextBoxFontType tbft);
/**
* @param tb Handle to the textbox
@ -154,7 +152,7 @@ void textbox_font ( textbox *tb, TextBoxFontType tbft );
*
* Set the text to show. Cursor is moved to end (if visible)
*/
void textbox_text ( textbox *tb, const char *text );
void textbox_text(textbox *tb, const char *text);
/**
* @param tb Handle to the textbox
@ -164,16 +162,16 @@ void textbox_text ( textbox *tb, const char *text );
*
* @return TRUE if action was taken.
*/
int textbox_keybinding ( textbox *tb, KeyBindingAction action );
int textbox_keybinding(textbox *tb, KeyBindingAction action);
/**
* @param tb Handle to the textbox
* @param pad The text to insert
* @param pad_len the length of the text
*
* The text should be one insert from a keypress.. the first gunichar is validated to be (or not) control
* return TRUE if inserted
* The text should be one insert from a keypress.. the first gunichar is
* validated to be (or not) control return TRUE if inserted
*/
gboolean textbox_append_text ( textbox *tb, const char *pad, const int pad_len );
gboolean textbox_append_text(textbox *tb, const char *pad, const int pad_len);
/**
* @param tb Handle to the textbox
@ -181,7 +179,7 @@ gboolean textbox_append_text ( textbox *tb, const char *pad, const int pad_len )
*
* Set the cursor position (string index)
*/
void textbox_cursor ( textbox *tb, int pos );
void textbox_cursor(textbox *tb, int pos);
/**
* @param tb Handle to the textbox
@ -191,19 +189,20 @@ void textbox_cursor ( textbox *tb, int pos );
*
* Insert the string str at position pos.
*/
void textbox_insert ( textbox *tb, const int char_pos, const char *str, const int slen );
void textbox_insert(textbox *tb, const int char_pos, const char *str,
const int slen);
/**
* Setup the cached fonts. This is required to do
* before any of the textbox_ functions is called.
* Clean with textbox_cleanup()
*/
void textbox_setup ( void );
void textbox_setup(void);
/**
* Cleanup the allocated colors and fonts by textbox_setup().
*/
void textbox_cleanup ( void );
void textbox_cleanup(void);
/**
* @param tb Handle to the textbox
@ -212,7 +211,7 @@ void textbox_cleanup ( void );
*
* @returns the height of the textbox in pixels.
*/
int textbox_get_height ( const textbox *tb );
int textbox_get_height(const textbox *tb);
/**
* @param tb Handle to the textbox
@ -221,7 +220,7 @@ int textbox_get_height ( const textbox *tb );
*
* @returns the height of the string in pixels.
*/
int textbox_get_font_height ( const textbox *tb );
int textbox_get_font_height(const textbox *tb);
/**
* @param tb Handle to the textbox
@ -230,27 +229,27 @@ int textbox_get_font_height ( const textbox *tb );
*
* @returns the width of the string in pixels.
*/
int textbox_get_font_width ( const textbox *tb );
int textbox_get_font_width(const textbox *tb);
/**
* Estimate the width of a character.
*
* @returns the width of a character in pixels.
*/
double textbox_get_estimated_char_width ( void );
double textbox_get_estimated_char_width(void);
/**
* Estimate the width of a 0.
*
* @returns the width of a 0 in pixels.
*/
double textbox_get_estimated_ch ( void );
double textbox_get_estimated_ch(void);
/**
* Estimate the height of a character.
*
* @returns the height of a character in pixels.
*/
double textbox_get_estimated_char_height ( void );
double textbox_get_estimated_char_height(void);
/**
* @param tb Handle to the textbox
@ -259,7 +258,7 @@ double textbox_get_estimated_char_height ( void );
*
* Remove dlen bytes from position pos.
*/
void textbox_delete ( textbox *tb, int pos, int dlen );
void textbox_delete(textbox *tb, int pos, int dlen);
/**
* @param tb Handle to the textbox
@ -271,32 +270,32 @@ void textbox_delete ( textbox *tb, int pos, int dlen );
* Move and resize the textbox.
* TODO remove for #widget_resize and #widget_move
*/
void textbox_moveresize ( textbox *tb, int x, int y, int w, int h );
void textbox_moveresize(textbox *tb, int x, int y, int w, int h);
/**
* @param tb Handle to the textbox
* @param eh The number of rows to display
*
* Get the (estimated) with of a character, can be used to calculate window width.
* This includes padding.
* Get the (estimated) with of a character, can be used to calculate window
* width. This includes padding.
*
* @returns the estimated width of a character.
*/
int textbox_get_estimated_height ( const textbox *tb, int eh );
int textbox_get_estimated_height(const textbox *tb, int eh);
/**
* @param font The name of the font used.
* @param p The new default PangoContext
*
* Set the default pango context (with font description) for all textboxes.
*/
void textbox_set_pango_context ( const char *font, PangoContext *p );
void textbox_set_pango_context(const char *font, PangoContext *p);
/**
* @param tb Handle to the textbox
* @param list New pango attributes
*
* Sets list as active pango attributes.
*/
void textbox_set_pango_attributes ( textbox *tb, PangoAttrList *list );
void textbox_set_pango_attributes(textbox *tb, PangoAttrList *list);
/**
* @param tb Handle to the textbox
@ -305,14 +304,14 @@ void textbox_set_pango_attributes ( textbox *tb, PangoAttrList *list );
*
* @returns the pango attributes
*/
PangoAttrList *textbox_get_pango_attributes ( textbox *tb );
PangoAttrList *textbox_get_pango_attributes(textbox *tb);
/**
* @param tb Handle to the textbox
*
* @returns the visible text.
*/
const char *textbox_get_visible_text ( const textbox *tb );
const char *textbox_get_visible_text(const textbox *tb);
/**
* @param wid The handle to the textbox.
*
@ -320,14 +319,14 @@ const char *textbox_get_visible_text ( const textbox *tb );
*
* @returns the desired width of the textbox.
*/
int textbox_get_desired_width ( widget *wid );
int textbox_get_desired_width(widget *wid);
/**
* @param tb Handle to the textbox
*
* Move the cursor to the end of the string.
*/
void textbox_cursor_end ( textbox *tb );
void textbox_cursor_end(textbox *tb);
/**
* @param tb Handle to the textbox
@ -335,6 +334,6 @@ void textbox_cursor_end ( textbox *tb );
*
* Set the ellipsizing mode used on the string.
*/
void textbox_set_ellipsize ( textbox *tb, PangoEllipsizeMode mode );
void textbox_set_ellipsize(textbox *tb, PangoEllipsizeMode mode);
/**@}*/
#endif //ROFI_TEXTBOX_H
#endif // ROFI_TEXTBOX_H

View file

@ -32,73 +32,72 @@
/**
* Data structure holding the internal state of the Widget
*/
struct _widget
{
/** The type of the widget */
WidgetType type;
/** X position relative to parent */
short x;
/** Y position relative to parent */
short y;
/** Width of the widget */
short w;
/** Height of the widget */
short h;
/** RofiPadding */
RofiPadding def_margin;
RofiPadding def_padding;
RofiPadding def_border;
RofiPadding def_border_radius;
RofiPadding margin;
RofiPadding padding;
RofiPadding border;
RofiPadding border_radius;
struct _widget {
/** The type of the widget */
WidgetType type;
/** X position relative to parent */
short x;
/** Y position relative to parent */
short y;
/** Width of the widget */
short w;
/** Height of the widget */
short h;
/** RofiPadding */
RofiPadding def_margin;
RofiPadding def_padding;
RofiPadding def_border;
RofiPadding def_border_radius;
RofiPadding margin;
RofiPadding padding;
RofiPadding border;
RofiPadding border_radius;
/** Cursor that is set when the widget is hovered */
RofiCursorType cursor_type;
/** Cursor that is set when the widget is hovered */
RofiCursorType cursor_type;
/** enabled or not */
gboolean enabled;
/** Expand the widget when packed */
gboolean expand;
/** Place widget at end of parent */
gboolean end;
/** Parent widget */
struct _widget *parent;
/** Internal */
gboolean need_redraw;
/** get width of widget implementation function */
int ( *get_width )( struct _widget * );
/** get height of widget implementation function */
int ( *get_height )( struct _widget * );
/** draw widget implementation function */
void ( *draw )( struct _widget *widget, cairo_t *draw );
/** resize widget implementation function */
void ( *resize )( struct _widget *, short, short );
/** update widget implementation function */
void ( *update )( struct _widget * );
/** enabled or not */
gboolean enabled;
/** Expand the widget when packed */
gboolean expand;
/** Place widget at end of parent */
gboolean end;
/** Parent widget */
struct _widget *parent;
/** Internal */
gboolean need_redraw;
/** get width of widget implementation function */
int (*get_width)(struct _widget *);
/** get height of widget implementation function */
int (*get_height)(struct _widget *);
/** draw widget implementation function */
void (*draw)(struct _widget *widget, cairo_t *draw);
/** resize widget implementation function */
void (*resize)(struct _widget *, short, short);
/** update widget implementation function */
void (*update)(struct _widget *);
/** Handle mouse motion, used for dragging */
gboolean ( *motion_notify )( struct _widget *, gint x, gint y );
/** Handle mouse motion, used for dragging */
gboolean (*motion_notify)(struct _widget *, gint x, gint y);
int ( *get_desired_height )( struct _widget * );
int ( *get_desired_width )( struct _widget * );
int (*get_desired_height)(struct _widget *);
int (*get_desired_width)(struct _widget *);
void ( *set_state ) ( struct _widget *, const char * );
void (*set_state)(struct _widget *, const char *);
/** 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;
/** 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 );
/** Free widget callback */
void (*free)(struct _widget *widget);
/** Name of widget (used for theming) */
char *name;
const char *state;
/** Name of widget (used for theming) */
char *name;
const char *state;
};
/**
@ -110,7 +109,8 @@ struct _widget
* Initializes the widget structure.
*
*/
void widget_init ( widget *wid, widget *parent, WidgetType type, const char *name );
void widget_init(widget *wid, widget *parent, WidgetType type,
const char *name);
/**
* @param widget The widget handle.
@ -118,7 +118,7 @@ void widget_init ( widget *wid, widget *parent, WidgetType type, const char *nam
*
* Set the state of the widget.
*/
void widget_set_state ( widget *widget, const char *state );
void widget_set_state(widget *widget, const char *state);
/**
* @param wid The widget handle.
@ -127,7 +127,7 @@ void widget_set_state ( widget *widget, const char *state );
*
* @returns the left padding in pixels.
*/
int widget_padding_get_left ( const widget *wid );
int widget_padding_get_left(const widget *wid);
/**
* @param wid The widget handle.
@ -136,7 +136,7 @@ int widget_padding_get_left ( const widget *wid );
*
* @returns the right padding in pixels.
*/
int widget_padding_get_right ( const widget *wid );
int widget_padding_get_right(const widget *wid);
/**
* @param wid The widget handle.
@ -145,7 +145,7 @@ int widget_padding_get_right ( const widget *wid );
*
* @returns the top padding in pixels.
*/
int widget_padding_get_top ( const widget *wid );
int widget_padding_get_top(const widget *wid);
/**
* @param wid The widget handle.
@ -154,7 +154,7 @@ int widget_padding_get_top ( const widget *wid );
*
* @returns the bottom padding in pixels.
*/
int widget_padding_get_bottom ( const widget *wid );
int widget_padding_get_bottom(const widget *wid);
/**
* @param wid The widget handle.
@ -163,7 +163,7 @@ int widget_padding_get_bottom ( const widget *wid );
*
* @returns the widget width, excluding padding.
*/
int widget_padding_get_remaining_width ( const widget *wid );
int widget_padding_get_remaining_width(const widget *wid);
/**
* @param wid The widget handle.
*
@ -171,7 +171,7 @@ int widget_padding_get_remaining_width ( const widget *wid );
*
* @returns the widget height, excluding padding.
*/
int widget_padding_get_remaining_height ( const widget *wid );
int widget_padding_get_remaining_height(const widget *wid);
/**
* @param wid The widget handle.
*
@ -179,7 +179,7 @@ int widget_padding_get_remaining_height ( const widget *wid );
*
* @returns the top and bottom padding of the widget in pixels.
*/
int widget_padding_get_padding_height ( const widget *wid );
int widget_padding_get_padding_height(const widget *wid);
/**
* @param wid The widget handle.
*
@ -187,5 +187,5 @@ int widget_padding_get_padding_height ( const widget *wid );
*
* @returns the left and right padding of the widget in pixels.
*/
int widget_padding_get_padding_width ( const widget *wid );
int widget_padding_get_padding_width(const widget *wid);
#endif // WIDGET_INTERNAL_H

View file

@ -27,19 +27,19 @@
#ifndef ROFI_WIDGET_H
#define ROFI_WIDGET_H
#include <glib.h>
#include "keyb.h"
#include <cairo.h>
#include <glib.h>
#include <xcb/xcb.h>
#include <xcb/xproto.h>
#include "keyb.h"
/**
* @defgroup widget widget
*
* 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.
* 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.
*
* @{
*/
@ -53,37 +53,35 @@ typedef struct _widget widget;
/**
* Type of the widget. It is used to bubble events to the relevant widget.
*/
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 widget allowing user to swithc between modi */
WIDGET_TYPE_MODE_SWITCHER = SCOPE_MOUSE_MODE_SWITCHER,
/** Text-only textbox */
WIDGET_TYPE_TEXTBOX_TEXT,
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 widget allowing user to swithc between modi */
WIDGET_TYPE_MODE_SWITCHER = SCOPE_MOUSE_MODE_SWITCHER,
/** Text-only textbox */
WIDGET_TYPE_TEXTBOX_TEXT,
} 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,
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;
/**
@ -92,11 +90,13 @@ typedef enum
* @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.
* 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 );
typedef widget *(*widget_find_mouse_target_cb)(widget *widget, WidgetType type,
gint x, gint y);
/**
* @param widget The target widget
@ -105,14 +105,18 @@ typedef widget * ( *widget_find_mouse_target_cb )( widget *widget, WidgetType ty
* @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.
* 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 );
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 ) )
#define WIDGET(a) ((widget *)(a))
/**
* @param widget The widget to check
@ -123,7 +127,7 @@ typedef WidgetTriggerActionResult ( *widget_trigger_action_cb )( widget *widget,
*
* @return TRUE if x,y falls within the widget
*/
int widget_intersect ( const widget *widget, int x, int y );
int widget_intersect(const widget *widget, int x, int y);
/**
* @param widget The widget to move
@ -132,7 +136,7 @@ int widget_intersect ( const widget *widget, int x, int y );
*
* Moves the widget.
*/
void widget_move ( widget *widget, short x, short y );
void widget_move(widget *widget, short x, short y);
/**
* @param widget Handle to widget
@ -140,7 +144,7 @@ void widget_move ( widget *widget, short x, short y );
* Get the type of the widget.
* @returns The type of the widget.
*/
WidgetType widget_type ( widget *widget );
WidgetType widget_type(widget *widget);
/**
* @param widget Handle to widget
@ -148,7 +152,7 @@ WidgetType widget_type ( widget *widget );
*
* Set the widget type.
*/
void widget_set_type ( widget *widget, WidgetType type );
void widget_set_type(widget *widget, WidgetType type);
/**
* @param widget Handle to widget
@ -156,7 +160,7 @@ void widget_set_type ( widget *widget, WidgetType type );
* Check if widget is enabled.
* @returns TRUE when widget is enabled.
*/
gboolean widget_enabled ( widget *widget );
gboolean widget_enabled(widget *widget);
/**
* @param widget Handle to widget
@ -164,27 +168,23 @@ gboolean widget_enabled ( widget *widget );
*
* Disable the widget.
*/
void widget_set_enabled ( widget *widget, gboolean enabled );
void widget_set_enabled(widget *widget, gboolean enabled);
/**
* @param widget Handle to widget
*
* Disable the widget.
*/
static inline
void widget_disable ( widget *widget )
{
widget_set_enabled ( widget, FALSE );
static inline void widget_disable(widget *widget) {
widget_set_enabled(widget, FALSE);
}
/**
* @param widget Handle to widget
*
* Enable the widget.
*/
static inline
void widget_enable ( widget *widget )
{
widget_set_enabled ( widget, TRUE );
static inline void widget_enable(widget *widget) {
widget_set_enabled(widget, TRUE);
}
/**
@ -193,14 +193,14 @@ void widget_enable ( widget *widget )
*
* Render the textbox.
*/
void widget_draw ( widget *widget, cairo_t *d );
void widget_draw(widget *widget, cairo_t *d);
/**
* @param wid Handle to the widget
*
* Free the widget and all allocated memory.
*/
void widget_free ( widget *wid );
void widget_free(widget *wid);
/**
* @param widget The widget toresize
@ -209,35 +209,35 @@ void widget_free ( widget *wid );
*
* Resizes the widget.
*/
void widget_resize ( widget *widget, short w, short h );
void widget_resize(widget *widget, short w, short h);
/**
* @param widget The widget handle
*
* @returns the height of the widget.
*/
int widget_get_height ( widget *widget );
int widget_get_height(widget *widget);
/**
* @param widget The widget handle
*
* @returns the width of the widget.
*/
int widget_get_width ( widget *widget );
int widget_get_width(widget *widget);
/**
* @param widget The widget handle
*
* @returns the y position of the widget relative to its parent.
*/
int widget_get_y_pos ( widget *widget );
int widget_get_y_pos(widget *widget);
/**
* @param widget The widget handle
*
* @returns the x position of the widget relative to its parent.
*/
int widget_get_x_pos ( widget *widget );
int widget_get_x_pos(widget *widget);
/**
* @param widget The widget handle
@ -246,7 +246,7 @@ int widget_get_x_pos ( widget *widget );
*
* 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 );
void widget_xy_to_relative(widget *widget, gint *x, gint *y);
/**
* @param widget The widget handle
@ -254,20 +254,20 @@ void widget_xy_to_relative ( widget *widget, gint *x, gint *y );
* Update the widget, and its parent recursively.
* This should be called when size of widget changes.
*/
void widget_update ( widget *widget );
void widget_update(widget *widget);
/**
* @param wid The widget handle
*
* Indicate that the widget needs to be redrawn.
* This is done by setting the redraw flag on the toplevel widget.
*/
void widget_queue_redraw ( widget *wid );
void widget_queue_redraw(widget *wid);
/**
* @param wid The widget handle
*
* Check the flag indicating the widget needs to be redrawn.
*/
gboolean widget_need_redraw ( widget *wid );
gboolean widget_need_redraw(widget *wid);
/**
* @param wid The widget handle
@ -279,7 +279,7 @@ gboolean widget_need_redraw ( widget *wid );
*
* @returns returns the widget that should handle the mouse event.
*/
widget *widget_find_mouse_target ( widget *wid, WidgetType type, gint x, gint y );
widget *widget_find_mouse_target(widget *wid, WidgetType type, gint x, gint y);
/**
* @param wid The widget handle
@ -292,7 +292,8 @@ widget *widget_find_mouse_target ( widget *wid, WidgetType type, gint x, gint y
*
* @returns Whether the action was handled or not
*/
WidgetTriggerActionResult widget_trigger_action ( widget *wid, guint action, gint x, gint y );
WidgetTriggerActionResult widget_trigger_action(widget *wid, guint action,
gint x, gint y);
/**
* @param wid The widget handle
@ -301,7 +302,8 @@ WidgetTriggerActionResult widget_trigger_action ( widget *wid, guint action, gin
*
* Override the widget trigger action handler on widget.
*/
void widget_set_trigger_action_handler ( widget *wid, widget_trigger_action_cb cb, void *cb_data );
void widget_set_trigger_action_handler(widget *wid, widget_trigger_action_cb cb,
void *cb_data);
/**
* @param wid The widget handle
@ -312,7 +314,7 @@ void widget_set_trigger_action_handler ( widget *wid, widget_trigger_action_cb c
*
* @returns TRUE when handled.
*/
gboolean widget_motion_notify ( widget *wid, gint x, gint y );
gboolean widget_motion_notify(widget *wid, gint x, gint y);
/**
* @param wid The widget handle
@ -321,7 +323,7 @@ gboolean widget_motion_notify ( widget *wid, gint x, gint y );
*
* @returns the desired height of the widget in pixels.
*/
int widget_get_desired_height ( widget *wid );
int widget_get_desired_height(widget *wid);
/**
* @param wid The widget handle
@ -330,7 +332,7 @@ int widget_get_desired_height ( widget *wid );
*
* @returns the desired width of the widget in pixels.
*/
int widget_get_desired_width ( widget *wid );
int widget_get_desired_width(widget *wid);
/**
* @param wid The widget handle
*
@ -338,7 +340,7 @@ int widget_get_desired_width ( widget *wid );
*
* @returns the absolute x-position of widget of the widget in pixels.
*/
int widget_get_absolute_xpos ( widget *wid );
int widget_get_absolute_xpos(widget *wid);
/**
* @param wid The widget handle
*
@ -346,6 +348,6 @@ int widget_get_absolute_xpos ( widget *wid );
*
* @returns the absolute y-position of widget of the widget in pixels.
*/
int widget_get_absolute_ypos ( widget *wid );
int widget_get_absolute_ypos(widget *wid);
/**@}*/
#endif // ROFI_WIDGET_H

View file

@ -31,37 +31,35 @@
#define SN_API_NOT_YET_FROZEN
#include <libsn/sn.h>
#include "libgwater-xcb.h"
#include <xcb/xcb.h>
#include <xcb/xcb_ewmh.h>
#include "libgwater-xcb.h"
#include "nkutils-bindings.h"
/**
* Structure to keep xcb stuff around.
*/
struct _xcb_stuff
{
GMainLoop *main_loop;
GWaterXcbSource *source;
xcb_connection_t *connection;
xcb_ewmh_connection_t ewmh;
xcb_screen_t *screen;
int screen_nbr;
SnDisplay *sndisplay;
SnLauncheeContext *sncontext;
struct _workarea *monitors;
struct
{
/** Flag indicating first event */
uint8_t first_event;
/** Keyboard device id */
int32_t device_id;
} xkb;
xcb_timestamp_t last_timestamp;
NkBindingsSeat *bindings_seat;
gboolean mouse_seen;
xcb_window_t focus_revert;
struct _xcb_stuff {
GMainLoop *main_loop;
GWaterXcbSource *source;
xcb_connection_t *connection;
xcb_ewmh_connection_t ewmh;
xcb_screen_t *screen;
int screen_nbr;
SnDisplay *sndisplay;
SnLauncheeContext *sncontext;
struct _workarea *monitors;
struct {
/** Flag indicating first event */
uint8_t first_event;
/** Keyboard device id */
int32_t device_id;
} xkb;
xcb_timestamp_t last_timestamp;
NkBindingsSeat *bindings_seat;
gboolean mouse_seen;
xcb_window_t focus_revert;
};
#endif

View file

@ -28,8 +28,8 @@
#ifndef ROFI_XCB_H
#define ROFI_XCB_H
#include <xcb/xcb.h>
#include <cairo.h>
#include <xcb/xcb.h>
/**
* xcb data structure type declaration.
@ -46,7 +46,7 @@ extern xcb_stuff *xcb;
*
* @returns the root window.
*/
xcb_window_t xcb_stuff_get_root_window ( void );
xcb_window_t xcb_stuff_get_root_window(void);
/**
* @param w The xcb_window_t to read property from.
@ -57,7 +57,7 @@ xcb_window_t xcb_stuff_get_root_window ( void );
*
* @returns a newly allocated string with the result or NULL
*/
char* window_get_text_prop ( xcb_window_t w, xcb_atom_t atom );
char *window_get_text_prop(xcb_window_t w, xcb_atom_t atom);
/**
* @param w The xcb_window_t to set property on
@ -67,28 +67,22 @@ char* window_get_text_prop ( xcb_window_t w, xcb_atom_t atom );
*
* Set property on window.
*/
void window_set_atom_prop ( xcb_window_t w, xcb_atom_t prop, xcb_atom_t *atoms, int count );
void window_set_atom_prop(xcb_window_t w, xcb_atom_t prop, xcb_atom_t *atoms,
int count);
/** For getting the atoms in an enum */
#define ATOM_ENUM( x ) x
#define ATOM_ENUM(x) x
/** Get the atoms as strings. */
#define ATOM_CHAR( x ) # x
#define ATOM_CHAR(x) #x
/** Atoms we want to pre-load */
#define EWMH_ATOMS( X ) \
X ( _NET_WM_WINDOW_OPACITY ), \
X ( I3_SOCKET_PATH ), \
X ( UTF8_STRING ), \
X ( STRING ), \
X ( CLIPBOARD ), \
X ( WM_WINDOW_ROLE ), \
X ( _XROOTPMAP_ID ), \
X ( _MOTIF_WM_HINTS ), \
X ( WM_TAKE_FOCUS ), \
X ( ESETROOT_PMAP_ID )
#define EWMH_ATOMS(X) \
X(_NET_WM_WINDOW_OPACITY), X(I3_SOCKET_PATH), X(UTF8_STRING), X(STRING), \
X(CLIPBOARD), X(WM_WINDOW_ROLE), X(_XROOTPMAP_ID), X(_MOTIF_WM_HINTS), \
X(WM_TAKE_FOCUS), X(ESETROOT_PMAP_ID)
/** enumeration of the atoms. */
enum { EWMH_ATOMS ( ATOM_ENUM ), NUM_NETATOMS };
enum { EWMH_ATOMS(ATOM_ENUM), NUM_NETATOMS };
/** atoms as string */
extern const char *netatom_names[];
/** atoms */
@ -99,12 +93,12 @@ extern xcb_atom_t netatoms[NUM_NETATOMS];
*
* Stores old input focus for reverting and set focus to rofi.
*/
void rofi_xcb_set_input_focus ( xcb_window_t w );
void rofi_xcb_set_input_focus(xcb_window_t w);
/**
* IF set, revert the focus back to the original applications.
*/
void rofi_xcb_revert_input_focus ( void );
void rofi_xcb_revert_input_focus(void);
/**
* Depth of visual
@ -124,7 +118,7 @@ extern xcb_colormap_t map;
*
* @returns a cairo surface with the background image of the desktop.
*/
cairo_surface_t * x11_helper_get_bg_surface ( void );
cairo_surface_t *x11_helper_get_bg_surface(void);
/**
* Gets a surface for the root window of the desktop.
*
@ -132,7 +126,7 @@ cairo_surface_t * x11_helper_get_bg_surface ( void );
*
* @returns a cairo surface for the root window of the desktop.
*/
cairo_surface_t *x11_helper_get_screenshot_surface ( void );
cairo_surface_t *x11_helper_get_screenshot_surface(void);
/**
* @param window The X11 window to modify
@ -140,20 +134,19 @@ cairo_surface_t *x11_helper_get_screenshot_surface ( void );
* Set the right hints to disable the window decoration.
* (Set MOTIF_WM_HINTS, decoration field)
*/
void x11_disable_decoration ( xcb_window_t window );
void x11_disable_decoration(xcb_window_t window);
/**
* List of cursor types.
*/
typedef enum
{
/** Default arrow cursor */
CURSOR_DEFAULT = 0,
/** Cursor denoting a clickable area */
CURSOR_POINTER,
/** Cursor denoting an input field / selectable text */
CURSOR_TEXT,
NUM_CURSORS
typedef enum {
/** Default arrow cursor */
CURSOR_DEFAULT = 0,
/** Cursor denoting a clickable area */
CURSOR_POINTER,
/** Cursor denoting an input field / selectable text */
CURSOR_TEXT,
NUM_CURSORS
} X11CursorType;
/**
@ -162,21 +155,20 @@ typedef enum
*
* Change mouse cursor
*/
void x11_set_cursor ( xcb_window_t window, X11CursorType type );
void x11_set_cursor(xcb_window_t window, X11CursorType type);
/**
* List of window managers that need different behaviour to functioning.
*/
typedef enum
{
/** Default EWHM compatible window manager */
WM_EWHM = 0,
/** I3 Window manager */
WM_DO_NOT_CHANGE_CURRENT_DESKTOP = 1,
/** PANGO WORKSPACE NAMES */
WM_PANGO_WORKSPACE_NAMES = 2,
/** Root window offset (for bspwm) */
WM_ROOT_WINDOW_OFFSET = 4,
typedef enum {
/** Default EWHM compatible window manager */
WM_EWHM = 0,
/** I3 Window manager */
WM_DO_NOT_CHANGE_CURRENT_DESKTOP = 1,
/** PANGO WORKSPACE NAMES */
WM_PANGO_WORKSPACE_NAMES = 2,
/** Root window offset (for bspwm) */
WM_ROOT_WINDOW_OFFSET = 4,
} WindowManagerQuirk;
/**
@ -191,9 +183,11 @@ extern WindowManagerQuirk current_window_manager;
*
* Creates a thumbnail of the window.
*
* @returns NULL if window was not found, or unmapped, otherwise returns a cairo_surface.
* @returns NULL if window was not found, or unmapped, otherwise returns a
* cairo_surface.
*/
cairo_surface_t *x11_helper_get_screenshot_surface_window ( xcb_window_t window, int size );
cairo_surface_t *x11_helper_get_screenshot_surface_window(xcb_window_t window,
int size);
/**
* @param surface
@ -202,6 +196,7 @@ cairo_surface_t *x11_helper_get_screenshot_surface_window ( xcb_window_t window,
*
* Blur the content of the surface with radius and deviation.
*/
void cairo_image_surface_blur ( cairo_surface_t* surface, double radius, double deviation );
void cairo_image_surface_blur(cairo_surface_t *surface, double radius,
double deviation);
#endif

View file

@ -27,20 +27,22 @@
#ifndef ROFI_XRMOPTIONS_H
#define ROFI_XRMOPTIONS_H
#include "xcb.h"
#include "theme.h"
#include "xcb.h"
// Big thanks to Sean Pringle for this code.
/**
* @defgroup CONFXResources XResources Configuration
* @ingroup CONFIGURATION
*
* Configuration described in Xresource format. This can be loaded from the X server or file.
* Configuration described in Xresource format. This can be loaded from the X
* server or file.
*
* @defgroup CONFXServer XServer Configuration
* @ingroup CONFXResources
*
* Loads the configuration directly from the X server using the XResources system.
* Loads the configuration directly from the X server using the XResources
* system.
*
* @defgroup CONFCommandline Commandline Configuration
* @ingroup CONFIGURATION
@ -50,7 +52,8 @@
* @defgroup CONFFile File Configuration
* @ingroup CONFXResources
*
* Loads the configuration from a config file that uses the XResource file format.
* Loads the configuration from a config file that uses the XResource file
* format.
*
* @defgroup CONFIGURATION Configuration
*
@ -66,32 +69,31 @@
/**
* Type of the config options.
*/
typedef enum
{
/** Config option is string */
xrm_String = 0,
/** Config option is an unsigned number */
xrm_Number = 1,
/** Config option is a signed number */
xrm_SNumber = 2,
/** Config option is a boolean (true/false) value*/
xrm_Boolean = 3,
/** Config option is a character */
xrm_Char = 4
typedef enum {
/** Config option is string */
xrm_String = 0,
/** Config option is an unsigned number */
xrm_Number = 1,
/** Config option is a signed number */
xrm_SNumber = 2,
/** Config option is a boolean (true/false) value*/
xrm_Boolean = 3,
/** Config option is a character */
xrm_Char = 4
} XrmOptionType;
/**
* Parse commandline options.
* @ingroup CONFCommandline
*/
void config_parse_cmd_options ( void );
void config_parse_cmd_options(void);
/**
* Free any allocated memory.
*
* @ingroup CONFXResources
*/
void config_xresource_free ( void );
void config_xresource_free(void);
/**
* @param type The type of the value
@ -101,12 +103,14 @@ void config_xresource_free ( void );
*
* Add option (at runtime) to the dynamic option parser.
*/
void config_parser_add_option ( XrmOptionType type, const char *key, void **value, const char *comment );
void config_parser_add_option(XrmOptionType type, const char *key, void **value,
const char *comment);
/**
* Print the current configuration to stdout. Uses bold/italic when printing to terminal.
* Print the current configuration to stdout. Uses bold/italic when printing to
* terminal.
*/
void print_options ( void );
void print_options(void);
/**
* @param option The name of the option
@ -117,7 +121,8 @@ void print_options ( void );
*
* Function that does the markup for printing an configuration option to stdout.
*/
void print_help_msg ( const char *option, const char *type, const char*text, const char *def, int isatty );
void print_help_msg(const char *option, const char *type, const char *text,
const char *def, int isatty);
/**
* @param length the length of the returned array
@ -126,7 +131,7 @@ void print_help_msg ( const char *option, const char *type, const char*text, con
*
* @returns an array of string with length elements
*/
char ** config_parser_return_display_help ( unsigned int *length );
char **config_parser_return_display_help(unsigned int *length);
/**
* @brief Set config option.
@ -138,7 +143,7 @@ char ** config_parser_return_display_help ( unsigned int *length );
*
* @returns true when failed to set property.
*/
gboolean config_parse_set_property ( const Property *p, char **error );
gboolean config_parse_set_property(const Property *p, char **error);
/**
* @param out The destination.
@ -146,6 +151,6 @@ gboolean config_parse_set_property ( const Property *p, char **error );
*
* @brief Dump configuration in rasi format.
*/
void config_parse_dump_config_rasi_format ( FILE *out, gboolean changes );
void config_parse_dump_config_rasi_format(FILE *out, gboolean changes);
/** @}*/
#endif

View file

@ -1,154 +1,152 @@
#include <stdint.h>
#include "css-colors.h"
const CSSColor CSSColors[] = {
{ .name = "AliceBlue", .r = 0xF0, .g = 0xF8, .b = 0xFF },
{ .name = "AntiqueWhite", .r = 0xFA, .g = 0xEB, .b = 0xD7 },
{ .name = "Aqua", .r = 0x00, .g = 0xFF, .b = 0xFF },
{ .name = "Aquamarine", .r = 0x7F, .g = 0xFF, .b = 0xD4 },
{ .name = "Azure", .r = 0xF0, .g = 0xFF, .b = 0xFF },
{ .name = "Beige", .r = 0xF5, .g = 0xF5, .b = 0xDC },
{ .name = "Bisque", .r = 0xFF, .g = 0xE4, .b = 0xC4 },
{ .name = "Black", .r = 0x00, .g = 0x00, .b = 0x00 },
{ .name = "BlanchedAlmond", .r = 0xFF, .g = 0xEB, .b = 0xCD },
{ .name = "Blue", .r = 0x00, .g = 0x00, .b = 0xFF },
{ .name = "BlueViolet", .r = 0x8A, .g = 0x2B, .b = 0xE2 },
{ .name = "Brown", .r = 0xA5, .g = 0x2A, .b = 0x2A },
{ .name = "BurlyWood", .r = 0xDE, .g = 0xB8, .b = 0x87 },
{ .name = "CadetBlue", .r = 0x5F, .g = 0x9E, .b = 0xA0 },
{ .name = "Chartreuse", .r = 0x7F, .g = 0xFF, .b = 0x00 },
{ .name = "Chocolate", .r = 0xD2, .g = 0x69, .b = 0x1E },
{ .name = "Coral", .r = 0xFF, .g = 0x7F, .b = 0x50 },
{ .name = "CornflowerBlue", .r = 0x64, .g = 0x95, .b = 0xED },
{ .name = "Cornsilk", .r = 0xFF, .g = 0xF8, .b = 0xDC },
{ .name = "Crimson", .r = 0xDC, .g = 0x14, .b = 0x3C },
{ .name = "Cyan", .r = 0x00, .g = 0xFF, .b = 0xFF },
{ .name = "DarkBlue", .r = 0x00, .g = 0x00, .b = 0x8B },
{ .name = "DarkCyan", .r = 0x00, .g = 0x8B, .b = 0x8B },
{ .name = "DarkGoldenRod", .r = 0xB8, .g = 0x86, .b = 0x0B },
{ .name = "DarkGray", .r = 0xA9, .g = 0xA9, .b = 0xA9 },
{ .name = "DarkGrey", .r = 0xA9, .g = 0xA9, .b = 0xA9 },
{ .name = "DarkGreen", .r = 0x00, .g = 0x64, .b = 0x00 },
{ .name = "DarkKhaki", .r = 0xBD, .g = 0xB7, .b = 0x6B },
{ .name = "DarkMagenta", .r = 0x8B, .g = 0x00, .b = 0x8B },
{ .name = "DarkOliveGreen", .r = 0x55, .g = 0x6B, .b = 0x2F },
{ .name = "DarkOrange", .r = 0xFF, .g = 0x8C, .b = 0x00 },
{ .name = "DarkOrchid", .r = 0x99, .g = 0x32, .b = 0xCC },
{ .name = "DarkRed", .r = 0x8B, .g = 0x00, .b = 0x00 },
{ .name = "DarkSalmon", .r = 0xE9, .g = 0x96, .b = 0x7A },
{ .name = "DarkSeaGreen", .r = 0x8F, .g = 0xBC, .b = 0x8F },
{ .name = "DarkSlateBlue", .r = 0x48, .g = 0x3D, .b = 0x8B },
{ .name = "DarkSlateGray", .r = 0x2F, .g = 0x4F, .b = 0x4F },
{ .name = "DarkSlateGrey", .r = 0x2F, .g = 0x4F, .b = 0x4F },
{ .name = "DarkTurquoise", .r = 0x00, .g = 0xCE, .b = 0xD1 },
{ .name = "DarkViolet", .r = 0x94, .g = 0x00, .b = 0xD3 },
{ .name = "DeepPink", .r = 0xFF, .g = 0x14, .b = 0x93 },
{ .name = "DeepSkyBlue", .r = 0x00, .g = 0xBF, .b = 0xFF },
{ .name = "DimGray", .r = 0x69, .g = 0x69, .b = 0x69 },
{ .name = "DimGrey", .r = 0x69, .g = 0x69, .b = 0x69 },
{ .name = "DodgerBlue", .r = 0x1E, .g = 0x90, .b = 0xFF },
{ .name = "FireBrick", .r = 0xB2, .g = 0x22, .b = 0x22 },
{ .name = "FloralWhite", .r = 0xFF, .g = 0xFA, .b = 0xF0 },
{ .name = "ForestGreen", .r = 0x22, .g = 0x8B, .b = 0x22 },
{ .name = "Fuchsia", .r = 0xFF, .g = 0x00, .b = 0xFF },
{ .name = "Gainsboro", .r = 0xDC, .g = 0xDC, .b = 0xDC },
{ .name = "GhostWhite", .r = 0xF8, .g = 0xF8, .b = 0xFF },
{ .name = "Gold", .r = 0xFF, .g = 0xD7, .b = 0x00 },
{ .name = "GoldenRod", .r = 0xDA, .g = 0xA5, .b = 0x20 },
{ .name = "Gray", .r = 0x80, .g = 0x80, .b = 0x80 },
{ .name = "Grey", .r = 0x80, .g = 0x80, .b = 0x80 },
{ .name = "Green", .r = 0x00, .g = 0x80, .b = 0x00 },
{ .name = "GreenYellow", .r = 0xAD, .g = 0xFF, .b = 0x2F },
{ .name = "HoneyDew", .r = 0xF0, .g = 0xFF, .b = 0xF0 },
{ .name = "HotPink", .r = 0xFF, .g = 0x69, .b = 0xB4 },
{ .name = "IndianRed", .r = 0xCD, .g = 0x5C, .b = 0x5C },
{ .name = "Indigo", .r = 0x4B, .g = 0x00, .b = 0x82 },
{ .name = "Ivory", .r = 0xFF, .g = 0xFF, .b = 0xF0 },
{ .name = "Khaki", .r = 0xF0, .g = 0xE6, .b = 0x8C },
{ .name = "Lavender", .r = 0xE6, .g = 0xE6, .b = 0xFA },
{ .name = "LavenderBlush", .r = 0xFF, .g = 0xF0, .b = 0xF5 },
{ .name = "LawnGreen", .r = 0x7C, .g = 0xFC, .b = 0x00 },
{ .name = "LemonChiffon", .r = 0xFF, .g = 0xFA, .b = 0xCD },
{ .name = "LightBlue", .r = 0xAD, .g = 0xD8, .b = 0xE6 },
{ .name = "LightCoral", .r = 0xF0, .g = 0x80, .b = 0x80 },
{ .name = "LightCyan", .r = 0xE0, .g = 0xFF, .b = 0xFF },
{ .name = "LightGoldenRodYellow", .r = 0xFA, .g = 0xFA, .b = 0xD2 },
{ .name = "LightGray", .r = 0xD3, .g = 0xD3, .b = 0xD3 },
{ .name = "LightGrey", .r = 0xD3, .g = 0xD3, .b = 0xD3 },
{ .name = "LightGreen", .r = 0x90, .g = 0xEE, .b = 0x90 },
{ .name = "LightPink", .r = 0xFF, .g = 0xB6, .b = 0xC1 },
{ .name = "LightSalmon", .r = 0xFF, .g = 0xA0, .b = 0x7A },
{ .name = "LightSeaGreen", .r = 0x20, .g = 0xB2, .b = 0xAA },
{ .name = "LightSkyBlue", .r = 0x87, .g = 0xCE, .b = 0xFA },
{ .name = "LightSlateGray", .r = 0x77, .g = 0x88, .b = 0x99 },
{ .name = "LightSlateGrey", .r = 0x77, .g = 0x88, .b = 0x99 },
{ .name = "LightSteelBlue", .r = 0xB0, .g = 0xC4, .b = 0xDE },
{ .name = "LightYellow", .r = 0xFF, .g = 0xFF, .b = 0xE0 },
{ .name = "Lime", .r = 0x00, .g = 0xFF, .b = 0x00 },
{ .name = "LimeGreen", .r = 0x32, .g = 0xCD, .b = 0x32 },
{ .name = "Linen", .r = 0xFA, .g = 0xF0, .b = 0xE6 },
{ .name = "Magenta", .r = 0xFF, .g = 0x00, .b = 0xFF },
{ .name = "Maroon", .r = 0x80, .g = 0x00, .b = 0x00 },
{ .name = "MediumAquaMarine", .r = 0x66, .g = 0xCD, .b = 0xAA },
{ .name = "MediumBlue", .r = 0x00, .g = 0x00, .b = 0xCD },
{ .name = "MediumOrchid", .r = 0xBA, .g = 0x55, .b = 0xD3 },
{ .name = "MediumPurple", .r = 0x93, .g = 0x70, .b = 0xDB },
{ .name = "MediumSeaGreen", .r = 0x3C, .g = 0xB3, .b = 0x71 },
{ .name = "MediumSlateBlue", .r = 0x7B, .g = 0x68, .b = 0xEE },
{ .name = "MediumSpringGreen", .r = 0x00, .g = 0xFA, .b = 0x9A },
{ .name = "MediumTurquoise", .r = 0x48, .g = 0xD1, .b = 0xCC },
{ .name = "MediumVioletRed", .r = 0xC7, .g = 0x15, .b = 0x85 },
{ .name = "MidnightBlue", .r = 0x19, .g = 0x19, .b = 0x70 },
{ .name = "MintCream", .r = 0xF5, .g = 0xFF, .b = 0xFA },
{ .name = "MistyRose", .r = 0xFF, .g = 0xE4, .b = 0xE1 },
{ .name = "Moccasin", .r = 0xFF, .g = 0xE4, .b = 0xB5 },
{ .name = "NavajoWhite", .r = 0xFF, .g = 0xDE, .b = 0xAD },
{ .name = "Navy", .r = 0x00, .g = 0x00, .b = 0x80 },
{ .name = "OldLace", .r = 0xFD, .g = 0xF5, .b = 0xE6 },
{ .name = "Olive", .r = 0x80, .g = 0x80, .b = 0x00 },
{ .name = "OliveDrab", .r = 0x6B, .g = 0x8E, .b = 0x23 },
{ .name = "Orange", .r = 0xFF, .g = 0xA5, .b = 0x00 },
{ .name = "OrangeRed", .r = 0xFF, .g = 0x45, .b = 0x00 },
{ .name = "Orchid", .r = 0xDA, .g = 0x70, .b = 0xD6 },
{ .name = "PaleGoldenRod", .r = 0xEE, .g = 0xE8, .b = 0xAA },
{ .name = "PaleGreen", .r = 0x98, .g = 0xFB, .b = 0x98 },
{ .name = "PaleTurquoise", .r = 0xAF, .g = 0xEE, .b = 0xEE },
{ .name = "PaleVioletRed", .r = 0xDB, .g = 0x70, .b = 0x93 },
{ .name = "PapayaWhip", .r = 0xFF, .g = 0xEF, .b = 0xD5 },
{ .name = "PeachPuff", .r = 0xFF, .g = 0xDA, .b = 0xB9 },
{ .name = "Peru", .r = 0xCD, .g = 0x85, .b = 0x3F },
{ .name = "Pink", .r = 0xFF, .g = 0xC0, .b = 0xCB },
{ .name = "Plum", .r = 0xDD, .g = 0xA0, .b = 0xDD },
{ .name = "PowderBlue", .r = 0xB0, .g = 0xE0, .b = 0xE6 },
{ .name = "Purple", .r = 0x80, .g = 0x00, .b = 0x80 },
{ .name = "RebeccaPurple", .r = 0x66, .g = 0x33, .b = 0x99 },
{ .name = "Red", .r = 0xFF, .g = 0x00, .b = 0x00 },
{ .name = "RosyBrown", .r = 0xBC, .g = 0x8F, .b = 0x8F },
{ .name = "RoyalBlue", .r = 0x41, .g = 0x69, .b = 0xE1 },
{ .name = "SaddleBrown", .r = 0x8B, .g = 0x45, .b = 0x13 },
{ .name = "Salmon", .r = 0xFA, .g = 0x80, .b = 0x72 },
{ .name = "SandyBrown", .r = 0xF4, .g = 0xA4, .b = 0x60 },
{ .name = "SeaGreen", .r = 0x2E, .g = 0x8B, .b = 0x57 },
{ .name = "SeaShell", .r = 0xFF, .g = 0xF5, .b = 0xEE },
{ .name = "Sienna", .r = 0xA0, .g = 0x52, .b = 0x2D },
{ .name = "Silver", .r = 0xC0, .g = 0xC0, .b = 0xC0 },
{ .name = "SkyBlue", .r = 0x87, .g = 0xCE, .b = 0xEB },
{ .name = "SlateBlue", .r = 0x6A, .g = 0x5A, .b = 0xCD },
{ .name = "SlateGray", .r = 0x70, .g = 0x80, .b = 0x90 },
{ .name = "SlateGrey", .r = 0x70, .g = 0x80, .b = 0x90 },
{ .name = "Snow", .r = 0xFF, .g = 0xFA, .b = 0xFA },
{ .name = "SpringGreen", .r = 0x00, .g = 0xFF, .b = 0x7F },
{ .name = "SteelBlue", .r = 0x46, .g = 0x82, .b = 0xB4 },
{ .name = "Tan", .r = 0xD2, .g = 0xB4, .b = 0x8C },
{ .name = "Teal", .r = 0x00, .g = 0x80, .b = 0x80 },
{ .name = "Thistle", .r = 0xD8, .g = 0xBF, .b = 0xD8 },
{ .name = "Tomato", .r = 0xFF, .g = 0x63, .b = 0x47 },
{ .name = "Turquoise", .r = 0x40, .g = 0xE0, .b = 0xD0 },
{ .name = "Violet", .r = 0xEE, .g = 0x82, .b = 0xEE },
{ .name = "Wheat", .r = 0xF5, .g = 0xDE, .b = 0xB3 },
{ .name = "White", .r = 0xFF, .g = 0xFF, .b = 0xFF },
{ .name = "WhiteSmoke", .r = 0xF5, .g = 0xF5, .b = 0xF5 },
{ .name = "Yellow", .r = 0xFF, .g = 0xFF, .b = 0x00 },
{ .name = "YellowGreen", .r = 0x9A, .g = 0xCD, .b = 0x32 }
};
const CSSColor CSSColors[] = {
{.name = "AliceBlue", .r = 0xF0, .g = 0xF8, .b = 0xFF},
{.name = "AntiqueWhite", .r = 0xFA, .g = 0xEB, .b = 0xD7},
{.name = "Aqua", .r = 0x00, .g = 0xFF, .b = 0xFF},
{.name = "Aquamarine", .r = 0x7F, .g = 0xFF, .b = 0xD4},
{.name = "Azure", .r = 0xF0, .g = 0xFF, .b = 0xFF},
{.name = "Beige", .r = 0xF5, .g = 0xF5, .b = 0xDC},
{.name = "Bisque", .r = 0xFF, .g = 0xE4, .b = 0xC4},
{.name = "Black", .r = 0x00, .g = 0x00, .b = 0x00},
{.name = "BlanchedAlmond", .r = 0xFF, .g = 0xEB, .b = 0xCD},
{.name = "Blue", .r = 0x00, .g = 0x00, .b = 0xFF},
{.name = "BlueViolet", .r = 0x8A, .g = 0x2B, .b = 0xE2},
{.name = "Brown", .r = 0xA5, .g = 0x2A, .b = 0x2A},
{.name = "BurlyWood", .r = 0xDE, .g = 0xB8, .b = 0x87},
{.name = "CadetBlue", .r = 0x5F, .g = 0x9E, .b = 0xA0},
{.name = "Chartreuse", .r = 0x7F, .g = 0xFF, .b = 0x00},
{.name = "Chocolate", .r = 0xD2, .g = 0x69, .b = 0x1E},
{.name = "Coral", .r = 0xFF, .g = 0x7F, .b = 0x50},
{.name = "CornflowerBlue", .r = 0x64, .g = 0x95, .b = 0xED},
{.name = "Cornsilk", .r = 0xFF, .g = 0xF8, .b = 0xDC},
{.name = "Crimson", .r = 0xDC, .g = 0x14, .b = 0x3C},
{.name = "Cyan", .r = 0x00, .g = 0xFF, .b = 0xFF},
{.name = "DarkBlue", .r = 0x00, .g = 0x00, .b = 0x8B},
{.name = "DarkCyan", .r = 0x00, .g = 0x8B, .b = 0x8B},
{.name = "DarkGoldenRod", .r = 0xB8, .g = 0x86, .b = 0x0B},
{.name = "DarkGray", .r = 0xA9, .g = 0xA9, .b = 0xA9},
{.name = "DarkGrey", .r = 0xA9, .g = 0xA9, .b = 0xA9},
{.name = "DarkGreen", .r = 0x00, .g = 0x64, .b = 0x00},
{.name = "DarkKhaki", .r = 0xBD, .g = 0xB7, .b = 0x6B},
{.name = "DarkMagenta", .r = 0x8B, .g = 0x00, .b = 0x8B},
{.name = "DarkOliveGreen", .r = 0x55, .g = 0x6B, .b = 0x2F},
{.name = "DarkOrange", .r = 0xFF, .g = 0x8C, .b = 0x00},
{.name = "DarkOrchid", .r = 0x99, .g = 0x32, .b = 0xCC},
{.name = "DarkRed", .r = 0x8B, .g = 0x00, .b = 0x00},
{.name = "DarkSalmon", .r = 0xE9, .g = 0x96, .b = 0x7A},
{.name = "DarkSeaGreen", .r = 0x8F, .g = 0xBC, .b = 0x8F},
{.name = "DarkSlateBlue", .r = 0x48, .g = 0x3D, .b = 0x8B},
{.name = "DarkSlateGray", .r = 0x2F, .g = 0x4F, .b = 0x4F},
{.name = "DarkSlateGrey", .r = 0x2F, .g = 0x4F, .b = 0x4F},
{.name = "DarkTurquoise", .r = 0x00, .g = 0xCE, .b = 0xD1},
{.name = "DarkViolet", .r = 0x94, .g = 0x00, .b = 0xD3},
{.name = "DeepPink", .r = 0xFF, .g = 0x14, .b = 0x93},
{.name = "DeepSkyBlue", .r = 0x00, .g = 0xBF, .b = 0xFF},
{.name = "DimGray", .r = 0x69, .g = 0x69, .b = 0x69},
{.name = "DimGrey", .r = 0x69, .g = 0x69, .b = 0x69},
{.name = "DodgerBlue", .r = 0x1E, .g = 0x90, .b = 0xFF},
{.name = "FireBrick", .r = 0xB2, .g = 0x22, .b = 0x22},
{.name = "FloralWhite", .r = 0xFF, .g = 0xFA, .b = 0xF0},
{.name = "ForestGreen", .r = 0x22, .g = 0x8B, .b = 0x22},
{.name = "Fuchsia", .r = 0xFF, .g = 0x00, .b = 0xFF},
{.name = "Gainsboro", .r = 0xDC, .g = 0xDC, .b = 0xDC},
{.name = "GhostWhite", .r = 0xF8, .g = 0xF8, .b = 0xFF},
{.name = "Gold", .r = 0xFF, .g = 0xD7, .b = 0x00},
{.name = "GoldenRod", .r = 0xDA, .g = 0xA5, .b = 0x20},
{.name = "Gray", .r = 0x80, .g = 0x80, .b = 0x80},
{.name = "Grey", .r = 0x80, .g = 0x80, .b = 0x80},
{.name = "Green", .r = 0x00, .g = 0x80, .b = 0x00},
{.name = "GreenYellow", .r = 0xAD, .g = 0xFF, .b = 0x2F},
{.name = "HoneyDew", .r = 0xF0, .g = 0xFF, .b = 0xF0},
{.name = "HotPink", .r = 0xFF, .g = 0x69, .b = 0xB4},
{.name = "IndianRed", .r = 0xCD, .g = 0x5C, .b = 0x5C},
{.name = "Indigo", .r = 0x4B, .g = 0x00, .b = 0x82},
{.name = "Ivory", .r = 0xFF, .g = 0xFF, .b = 0xF0},
{.name = "Khaki", .r = 0xF0, .g = 0xE6, .b = 0x8C},
{.name = "Lavender", .r = 0xE6, .g = 0xE6, .b = 0xFA},
{.name = "LavenderBlush", .r = 0xFF, .g = 0xF0, .b = 0xF5},
{.name = "LawnGreen", .r = 0x7C, .g = 0xFC, .b = 0x00},
{.name = "LemonChiffon", .r = 0xFF, .g = 0xFA, .b = 0xCD},
{.name = "LightBlue", .r = 0xAD, .g = 0xD8, .b = 0xE6},
{.name = "LightCoral", .r = 0xF0, .g = 0x80, .b = 0x80},
{.name = "LightCyan", .r = 0xE0, .g = 0xFF, .b = 0xFF},
{.name = "LightGoldenRodYellow", .r = 0xFA, .g = 0xFA, .b = 0xD2},
{.name = "LightGray", .r = 0xD3, .g = 0xD3, .b = 0xD3},
{.name = "LightGrey", .r = 0xD3, .g = 0xD3, .b = 0xD3},
{.name = "LightGreen", .r = 0x90, .g = 0xEE, .b = 0x90},
{.name = "LightPink", .r = 0xFF, .g = 0xB6, .b = 0xC1},
{.name = "LightSalmon", .r = 0xFF, .g = 0xA0, .b = 0x7A},
{.name = "LightSeaGreen", .r = 0x20, .g = 0xB2, .b = 0xAA},
{.name = "LightSkyBlue", .r = 0x87, .g = 0xCE, .b = 0xFA},
{.name = "LightSlateGray", .r = 0x77, .g = 0x88, .b = 0x99},
{.name = "LightSlateGrey", .r = 0x77, .g = 0x88, .b = 0x99},
{.name = "LightSteelBlue", .r = 0xB0, .g = 0xC4, .b = 0xDE},
{.name = "LightYellow", .r = 0xFF, .g = 0xFF, .b = 0xE0},
{.name = "Lime", .r = 0x00, .g = 0xFF, .b = 0x00},
{.name = "LimeGreen", .r = 0x32, .g = 0xCD, .b = 0x32},
{.name = "Linen", .r = 0xFA, .g = 0xF0, .b = 0xE6},
{.name = "Magenta", .r = 0xFF, .g = 0x00, .b = 0xFF},
{.name = "Maroon", .r = 0x80, .g = 0x00, .b = 0x00},
{.name = "MediumAquaMarine", .r = 0x66, .g = 0xCD, .b = 0xAA},
{.name = "MediumBlue", .r = 0x00, .g = 0x00, .b = 0xCD},
{.name = "MediumOrchid", .r = 0xBA, .g = 0x55, .b = 0xD3},
{.name = "MediumPurple", .r = 0x93, .g = 0x70, .b = 0xDB},
{.name = "MediumSeaGreen", .r = 0x3C, .g = 0xB3, .b = 0x71},
{.name = "MediumSlateBlue", .r = 0x7B, .g = 0x68, .b = 0xEE},
{.name = "MediumSpringGreen", .r = 0x00, .g = 0xFA, .b = 0x9A},
{.name = "MediumTurquoise", .r = 0x48, .g = 0xD1, .b = 0xCC},
{.name = "MediumVioletRed", .r = 0xC7, .g = 0x15, .b = 0x85},
{.name = "MidnightBlue", .r = 0x19, .g = 0x19, .b = 0x70},
{.name = "MintCream", .r = 0xF5, .g = 0xFF, .b = 0xFA},
{.name = "MistyRose", .r = 0xFF, .g = 0xE4, .b = 0xE1},
{.name = "Moccasin", .r = 0xFF, .g = 0xE4, .b = 0xB5},
{.name = "NavajoWhite", .r = 0xFF, .g = 0xDE, .b = 0xAD},
{.name = "Navy", .r = 0x00, .g = 0x00, .b = 0x80},
{.name = "OldLace", .r = 0xFD, .g = 0xF5, .b = 0xE6},
{.name = "Olive", .r = 0x80, .g = 0x80, .b = 0x00},
{.name = "OliveDrab", .r = 0x6B, .g = 0x8E, .b = 0x23},
{.name = "Orange", .r = 0xFF, .g = 0xA5, .b = 0x00},
{.name = "OrangeRed", .r = 0xFF, .g = 0x45, .b = 0x00},
{.name = "Orchid", .r = 0xDA, .g = 0x70, .b = 0xD6},
{.name = "PaleGoldenRod", .r = 0xEE, .g = 0xE8, .b = 0xAA},
{.name = "PaleGreen", .r = 0x98, .g = 0xFB, .b = 0x98},
{.name = "PaleTurquoise", .r = 0xAF, .g = 0xEE, .b = 0xEE},
{.name = "PaleVioletRed", .r = 0xDB, .g = 0x70, .b = 0x93},
{.name = "PapayaWhip", .r = 0xFF, .g = 0xEF, .b = 0xD5},
{.name = "PeachPuff", .r = 0xFF, .g = 0xDA, .b = 0xB9},
{.name = "Peru", .r = 0xCD, .g = 0x85, .b = 0x3F},
{.name = "Pink", .r = 0xFF, .g = 0xC0, .b = 0xCB},
{.name = "Plum", .r = 0xDD, .g = 0xA0, .b = 0xDD},
{.name = "PowderBlue", .r = 0xB0, .g = 0xE0, .b = 0xE6},
{.name = "Purple", .r = 0x80, .g = 0x00, .b = 0x80},
{.name = "RebeccaPurple", .r = 0x66, .g = 0x33, .b = 0x99},
{.name = "Red", .r = 0xFF, .g = 0x00, .b = 0x00},
{.name = "RosyBrown", .r = 0xBC, .g = 0x8F, .b = 0x8F},
{.name = "RoyalBlue", .r = 0x41, .g = 0x69, .b = 0xE1},
{.name = "SaddleBrown", .r = 0x8B, .g = 0x45, .b = 0x13},
{.name = "Salmon", .r = 0xFA, .g = 0x80, .b = 0x72},
{.name = "SandyBrown", .r = 0xF4, .g = 0xA4, .b = 0x60},
{.name = "SeaGreen", .r = 0x2E, .g = 0x8B, .b = 0x57},
{.name = "SeaShell", .r = 0xFF, .g = 0xF5, .b = 0xEE},
{.name = "Sienna", .r = 0xA0, .g = 0x52, .b = 0x2D},
{.name = "Silver", .r = 0xC0, .g = 0xC0, .b = 0xC0},
{.name = "SkyBlue", .r = 0x87, .g = 0xCE, .b = 0xEB},
{.name = "SlateBlue", .r = 0x6A, .g = 0x5A, .b = 0xCD},
{.name = "SlateGray", .r = 0x70, .g = 0x80, .b = 0x90},
{.name = "SlateGrey", .r = 0x70, .g = 0x80, .b = 0x90},
{.name = "Snow", .r = 0xFF, .g = 0xFA, .b = 0xFA},
{.name = "SpringGreen", .r = 0x00, .g = 0xFF, .b = 0x7F},
{.name = "SteelBlue", .r = 0x46, .g = 0x82, .b = 0xB4},
{.name = "Tan", .r = 0xD2, .g = 0xB4, .b = 0x8C},
{.name = "Teal", .r = 0x00, .g = 0x80, .b = 0x80},
{.name = "Thistle", .r = 0xD8, .g = 0xBF, .b = 0xD8},
{.name = "Tomato", .r = 0xFF, .g = 0x63, .b = 0x47},
{.name = "Turquoise", .r = 0x40, .g = 0xE0, .b = 0xD0},
{.name = "Violet", .r = 0xEE, .g = 0x82, .b = 0xEE},
{.name = "Wheat", .r = 0xF5, .g = 0xDE, .b = 0xB3},
{.name = "White", .r = 0xFF, .g = 0xFF, .b = 0xFF},
{.name = "WhiteSmoke", .r = 0xF5, .g = 0xF5, .b = 0xF5},
{.name = "Yellow", .r = 0xFF, .g = 0xFF, .b = 0x00},
{.name = "YellowGreen", .r = 0x9A, .g = 0xCD, .b = 0x32}};
const unsigned int num_CSSColors = sizeof ( CSSColors ) / sizeof ( *CSSColors );
const unsigned int num_CSSColors = sizeof(CSSColors) / sizeof(*CSSColors);

View file

@ -26,294 +26,296 @@
*/
/** The log domain of this dialog. */
#define G_LOG_DOMAIN "Dialogs.Combi"
#define G_LOG_DOMAIN "Dialogs.Combi"
#include <config.h>
#include <stdlib.h>
#include <stdio.h>
#include <rofi.h>
#include "settings.h"
#include "helper.h"
#include "settings.h"
#include <rofi.h>
#include <stdio.h>
#include <stdlib.h>
#include "mode-private.h"
#include <dialogs/dialogs.h>
#include <pango/pango.h>
#include "mode-private.h"
#include <theme.h>
/**
* Combi Mode
*/
typedef struct
{
Mode *mode;
gboolean disable;
typedef struct {
Mode *mode;
gboolean disable;
} CombiMode;
typedef struct
{
// List of (combined) entries.
unsigned int cmd_list_length;
// List to validate where each switcher starts.
unsigned int *starts;
unsigned int *lengths;
// List of switchers to combine.
unsigned int num_switchers;
CombiMode *switchers;
typedef struct {
// List of (combined) entries.
unsigned int cmd_list_length;
// List to validate where each switcher starts.
unsigned int *starts;
unsigned int *lengths;
// List of switchers to combine.
unsigned int num_switchers;
CombiMode *switchers;
} CombiModePrivateData;
static void combi_mode_parse_switchers ( Mode *sw )
{
CombiModePrivateData *pd = mode_get_private_data ( sw );
char *savept = NULL;
// Make a copy, as strtok will modify it.
char *switcher_str = g_strdup ( config.combi_modi );
const char * const sep = ",#";
// Split token on ','. This modifies switcher_str.
for ( char *token = strtok_r ( switcher_str, sep, &savept ); token != NULL;
token = strtok_r ( NULL, sep, &savept ) ) {
// Resize and add entry.
pd->switchers = (CombiMode *) g_realloc ( pd->switchers,
sizeof ( CombiMode ) * ( pd->num_switchers + 1 ) );
static void combi_mode_parse_switchers(Mode *sw) {
CombiModePrivateData *pd = mode_get_private_data(sw);
char *savept = NULL;
// Make a copy, as strtok will modify it.
char *switcher_str = g_strdup(config.combi_modi);
const char *const sep = ",#";
// Split token on ','. This modifies switcher_str.
for (char *token = strtok_r(switcher_str, sep, &savept); token != NULL;
token = strtok_r(NULL, sep, &savept)) {
// Resize and add entry.
pd->switchers = (CombiMode *)g_realloc(
pd->switchers, sizeof(CombiMode) * (pd->num_switchers + 1));
Mode *mode = rofi_collect_modi_search ( token );
if ( mode != NULL ) {
pd->switchers[pd->num_switchers].disable = FALSE;
pd->switchers[pd->num_switchers++].mode = mode;
continue;
}
// If not build in, use custom switchers.
mode = script_switcher_parse_setup ( token );
if ( mode != NULL ) {
pd->switchers[pd->num_switchers].disable = FALSE;
pd->switchers[pd->num_switchers++].mode = mode;
continue;
}
// Report error, don't continue.
g_warning ( "Invalid script switcher: %s", token );
token = NULL;
Mode *mode = rofi_collect_modi_search(token);
if (mode != NULL) {
pd->switchers[pd->num_switchers].disable = FALSE;
pd->switchers[pd->num_switchers++].mode = mode;
continue;
}
// Free string that was modified by strtok_r
g_free ( switcher_str );
// If not build in, use custom switchers.
mode = script_switcher_parse_setup(token);
if (mode != NULL) {
pd->switchers[pd->num_switchers].disable = FALSE;
pd->switchers[pd->num_switchers++].mode = mode;
continue;
}
// Report error, don't continue.
g_warning("Invalid script switcher: %s", token);
token = NULL;
}
// Free string that was modified by strtok_r
g_free(switcher_str);
}
static unsigned int combi_mode_get_num_entries ( const Mode *sw )
{
const CombiModePrivateData *pd = (const CombiModePrivateData *) mode_get_private_data ( sw );
unsigned int length = 0;
for ( unsigned int i = 0; i < pd->num_switchers; i++ ) {
unsigned int entries = mode_get_num_entries ( pd->switchers[i].mode );
pd->starts[i] = length;
pd->lengths[i] = entries;
length += entries;
}
return length;
static unsigned int combi_mode_get_num_entries(const Mode *sw) {
const CombiModePrivateData *pd =
(const CombiModePrivateData *)mode_get_private_data(sw);
unsigned int length = 0;
for (unsigned int i = 0; i < pd->num_switchers; i++) {
unsigned int entries = mode_get_num_entries(pd->switchers[i].mode);
pd->starts[i] = length;
pd->lengths[i] = entries;
length += entries;
}
return length;
}
static int combi_mode_init ( Mode *sw )
{
if ( mode_get_private_data ( sw ) == NULL ) {
CombiModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
mode_set_private_data ( sw, (void *) pd );
combi_mode_parse_switchers ( sw );
pd->starts = g_malloc0 ( sizeof ( int ) * pd->num_switchers );
pd->lengths = g_malloc0 ( sizeof ( int ) * pd->num_switchers );
for ( unsigned int i = 0; i < pd->num_switchers; i++ ) {
if ( !mode_init ( pd->switchers[i].mode ) ) {
return FALSE;
}
}
if ( pd->cmd_list_length == 0 ) {
pd->cmd_list_length = combi_mode_get_num_entries ( sw );
}
static int combi_mode_init(Mode *sw) {
if (mode_get_private_data(sw) == NULL) {
CombiModePrivateData *pd = g_malloc0(sizeof(*pd));
mode_set_private_data(sw, (void *)pd);
combi_mode_parse_switchers(sw);
pd->starts = g_malloc0(sizeof(int) * pd->num_switchers);
pd->lengths = g_malloc0(sizeof(int) * pd->num_switchers);
for (unsigned int i = 0; i < pd->num_switchers; i++) {
if (!mode_init(pd->switchers[i].mode)) {
return FALSE;
}
}
return TRUE;
}
static void combi_mode_destroy ( Mode *sw )
{
CombiModePrivateData *pd = (CombiModePrivateData *) mode_get_private_data ( sw );
if ( pd != NULL ) {
g_free ( pd->starts );
g_free ( pd->lengths );
// Cleanup switchers.
for ( unsigned int i = 0; i < pd->num_switchers; i++ ) {
mode_destroy ( pd->switchers[i].mode );
}
g_free ( pd->switchers );
g_free ( pd );
mode_set_private_data ( sw, NULL );
if (pd->cmd_list_length == 0) {
pd->cmd_list_length = combi_mode_get_num_entries(sw);
}
}
return TRUE;
}
static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line )
{
CombiModePrivateData *pd = mode_get_private_data ( sw );
static void combi_mode_destroy(Mode *sw) {
CombiModePrivateData *pd = (CombiModePrivateData *)mode_get_private_data(sw);
if (pd != NULL) {
g_free(pd->starts);
g_free(pd->lengths);
// Cleanup switchers.
for (unsigned int i = 0; i < pd->num_switchers; i++) {
mode_destroy(pd->switchers[i].mode);
}
g_free(pd->switchers);
g_free(pd);
mode_set_private_data(sw, NULL);
}
}
static ModeMode combi_mode_result(Mode *sw, int mretv, char **input,
unsigned int selected_line) {
CombiModePrivateData *pd = mode_get_private_data(sw);
if ( input[0][0] == '!' ) {
int switcher = -1;
// Implement strchrnul behaviour.
char *eob = g_utf8_strchr ( input[0], -1, ' ' );
if ( eob == NULL ) {
eob = &( input[0][strlen ( input[0] )] );
}
ssize_t bang_len = g_utf8_pointer_to_offset ( input[0], eob ) - 1;
if ( bang_len > 0 ) {
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
const char *mode_name = mode_get_name ( pd->switchers[i].mode );
size_t mode_name_len = g_utf8_strlen ( mode_name, -1 );
if ( (size_t) bang_len <= mode_name_len && utf8_strncmp ( &input[0][1], mode_name, bang_len ) == 0 ) {
switcher = i;
break;
}
}
}
if ( switcher >= 0 ) {
if ( eob[0] == ' ' ) {
char *n = eob + 1;
return mode_result ( pd->switchers[switcher].mode, mretv, &n,
selected_line - pd->starts[switcher] );
}
return MODE_EXIT;
}
} else if ( ( mretv& MENU_COMPLETE) ) {
return RELOAD_DIALOG;
if (input[0][0] == '!') {
int switcher = -1;
// Implement strchrnul behaviour.
char *eob = g_utf8_strchr(input[0], -1, ' ');
if (eob == NULL) {
eob = &(input[0][strlen(input[0])]);
}
ssize_t bang_len = g_utf8_pointer_to_offset(input[0], eob) - 1;
if (bang_len > 0) {
for (unsigned i = 0; i < pd->num_switchers; i++) {
const char *mode_name = mode_get_name(pd->switchers[i].mode);
size_t mode_name_len = g_utf8_strlen(mode_name, -1);
if ((size_t)bang_len <= mode_name_len &&
utf8_strncmp(&input[0][1], mode_name, bang_len) == 0) {
switcher = i;
break;
}
}
}
if (switcher >= 0) {
if (eob[0] == ' ') {
char *n = eob + 1;
return mode_result(pd->switchers[switcher].mode, mretv, &n,
selected_line - pd->starts[switcher]);
}
return MODE_EXIT;
}
} else if ((mretv & MENU_COMPLETE)) {
return RELOAD_DIALOG;
}
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
if ( selected_line >= pd->starts[i] &&
selected_line < ( pd->starts[i] + pd->lengths[i] ) ) {
return mode_result ( pd->switchers[i].mode, mretv, input, selected_line - pd->starts[i] );
}
for (unsigned i = 0; i < pd->num_switchers; i++) {
if (selected_line >= pd->starts[i] &&
selected_line < (pd->starts[i] + pd->lengths[i])) {
return mode_result(pd->switchers[i].mode, mretv, input,
selected_line - pd->starts[i]);
}
if ( ( mretv & MENU_CUSTOM_INPUT ) ) {
return mode_result ( pd->switchers[0].mode, mretv, input, selected_line );
}
return MODE_EXIT;
}
if ((mretv & MENU_CUSTOM_INPUT)) {
return mode_result(pd->switchers[0].mode, mretv, input, selected_line);
}
return MODE_EXIT;
}
static int combi_mode_match ( const Mode *sw, rofi_int_matcher **tokens, unsigned int index )
{
CombiModePrivateData *pd = mode_get_private_data ( sw );
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
if ( pd->switchers[i].disable ) {
continue;
}
if ( index >= pd->starts[i] && index < ( pd->starts[i] + pd->lengths[i] ) ) {
return mode_token_match ( pd->switchers[i].mode, tokens, index - pd->starts[i] );
}
static int combi_mode_match(const Mode *sw, rofi_int_matcher **tokens,
unsigned int index) {
CombiModePrivateData *pd = mode_get_private_data(sw);
for (unsigned i = 0; i < pd->num_switchers; i++) {
if (pd->switchers[i].disable) {
continue;
}
return 0;
if (index >= pd->starts[i] && index < (pd->starts[i] + pd->lengths[i])) {
return mode_token_match(pd->switchers[i].mode, tokens,
index - pd->starts[i]);
}
}
return 0;
}
static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *state, GList **attr_list, int get_entry )
{
CombiModePrivateData *pd = mode_get_private_data ( sw );
if ( !get_entry ) {
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
if ( selected_line >= pd->starts[i] && selected_line < ( pd->starts[i] + pd->lengths[i] ) ) {
mode_get_display_value ( pd->switchers[i].mode, selected_line - pd->starts[i], state, attr_list, FALSE );
return NULL;
}
}
static char *combi_mgrv(const Mode *sw, unsigned int selected_line, int *state,
GList **attr_list, int get_entry) {
CombiModePrivateData *pd = mode_get_private_data(sw);
if (!get_entry) {
for (unsigned i = 0; i < pd->num_switchers; i++) {
if (selected_line >= pd->starts[i] &&
selected_line < (pd->starts[i] + pd->lengths[i])) {
mode_get_display_value(pd->switchers[i].mode,
selected_line - pd->starts[i], state, attr_list,
FALSE);
return NULL;
}
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
if ( selected_line >= pd->starts[i] && selected_line < ( pd->starts[i] + pd->lengths[i] ) ) {
char * retv;
char * str = retv = mode_get_display_value ( pd->switchers[i].mode, selected_line - pd->starts[i], state, attr_list, TRUE );
const char *dname = mode_get_display_name ( pd->switchers[i].mode );
if ( !config.combi_hide_mode_prefix ) {
retv = g_strdup_printf ( "%s %s", dname, str );
g_free ( str );
if ( attr_list != NULL ) {
ThemeWidget *wid = rofi_config_find_widget ( sw->name, NULL, TRUE );
Property *p = rofi_theme_find_property ( wid, P_COLOR, pd->switchers[i].mode->name, TRUE );
if ( p != NULL ) {
PangoAttribute *pa = pango_attr_foreground_new (
p->value.color.red * 65535,
p->value.color.green * 65535,
p->value.color.blue * 65535 );
pa->start_index = PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING;
pa->end_index = strlen ( dname );
*attr_list = g_list_append ( *attr_list, pa );
}
}
}
return retv;
}
}
return NULL;
}
static char * combi_get_completion ( const Mode *sw, unsigned int index )
{
CombiModePrivateData *pd = mode_get_private_data ( sw );
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
if ( index >= pd->starts[i] && index < ( pd->starts[i] + pd->lengths[i] ) ) {
char *comp = mode_get_completion ( pd->switchers[i].mode, index - pd->starts[i] );
char *mcomp = g_strdup_printf ( "!%s %s", mode_get_name ( pd->switchers[i].mode ), comp );
g_free ( comp );
return mcomp;
}
}
// Should never get here.
g_assert_not_reached ();
return NULL;
}
static cairo_surface_t * combi_get_icon ( const Mode *sw, unsigned int index, int height )
{
CombiModePrivateData *pd = mode_get_private_data ( sw );
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
if ( index >= pd->starts[i] && index < ( pd->starts[i] + pd->lengths[i] ) ) {
cairo_surface_t *icon = mode_get_icon ( pd->switchers[i].mode, index - pd->starts[i], height );
return icon;
}
}
}
return NULL;
}
for (unsigned i = 0; i < pd->num_switchers; i++) {
if (selected_line >= pd->starts[i] &&
selected_line < (pd->starts[i] + pd->lengths[i])) {
char *retv;
char *str = retv = mode_get_display_value(pd->switchers[i].mode,
selected_line - pd->starts[i],
state, attr_list, TRUE);
const char *dname = mode_get_display_name(pd->switchers[i].mode);
if (!config.combi_hide_mode_prefix) {
retv = g_strdup_printf("%s %s", dname, str);
g_free(str);
if (attr_list != NULL) {
ThemeWidget *wid = rofi_config_find_widget(sw->name, NULL, TRUE);
Property *p = rofi_theme_find_property(
wid, P_COLOR, pd->switchers[i].mode->name, TRUE);
if (p != NULL) {
PangoAttribute *pa = pango_attr_foreground_new(
p->value.color.red * 65535, p->value.color.green * 65535,
p->value.color.blue * 65535);
pa->start_index = PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING;
pa->end_index = strlen(dname);
*attr_list = g_list_append(*attr_list, pa);
}
}
}
return retv;
}
}
return NULL;
}
static char *combi_get_completion(const Mode *sw, unsigned int index) {
CombiModePrivateData *pd = mode_get_private_data(sw);
for (unsigned i = 0; i < pd->num_switchers; i++) {
if (index >= pd->starts[i] && index < (pd->starts[i] + pd->lengths[i])) {
char *comp =
mode_get_completion(pd->switchers[i].mode, index - pd->starts[i]);
char *mcomp =
g_strdup_printf("!%s %s", mode_get_name(pd->switchers[i].mode), comp);
g_free(comp);
return mcomp;
}
}
// Should never get here.
g_assert_not_reached();
return NULL;
}
static char * combi_preprocess_input ( Mode *sw, const char *input )
{
CombiModePrivateData *pd = mode_get_private_data ( sw );
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
pd->switchers[i].disable = FALSE;
static cairo_surface_t *combi_get_icon(const Mode *sw, unsigned int index,
int height) {
CombiModePrivateData *pd = mode_get_private_data(sw);
for (unsigned i = 0; i < pd->num_switchers; i++) {
if (index >= pd->starts[i] && index < (pd->starts[i] + pd->lengths[i])) {
cairo_surface_t *icon =
mode_get_icon(pd->switchers[i].mode, index - pd->starts[i], height);
return icon;
}
if ( input != NULL && input[0] == '!' ) {
// Implement strchrnul behaviour.
const char *eob = g_utf8_strchr ( input, -1, ' ' );
if ( eob == NULL ) {
// Set it to end.
eob = &( input[strlen ( input )] );
}
ssize_t bang_len = g_utf8_pointer_to_offset ( input, eob ) - 1;
if ( bang_len > 0 ) {
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
const char *mode_name = mode_get_name ( pd->switchers[i].mode );
size_t mode_name_len = g_utf8_strlen ( mode_name, -1 );
if ( !( (size_t) bang_len <= mode_name_len && utf8_strncmp ( &input[1], mode_name, bang_len ) == 0 ) ) {
// No match.
pd->switchers[i].disable = TRUE;
}
}
if ( eob[0] == '\0' || eob[1] == '\0' ) {
return NULL;
}
return g_strdup ( eob + 1 );
}
}
return g_strdup ( input );
}
return NULL;
}
Mode combi_mode =
{
.name = "combi",
.cfg_name_key = "display-combi",
._init = combi_mode_init,
._get_num_entries = combi_mode_get_num_entries,
._result = combi_mode_result,
._destroy = combi_mode_destroy,
._token_match = combi_mode_match,
._get_completion = combi_get_completion,
._get_display_value = combi_mgrv,
._get_icon = combi_get_icon,
._preprocess_input = combi_preprocess_input,
.private_data = NULL,
.free = NULL
};
static char *combi_preprocess_input(Mode *sw, const char *input) {
CombiModePrivateData *pd = mode_get_private_data(sw);
for (unsigned i = 0; i < pd->num_switchers; i++) {
pd->switchers[i].disable = FALSE;
}
if (input != NULL && input[0] == '!') {
// Implement strchrnul behaviour.
const char *eob = g_utf8_strchr(input, -1, ' ');
if (eob == NULL) {
// Set it to end.
eob = &(input[strlen(input)]);
}
ssize_t bang_len = g_utf8_pointer_to_offset(input, eob) - 1;
if (bang_len > 0) {
for (unsigned i = 0; i < pd->num_switchers; i++) {
const char *mode_name = mode_get_name(pd->switchers[i].mode);
size_t mode_name_len = g_utf8_strlen(mode_name, -1);
if (!((size_t)bang_len <= mode_name_len &&
utf8_strncmp(&input[1], mode_name, bang_len) == 0)) {
// No match.
pd->switchers[i].disable = TRUE;
}
}
if (eob[0] == '\0' || eob[1] == '\0') {
return NULL;
}
return g_strdup(eob + 1);
}
}
return g_strdup(input);
}
Mode combi_mode = {.name = "combi",
.cfg_name_key = "display-combi",
._init = combi_mode_init,
._get_num_entries = combi_mode_get_num_entries,
._result = combi_mode_result,
._destroy = combi_mode_destroy,
._token_match = combi_mode_match,
._get_completion = combi_get_completion,
._get_display_value = combi_mgrv,
._get_icon = combi_get_icon,
._preprocess_input = combi_preprocess_input,
.private_data = NULL,
.free = NULL};

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -26,103 +26,96 @@
*/
#include <config.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <dirent.h>
#include <errno.h>
#include <limits.h>
#include <signal.h>
#include <sys/types.h>
#include <dirent.h>
#include <strings.h>
#include <string.h>
#include <errno.h>
#include <strings.h>
#include <sys/types.h>
#include <unistd.h>
#include "dialogs/help-keys.h"
#include "helper.h"
#include "rofi.h"
#include "settings.h"
#include "helper.h"
#include "xrmoptions.h"
#include "dialogs/help-keys.h"
#include "widgets/textbox.h"
#include "xrmoptions.h"
typedef struct
{
char **messages;
unsigned int messages_length;
typedef struct {
char **messages;
unsigned int messages_length;
} KeysHelpModePrivateData;
static void get_apps ( KeysHelpModePrivateData *pd )
{
pd->messages = config_parser_return_display_help ( &( pd->messages_length ) );
static void get_apps(KeysHelpModePrivateData *pd) {
pd->messages = config_parser_return_display_help(&(pd->messages_length));
}
static int help_keys_mode_init ( Mode *sw )
{
if ( mode_get_private_data ( sw ) == NULL ) {
KeysHelpModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
mode_set_private_data ( sw, (void *) pd );
get_apps ( pd );
}
return TRUE;
static int help_keys_mode_init(Mode *sw) {
if (mode_get_private_data(sw) == NULL) {
KeysHelpModePrivateData *pd = g_malloc0(sizeof(*pd));
mode_set_private_data(sw, (void *)pd);
get_apps(pd);
}
return TRUE;
}
static ModeMode help_keys_mode_result ( G_GNUC_UNUSED Mode *sw,
int mretv,
G_GNUC_UNUSED char **input,
G_GNUC_UNUSED unsigned int selected_line )
{
if ( mretv & MENU_CUSTOM_COMMAND ) {
int retv = ( mretv & MENU_LOWER_MASK );
return retv;
}
return MODE_EXIT;
static ModeMode
help_keys_mode_result(G_GNUC_UNUSED Mode *sw, int mretv,
G_GNUC_UNUSED char **input,
G_GNUC_UNUSED unsigned int selected_line) {
if (mretv & MENU_CUSTOM_COMMAND) {
int retv = (mretv & MENU_LOWER_MASK);
return retv;
}
return MODE_EXIT;
}
static void help_keys_mode_destroy ( Mode *sw )
{
KeysHelpModePrivateData *rmpd = (KeysHelpModePrivateData *) mode_get_private_data ( sw );
if ( rmpd != NULL ) {
g_strfreev ( rmpd->messages );
g_free ( rmpd );
mode_set_private_data ( sw, NULL );
}
static void help_keys_mode_destroy(Mode *sw) {
KeysHelpModePrivateData *rmpd =
(KeysHelpModePrivateData *)mode_get_private_data(sw);
if (rmpd != NULL) {
g_strfreev(rmpd->messages);
g_free(rmpd);
mode_set_private_data(sw, NULL);
}
}
static char *_get_display_value ( const Mode *sw, unsigned int selected_line, int *state, G_GNUC_UNUSED GList **list, int get_entry )
{
KeysHelpModePrivateData *pd = (KeysHelpModePrivateData *) mode_get_private_data ( sw );
*state |= MARKUP;
if ( !get_entry ) {
return NULL;
}
return g_strdup ( pd->messages[selected_line] );
static char *_get_display_value(const Mode *sw, unsigned int selected_line,
int *state, G_GNUC_UNUSED GList **list,
int get_entry) {
KeysHelpModePrivateData *pd =
(KeysHelpModePrivateData *)mode_get_private_data(sw);
*state |= MARKUP;
if (!get_entry) {
return NULL;
}
return g_strdup(pd->messages[selected_line]);
}
static int help_keys_token_match ( const Mode *data,
rofi_int_matcher **tokens,
unsigned int index
)
{
KeysHelpModePrivateData *rmpd = (KeysHelpModePrivateData *) mode_get_private_data ( data );
return helper_token_match ( tokens, rmpd->messages[index] );
static int help_keys_token_match(const Mode *data, rofi_int_matcher **tokens,
unsigned int index) {
KeysHelpModePrivateData *rmpd =
(KeysHelpModePrivateData *)mode_get_private_data(data);
return helper_token_match(tokens, rmpd->messages[index]);
}
static unsigned int help_keys_mode_get_num_entries ( const Mode *sw )
{
const KeysHelpModePrivateData *pd = (const KeysHelpModePrivateData *) mode_get_private_data ( sw );
return pd->messages_length;
static unsigned int help_keys_mode_get_num_entries(const Mode *sw) {
const KeysHelpModePrivateData *pd =
(const KeysHelpModePrivateData *)mode_get_private_data(sw);
return pd->messages_length;
}
#include "mode-private.h"
Mode help_keys_mode =
{
.name = "keys",
.cfg_name_key = "display-keys",
._init = help_keys_mode_init,
._get_num_entries = help_keys_mode_get_num_entries,
._result = help_keys_mode_result,
._destroy = help_keys_mode_destroy,
._token_match = help_keys_token_match,
._get_completion = NULL,
._get_display_value = _get_display_value,
.private_data = NULL,
.free = NULL
};
Mode help_keys_mode = {.name = "keys",
.cfg_name_key = "display-keys",
._init = help_keys_mode_init,
._get_num_entries = help_keys_mode_get_num_entries,
._result = help_keys_mode_result,
._destroy = help_keys_mode_destroy,
._token_match = help_keys_token_match,
._get_completion = NULL,
._get_display_value = _get_display_value,
.private_data = NULL,
.free = NULL};

File diff suppressed because it is too large Load diff

View file

@ -26,20 +26,19 @@
*/
/** The log domain of this dialog. */
#define G_LOG_DOMAIN "Dialogs.Script"
#define G_LOG_DOMAIN "Dialogs.Script"
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <strings.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
#include <errno.h>
#include "rofi.h"
#include "dialogs/script.h"
#include "helper.h"
#include "rofi.h"
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include "widgets/textbox.h"
@ -49,424 +48,415 @@
#include "dialogs/dmenuscriptshared.h"
typedef struct
{
/** ID of the current script. */
unsigned int id;
/** List of visible items. */
DmenuScriptEntry *cmd_list;
/** length list of visible items. */
unsigned int cmd_list_length;
typedef struct {
/** ID of the current script. */
unsigned int id;
/** List of visible items. */
DmenuScriptEntry *cmd_list;
/** length list of visible items. */
unsigned int cmd_list_length;
/** Urgent list */
struct rofi_range_pair * urgent_list;
unsigned int num_urgent_list;
/** Active list */
struct rofi_range_pair * active_list;
unsigned int num_active_list;
/** Configuration settings. */
char *message;
char *prompt;
gboolean do_markup;
char delim;
/** no custom */
gboolean no_custom;
/** Urgent list */
struct rofi_range_pair *urgent_list;
unsigned int num_urgent_list;
/** Active list */
struct rofi_range_pair *active_list;
unsigned int num_active_list;
/** Configuration settings. */
char *message;
char *prompt;
gboolean do_markup;
char delim;
/** no custom */
gboolean no_custom;
gboolean use_hot_keys;
gboolean use_hot_keys;
} ScriptModePrivateData;
/**
* Shared function between DMENU and Script mode.
*/
void dmenuscript_parse_entry_extras ( G_GNUC_UNUSED Mode *sw, DmenuScriptEntry *entry, char *buffer, G_GNUC_UNUSED size_t length )
{
gchar **extras = g_strsplit ( buffer, "\x1f", -1 );
gchar **extra;
for ( extra = extras; *extra != NULL && *( extra + 1 ) != NULL; extra += 2 ) {
gchar *key = *extra;
gchar *value = *( extra + 1 );
if ( strcasecmp ( key, "icon" ) == 0 ) {
entry->icon_name = value;
}
else if ( strcasecmp ( key, "meta" ) == 0 ) {
entry->meta = value;
}
else if ( strcasecmp ( key, "info" ) == 0 ) {
entry->info = value;
}
else if ( strcasecmp ( key, "nonselectable" ) == 0 ) {
entry->nonselectable = strcasecmp ( value, "true" ) == 0;
g_free ( value );
}
else {
g_free ( value );
}
g_free ( key );
void dmenuscript_parse_entry_extras(G_GNUC_UNUSED Mode *sw,
DmenuScriptEntry *entry, char *buffer,
G_GNUC_UNUSED size_t length) {
gchar **extras = g_strsplit(buffer, "\x1f", -1);
gchar **extra;
for (extra = extras; *extra != NULL && *(extra + 1) != NULL; extra += 2) {
gchar *key = *extra;
gchar *value = *(extra + 1);
if (strcasecmp(key, "icon") == 0) {
entry->icon_name = value;
} else if (strcasecmp(key, "meta") == 0) {
entry->meta = value;
} else if (strcasecmp(key, "info") == 0) {
entry->info = value;
} else if (strcasecmp(key, "nonselectable") == 0) {
entry->nonselectable = strcasecmp(value, "true") == 0;
g_free(value);
} else {
g_free(value);
}
g_free ( extras );
g_free(key);
}
g_free(extras);
}
/**
* End of shared functions.
*/
static void parse_header_entry ( Mode *sw, char *line, ssize_t length )
{
ScriptModePrivateData *pd = (ScriptModePrivateData *) sw->private_data;
ssize_t length_key = 0;//strlen ( line );
while ( length_key < length && line[length_key] != '\x1f' ) {
length_key++;
}
static void parse_header_entry(Mode *sw, char *line, ssize_t length) {
ScriptModePrivateData *pd = (ScriptModePrivateData *)sw->private_data;
ssize_t length_key = 0; // strlen ( line );
while (length_key < length && line[length_key] != '\x1f') {
length_key++;
}
if ( ( length_key + 1 ) < length ) {
line[length_key] = '\0';
char *value = line + length_key + 1;
if ( strcasecmp ( line, "message" ) == 0 ) {
g_free ( pd->message );
pd->message = strlen ( value ) ? g_strdup ( value ) : NULL;
}
else if ( strcasecmp ( line, "prompt" ) == 0 ) {
g_free ( pd->prompt );
pd->prompt = g_strdup ( value );
sw->display_name = pd->prompt;
}
else if ( strcasecmp ( line, "markup-rows" ) == 0 ) {
pd->do_markup = ( strcasecmp ( value, "true" ) == 0 );
}
else if ( strcasecmp ( line, "urgent" ) == 0 ) {
parse_ranges ( value, &( pd->urgent_list ), &( pd->num_urgent_list ) );
}
else if ( strcasecmp ( line, "active" ) == 0 ) {
parse_ranges ( value, &( pd->active_list ), &( pd->num_active_list ) );
}
else if ( strcasecmp ( line, "delim" ) == 0 ) {
pd->delim = helper_parse_char ( value );
}
else if ( strcasecmp ( line, "no-custom" ) == 0 ) {
pd->no_custom = ( strcasecmp ( value, "true" ) == 0 );
}
else if ( strcasecmp ( line, "use-hot-keys" ) == 0 ) {
pd->use_hot_keys = ( strcasecmp ( value, "true" ) == 0 );
}
if ((length_key + 1) < length) {
line[length_key] = '\0';
char *value = line + length_key + 1;
if (strcasecmp(line, "message") == 0) {
g_free(pd->message);
pd->message = strlen(value) ? g_strdup(value) : NULL;
} else if (strcasecmp(line, "prompt") == 0) {
g_free(pd->prompt);
pd->prompt = g_strdup(value);
sw->display_name = pd->prompt;
} else if (strcasecmp(line, "markup-rows") == 0) {
pd->do_markup = (strcasecmp(value, "true") == 0);
} else if (strcasecmp(line, "urgent") == 0) {
parse_ranges(value, &(pd->urgent_list), &(pd->num_urgent_list));
} else if (strcasecmp(line, "active") == 0) {
parse_ranges(value, &(pd->active_list), &(pd->num_active_list));
} else if (strcasecmp(line, "delim") == 0) {
pd->delim = helper_parse_char(value);
} else if (strcasecmp(line, "no-custom") == 0) {
pd->no_custom = (strcasecmp(value, "true") == 0);
} else if (strcasecmp(line, "use-hot-keys") == 0) {
pd->use_hot_keys = (strcasecmp(value, "true") == 0);
}
}
}
static DmenuScriptEntry *execute_executor ( Mode *sw, char *arg, unsigned int *length, int value, DmenuScriptEntry *entry )
{
ScriptModePrivateData *pd = (ScriptModePrivateData *) sw->private_data;
int fd = -1;
GError *error = NULL;
DmenuScriptEntry *retv = NULL;
char **argv = NULL;
int argc = 0;
*length = 0;
static DmenuScriptEntry *execute_executor(Mode *sw, char *arg,
unsigned int *length, int value,
DmenuScriptEntry *entry) {
ScriptModePrivateData *pd = (ScriptModePrivateData *)sw->private_data;
int fd = -1;
GError *error = NULL;
DmenuScriptEntry *retv = NULL;
char **argv = NULL;
int argc = 0;
*length = 0;
// Environment
char ** env = g_get_environ ();
// Environment
char **env = g_get_environ();
char *str_value = g_strdup_printf ( "%d", value );
env = g_environ_setenv ( env, "ROFI_RETV", str_value, TRUE );
g_free ( str_value );
char *str_value = g_strdup_printf("%d", value);
env = g_environ_setenv(env, "ROFI_RETV", str_value, TRUE);
g_free(str_value);
str_value = g_strdup_printf ( "%d", (int) getpid () );
env = g_environ_setenv ( env, "ROFI_OUTSIDE", str_value, TRUE );
g_free ( str_value );
str_value = g_strdup_printf("%d", (int)getpid());
env = g_environ_setenv(env, "ROFI_OUTSIDE", str_value, TRUE);
g_free(str_value);
if ( entry && entry->info ) {
env = g_environ_setenv ( env, "ROFI_INFO", entry->info, TRUE );
}
if (entry && entry->info) {
env = g_environ_setenv(env, "ROFI_INFO", entry->info, TRUE);
}
if ( g_shell_parse_argv ( sw->ed, &argc, &argv, &error ) ) {
argv = g_realloc ( argv, ( argc + 2 ) * sizeof ( char* ) );
argv[argc] = g_strdup ( arg );
argv[argc + 1] = NULL;
g_spawn_async_with_pipes ( NULL, argv, env, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL, &fd, NULL, &error );
}
g_strfreev ( env );
if ( error != NULL ) {
char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", (char *) sw->ed, error->message );
rofi_view_error_dialog ( msg, FALSE );
g_free ( msg );
// print error.
g_error_free ( error );
fd = -1;
}
if ( fd >= 0 ) {
FILE *inp = fdopen ( fd, "r" );
if ( inp ) {
char *buffer = NULL;
size_t buffer_length = 0;
ssize_t read_length = 0;
size_t actual_size = 0;
while ( ( read_length = getdelim ( &buffer, &buffer_length, pd->delim, inp ) ) > 0 ) {
// Filter out line-end.
if ( buffer[read_length - 1] == pd->delim ) {
buffer[read_length - 1] = '\0';
}
if ( buffer[0] == '\0' ) {
parse_header_entry ( sw, &buffer[1], read_length - 1 );
}
else {
if ( actual_size < ( ( *length ) + 2 ) ) {
actual_size += 256;
retv = g_realloc ( retv, ( actual_size ) * sizeof ( DmenuScriptEntry ) );
}
size_t buf_length = strlen ( buffer ) + 1;
retv[( *length )].entry = g_memdup ( buffer, buf_length );
retv[( *length )].icon_name = NULL;
retv[( *length )].meta = NULL;
retv[( *length )].info = NULL;
retv[( *length )].icon_fetch_uid = 0;
retv[( *length )].nonselectable = FALSE;
if ( buf_length > 0 && ( read_length > (ssize_t) buf_length ) ) {
dmenuscript_parse_entry_extras ( sw, &( retv[( *length )] ), buffer + buf_length, read_length - buf_length );
}
retv[( *length ) + 1].entry = NULL;
( *length )++;
}
}
if ( buffer ) {
free ( buffer );
}
if ( fclose ( inp ) != 0 ) {
g_warning ( "Failed to close stdout off executor script: '%s'",
g_strerror ( errno ) );
}
if (g_shell_parse_argv(sw->ed, &argc, &argv, &error)) {
argv = g_realloc(argv, (argc + 2) * sizeof(char *));
argv[argc] = g_strdup(arg);
argv[argc + 1] = NULL;
g_spawn_async_with_pipes(NULL, argv, env, G_SPAWN_SEARCH_PATH, NULL, NULL,
NULL, NULL, &fd, NULL, &error);
}
g_strfreev(env);
if (error != NULL) {
char *msg = g_strdup_printf("Failed to execute: '%s'\nError: '%s'",
(char *)sw->ed, error->message);
rofi_view_error_dialog(msg, FALSE);
g_free(msg);
// print error.
g_error_free(error);
fd = -1;
}
if (fd >= 0) {
FILE *inp = fdopen(fd, "r");
if (inp) {
char *buffer = NULL;
size_t buffer_length = 0;
ssize_t read_length = 0;
size_t actual_size = 0;
while ((read_length = getdelim(&buffer, &buffer_length, pd->delim, inp)) >
0) {
// Filter out line-end.
if (buffer[read_length - 1] == pd->delim) {
buffer[read_length - 1] = '\0';
}
if (buffer[0] == '\0') {
parse_header_entry(sw, &buffer[1], read_length - 1);
} else {
if (actual_size < ((*length) + 2)) {
actual_size += 256;
retv = g_realloc(retv, (actual_size) * sizeof(DmenuScriptEntry));
}
size_t buf_length = strlen(buffer) + 1;
retv[(*length)].entry = g_memdup(buffer, buf_length);
retv[(*length)].icon_name = NULL;
retv[(*length)].meta = NULL;
retv[(*length)].info = NULL;
retv[(*length)].icon_fetch_uid = 0;
retv[(*length)].nonselectable = FALSE;
if (buf_length > 0 && (read_length > (ssize_t)buf_length)) {
dmenuscript_parse_entry_extras(sw, &(retv[(*length)]),
buffer + buf_length,
read_length - buf_length);
}
retv[(*length) + 1].entry = NULL;
(*length)++;
}
}
if (buffer) {
free(buffer);
}
if (fclose(inp) != 0) {
g_warning("Failed to close stdout off executor script: '%s'",
g_strerror(errno));
}
}
g_strfreev ( argv );
return retv;
}
g_strfreev(argv);
return retv;
}
static void script_switcher_free ( Mode *sw )
{
if ( sw == NULL ) {
return;
}
g_free ( sw->name );
g_free ( sw->ed );
g_free ( sw );
static void script_switcher_free(Mode *sw) {
if (sw == NULL) {
return;
}
g_free(sw->name);
g_free(sw->ed);
g_free(sw);
}
static int script_mode_init ( Mode *sw )
{
if ( sw->private_data == NULL ) {
ScriptModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
pd->delim = '\n';
sw->private_data = (void *) pd;
pd->cmd_list = execute_executor ( sw, NULL, &( pd->cmd_list_length ), 0, NULL );
}
return TRUE;
static int script_mode_init(Mode *sw) {
if (sw->private_data == NULL) {
ScriptModePrivateData *pd = g_malloc0(sizeof(*pd));
pd->delim = '\n';
sw->private_data = (void *)pd;
pd->cmd_list = execute_executor(sw, NULL, &(pd->cmd_list_length), 0, NULL);
}
return TRUE;
}
static unsigned int script_mode_get_num_entries ( const Mode *sw )
{
const ScriptModePrivateData *rmpd = (const ScriptModePrivateData *) sw->private_data;
return rmpd->cmd_list_length;
static unsigned int script_mode_get_num_entries(const Mode *sw) {
const ScriptModePrivateData *rmpd =
(const ScriptModePrivateData *)sw->private_data;
return rmpd->cmd_list_length;
}
static void script_mode_reset_highlight ( Mode *sw )
{
ScriptModePrivateData *rmpd = (ScriptModePrivateData *) sw->private_data;
static void script_mode_reset_highlight(Mode *sw) {
ScriptModePrivateData *rmpd = (ScriptModePrivateData *)sw->private_data;
rmpd->num_urgent_list = 0;
g_free ( rmpd->urgent_list );
rmpd->urgent_list = NULL;
rmpd->num_active_list = 0;
g_free ( rmpd->active_list );
rmpd->active_list = NULL;
rmpd->num_urgent_list = 0;
g_free(rmpd->urgent_list);
rmpd->urgent_list = NULL;
rmpd->num_active_list = 0;
g_free(rmpd->active_list);
rmpd->active_list = NULL;
}
static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line )
{
ScriptModePrivateData *rmpd = (ScriptModePrivateData *) sw->private_data;
ModeMode retv = MODE_EXIT;
DmenuScriptEntry *new_list = NULL;
unsigned int new_length = 0;
static ModeMode script_mode_result(Mode *sw, int mretv, char **input,
unsigned int selected_line) {
ScriptModePrivateData *rmpd = (ScriptModePrivateData *)sw->private_data;
ModeMode retv = MODE_EXIT;
DmenuScriptEntry *new_list = NULL;
unsigned int new_length = 0;
if ( ( mretv & MENU_CUSTOM_COMMAND ) ) {
if ( rmpd->use_hot_keys ) {
script_mode_reset_highlight ( sw );
if ( selected_line != UINT32_MAX ) {
new_list = execute_executor ( sw, rmpd->cmd_list[selected_line].entry, &new_length, 10 + ( mretv & MENU_LOWER_MASK ), &( rmpd->cmd_list[selected_line] ) );
}
else {
if ( rmpd->no_custom == FALSE ) {
new_list = execute_executor ( sw, *input, &new_length, 10 + ( mretv & MENU_LOWER_MASK ), NULL );
}
else {
return RELOAD_DIALOG;
}
}
}
else {
retv = ( mretv & MENU_LOWER_MASK );
return retv;
if ((mretv & MENU_CUSTOM_COMMAND)) {
if (rmpd->use_hot_keys) {
script_mode_reset_highlight(sw);
if (selected_line != UINT32_MAX) {
new_list = execute_executor(sw, rmpd->cmd_list[selected_line].entry,
&new_length, 10 + (mretv & MENU_LOWER_MASK),
&(rmpd->cmd_list[selected_line]));
} else {
if (rmpd->no_custom == FALSE) {
new_list = execute_executor(sw, *input, &new_length,
10 + (mretv & MENU_LOWER_MASK), NULL);
} else {
return RELOAD_DIALOG;
}
}
} else {
retv = (mretv & MENU_LOWER_MASK);
return retv;
}
else if ( ( mretv & MENU_OK ) && rmpd->cmd_list[selected_line].entry != NULL ) {
if ( rmpd->cmd_list[selected_line].nonselectable ) {
return RELOAD_DIALOG;
}
script_mode_reset_highlight ( sw );
new_list = execute_executor ( sw, rmpd->cmd_list[selected_line].entry, &new_length, 1, &( rmpd->cmd_list[selected_line] ) );
} else if ((mretv & MENU_OK) && rmpd->cmd_list[selected_line].entry != NULL) {
if (rmpd->cmd_list[selected_line].nonselectable) {
return RELOAD_DIALOG;
}
else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] != '\0' ) {
if ( rmpd->no_custom == FALSE ) {
script_mode_reset_highlight ( sw );
new_list = execute_executor ( sw, *input, &new_length, 2, NULL );
}
else {
return RELOAD_DIALOG;
}
script_mode_reset_highlight(sw);
new_list =
execute_executor(sw, rmpd->cmd_list[selected_line].entry, &new_length,
1, &(rmpd->cmd_list[selected_line]));
} else if ((mretv & MENU_CUSTOM_INPUT) && *input != NULL &&
*input[0] != '\0') {
if (rmpd->no_custom == FALSE) {
script_mode_reset_highlight(sw);
new_list = execute_executor(sw, *input, &new_length, 2, NULL);
} else {
return RELOAD_DIALOG;
}
}
// If a new list was generated, use that an loop around.
if ( new_list != NULL ) {
for ( unsigned int i = 0; i < rmpd->cmd_list_length; i++ ) {
g_free ( rmpd->cmd_list[i].entry );
g_free ( rmpd->cmd_list[i].icon_name );
g_free ( rmpd->cmd_list[i].meta );
}
g_free ( rmpd->cmd_list );
rmpd->cmd_list = new_list;
rmpd->cmd_list_length = new_length;
retv = RESET_DIALOG;
// If a new list was generated, use that an loop around.
if (new_list != NULL) {
for (unsigned int i = 0; i < rmpd->cmd_list_length; i++) {
g_free(rmpd->cmd_list[i].entry);
g_free(rmpd->cmd_list[i].icon_name);
g_free(rmpd->cmd_list[i].meta);
}
return retv;
g_free(rmpd->cmd_list);
rmpd->cmd_list = new_list;
rmpd->cmd_list_length = new_length;
retv = RESET_DIALOG;
}
return retv;
}
static void script_mode_destroy ( Mode *sw )
{
ScriptModePrivateData *rmpd = (ScriptModePrivateData *) sw->private_data;
if ( rmpd != NULL ) {
for ( unsigned int i = 0; i < rmpd->cmd_list_length; i++ ) {
g_free ( rmpd->cmd_list[i].entry );
g_free ( rmpd->cmd_list[i].icon_name );
g_free ( rmpd->cmd_list[i].meta );
}
g_free ( rmpd->cmd_list );
g_free ( rmpd->message );
g_free ( rmpd->prompt );
g_free ( rmpd->urgent_list );
g_free ( rmpd->active_list );
g_free ( rmpd );
sw->private_data = NULL;
static void script_mode_destroy(Mode *sw) {
ScriptModePrivateData *rmpd = (ScriptModePrivateData *)sw->private_data;
if (rmpd != NULL) {
for (unsigned int i = 0; i < rmpd->cmd_list_length; i++) {
g_free(rmpd->cmd_list[i].entry);
g_free(rmpd->cmd_list[i].icon_name);
g_free(rmpd->cmd_list[i].meta);
}
g_free(rmpd->cmd_list);
g_free(rmpd->message);
g_free(rmpd->prompt);
g_free(rmpd->urgent_list);
g_free(rmpd->active_list);
g_free(rmpd);
sw->private_data = NULL;
}
}
static inline unsigned int get_index ( unsigned int length, int index )
{
if ( index >= 0 ) {
return index;
}
if ( ( (unsigned int) -index ) <= length ) {
return length + index;
}
// Out of range.
return UINT_MAX;
static inline unsigned int get_index(unsigned int length, int index) {
if (index >= 0) {
return index;
}
if (((unsigned int)-index) <= length) {
return length + index;
}
// Out of range.
return UINT_MAX;
}
static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, G_GNUC_UNUSED GList **list, int get_entry )
{
ScriptModePrivateData *pd = sw->private_data;
for ( unsigned int i = 0; i < pd->num_active_list; i++ ) {
unsigned int start = get_index ( pd->cmd_list_length, pd->active_list[i].start );
unsigned int stop = get_index ( pd->cmd_list_length, pd->active_list[i].stop );
if ( selected_line >= start && selected_line <= stop ) {
*state |= ACTIVE;
}
static char *_get_display_value(const Mode *sw, unsigned int selected_line,
G_GNUC_UNUSED int *state,
G_GNUC_UNUSED GList **list, int get_entry) {
ScriptModePrivateData *pd = sw->private_data;
for (unsigned int i = 0; i < pd->num_active_list; i++) {
unsigned int start =
get_index(pd->cmd_list_length, pd->active_list[i].start);
unsigned int stop = get_index(pd->cmd_list_length, pd->active_list[i].stop);
if (selected_line >= start && selected_line <= stop) {
*state |= ACTIVE;
}
for ( unsigned int i = 0; i < pd->num_urgent_list; i++ ) {
unsigned int start = get_index ( pd->cmd_list_length, pd->urgent_list[i].start );
unsigned int stop = get_index ( pd->cmd_list_length, pd->urgent_list[i].stop );
if ( selected_line >= start && selected_line <= stop ) {
*state |= URGENT;
}
}
for (unsigned int i = 0; i < pd->num_urgent_list; i++) {
unsigned int start =
get_index(pd->cmd_list_length, pd->urgent_list[i].start);
unsigned int stop = get_index(pd->cmd_list_length, pd->urgent_list[i].stop);
if (selected_line >= start && selected_line <= stop) {
*state |= URGENT;
}
if ( pd->do_markup ) {
*state |= MARKUP;
}
return get_entry ? g_strdup ( pd->cmd_list[selected_line].entry ) : NULL;
}
if (pd->do_markup) {
*state |= MARKUP;
}
return get_entry ? g_strdup(pd->cmd_list[selected_line].entry) : NULL;
}
static int script_token_match ( const Mode *sw, rofi_int_matcher **tokens, unsigned int index )
{
ScriptModePrivateData *rmpd = sw->private_data;
int match = 1;
if ( tokens ) {
for ( int j = 0; match && tokens != NULL && tokens[j] != NULL; j++ ) {
rofi_int_matcher *ftokens[2] = { tokens[j], NULL };
int test = 0;
test = helper_token_match ( ftokens, rmpd->cmd_list[index].entry );
if ( test == tokens[j]->invert && rmpd->cmd_list[index].meta ) {
test = helper_token_match ( ftokens, rmpd->cmd_list[index].meta );
}
static int script_token_match(const Mode *sw, rofi_int_matcher **tokens,
unsigned int index) {
ScriptModePrivateData *rmpd = sw->private_data;
int match = 1;
if (tokens) {
for (int j = 0; match && tokens != NULL && tokens[j] != NULL; j++) {
rofi_int_matcher *ftokens[2] = {tokens[j], NULL};
int test = 0;
test = helper_token_match(ftokens, rmpd->cmd_list[index].entry);
if (test == tokens[j]->invert && rmpd->cmd_list[index].meta) {
test = helper_token_match(ftokens, rmpd->cmd_list[index].meta);
}
if ( test == 0 ) {
match = 0;
}
}
if (test == 0) {
match = 0;
}
}
return match;
}
return match;
}
static char *script_get_message ( const Mode *sw )
{
ScriptModePrivateData *pd = sw->private_data;
return g_strdup ( pd->message );
static char *script_get_message(const Mode *sw) {
ScriptModePrivateData *pd = sw->private_data;
return g_strdup(pd->message);
}
static cairo_surface_t *script_get_icon ( const Mode *sw, unsigned int selected_line, int height )
{
ScriptModePrivateData *pd = (ScriptModePrivateData *) mode_get_private_data ( sw );
g_return_val_if_fail ( pd->cmd_list != NULL, NULL );
DmenuScriptEntry *dr = &( pd->cmd_list[selected_line] );
if ( dr->icon_name == NULL ) {
return NULL;
}
if ( dr->icon_fetch_uid > 0 ) {
return rofi_icon_fetcher_get ( dr->icon_fetch_uid );
}
dr->icon_fetch_uid = rofi_icon_fetcher_query ( dr->icon_name, height );
return rofi_icon_fetcher_get ( dr->icon_fetch_uid );
static cairo_surface_t *
script_get_icon(const Mode *sw, unsigned int selected_line, int height) {
ScriptModePrivateData *pd =
(ScriptModePrivateData *)mode_get_private_data(sw);
g_return_val_if_fail(pd->cmd_list != NULL, NULL);
DmenuScriptEntry *dr = &(pd->cmd_list[selected_line]);
if (dr->icon_name == NULL) {
return NULL;
}
if (dr->icon_fetch_uid > 0) {
return rofi_icon_fetcher_get(dr->icon_fetch_uid);
}
dr->icon_fetch_uid = rofi_icon_fetcher_query(dr->icon_name, height);
return rofi_icon_fetcher_get(dr->icon_fetch_uid);
}
#include "mode-private.h"
Mode *script_switcher_parse_setup ( const char *str )
{
Mode *sw = g_malloc0 ( sizeof ( *sw ) );
char *endp = NULL;
char *parse = g_strdup ( str );
unsigned int index = 0;
const char *const sep = ":";
for ( char *token = strtok_r ( parse, sep, &endp ); token != NULL; token = strtok_r ( NULL, sep, &endp ) ) {
if ( index == 0 ) {
sw->name = g_strdup ( token );
}
else if ( index == 1 ) {
sw->ed = (void *) rofi_expand_path ( token );
}
index++;
Mode *script_switcher_parse_setup(const char *str) {
Mode *sw = g_malloc0(sizeof(*sw));
char *endp = NULL;
char *parse = g_strdup(str);
unsigned int index = 0;
const char *const sep = ":";
for (char *token = strtok_r(parse, sep, &endp); token != NULL;
token = strtok_r(NULL, sep, &endp)) {
if (index == 0) {
sw->name = g_strdup(token);
} else if (index == 1) {
sw->ed = (void *)rofi_expand_path(token);
}
g_free ( parse );
if ( index == 2 ) {
sw->free = script_switcher_free;
sw->_init = script_mode_init;
sw->_get_num_entries = script_mode_get_num_entries;
sw->_result = script_mode_result;
sw->_destroy = script_mode_destroy;
sw->_token_match = script_token_match;
sw->_get_message = script_get_message;
sw->_get_icon = script_get_icon;
sw->_get_completion = NULL,
sw->_preprocess_input = NULL,
sw->_get_display_value = _get_display_value;
index++;
}
g_free(parse);
if (index == 2) {
sw->free = script_switcher_free;
sw->_init = script_mode_init;
sw->_get_num_entries = script_mode_get_num_entries;
sw->_result = script_mode_result;
sw->_destroy = script_mode_destroy;
sw->_token_match = script_token_match;
sw->_get_message = script_get_message;
sw->_get_icon = script_get_icon;
sw->_get_completion = NULL, sw->_preprocess_input = NULL,
sw->_get_display_value = _get_display_value;
return sw;
}
fprintf ( stderr, "The script command '%s' has %u options, but needs 2: <name>:<script>.", str, index );
script_switcher_free ( sw );
return NULL;
return sw;
}
fprintf(
stderr,
"The script command '%s' has %u options, but needs 2: <name>:<script>.",
str, index);
script_switcher_free(sw);
return NULL;
}
gboolean script_switcher_is_valid ( const char *token )
{
return strchr ( token, ':' ) != NULL;
gboolean script_switcher_is_valid(const char *token) {
return strchr(token, ':') != NULL;
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,75 +1,43 @@
#include "keyb.h"
#include <glib.h>
#include <xcb/xkb.h>
#include "keyb.h"
#include "display.h"
#include "display-internal.h"
#include "display.h"
#include "view.h"
#include "view-internal.h"
static const display_proxy *proxy;
void display_init ( const display_proxy *disp_in )
{
proxy = disp_in;
view_init ( proxy->view () );
void display_init(const display_proxy *disp_in) {
proxy = disp_in;
view_init(proxy->view());
}
int
monitor_active ( workarea *mon )
{
return proxy->monitor_active ( mon );
int monitor_active(workarea *mon) { return proxy->monitor_active(mon); }
void display_set_input_focus(guint w) { proxy->set_input_focus(w); }
void display_revert_input_focus() { proxy->revert_input_focus(); }
gboolean display_setup(GMainLoop *main_loop, NkBindings *bindings) {
return proxy->setup(main_loop, bindings);
}
void display_set_input_focus ( guint w )
{
proxy->set_input_focus(w);
gboolean display_late_setup(void) { return proxy->late_setup(); }
void display_early_cleanup(void) { proxy->early_cleanup(); }
void display_cleanup(void) { proxy->cleanup(); }
void display_dump_monitor_layout(void) { proxy->dump_monitor_layout(); }
void display_startup_notification(RofiHelperExecuteContext *context,
GSpawnChildSetupFunc *child_setup,
gpointer *user_data) {
proxy->startup_notification(context, child_setup, user_data);
}
void display_revert_input_focus ()
{
proxy->revert_input_focus();
}
gboolean
display_setup ( GMainLoop *main_loop, NkBindings *bindings )
{
return proxy->setup ( main_loop, bindings );
}
gboolean
display_late_setup ( void )
{
return proxy->late_setup ( );
}
void
display_early_cleanup ( void )
{
proxy->early_cleanup ( );
}
void
display_cleanup ( void )
{
proxy->cleanup ( );
}
void
display_dump_monitor_layout ( void )
{
proxy->dump_monitor_layout ( );
}
void
display_startup_notification ( RofiHelperExecuteContext *context, GSpawnChildSetupFunc *child_setup, gpointer *user_data )
{
proxy->startup_notification ( context, child_setup, user_data );
}
guint
display_scale ( void )
{
return proxy->scale ( );
}
guint display_scale(void) { return proxy->scale(); }

File diff suppressed because it is too large Load diff

View file

@ -25,327 +25,324 @@
*
*/
#include <config.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include "history.h"
#include "rofi.h"
#include "settings.h"
#include <errno.h>
#include <glib.h>
#include <glib/gstdio.h>
#include "rofi.h"
#include "history.h"
#include "settings.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
/**
* History element
*/
typedef struct __element
{
/** Index in history */
long int index;
/** Entry */
char *name;
}_element;
typedef struct __element {
/** Index in history */
long int index;
/** Entry */
char *name;
} _element;
static int __element_sort_func ( const void *ea, const void *eb, void *data __attribute__( ( unused ) ) )
{
_element *a = *(_element * *) ea;
_element *b = *(_element * *) eb;
return b->index - a->index;
static int __element_sort_func(const void *ea, const void *eb,
void *data __attribute__((unused))) {
_element *a = *(_element **)ea;
_element *b = *(_element **)eb;
return b->index - a->index;
}
static void __history_write_element_list ( FILE *fd, _element **list, unsigned int length )
{
if ( list == NULL || length == 0 ) {
return;
}
// Sort the list before writing out.
g_qsort_with_data ( list, length, sizeof ( _element* ), __element_sort_func, NULL );
static void __history_write_element_list(FILE *fd, _element **list,
unsigned int length) {
if (list == NULL || length == 0) {
return;
}
// Sort the list before writing out.
g_qsort_with_data(list, length, sizeof(_element *), __element_sort_func,
NULL);
// Get minimum index.
int min_value = list[length - 1]->index;
// Get minimum index.
int min_value = list[length - 1]->index;
// Set the max length of the list.
length = ( length > config.max_history_size ) ? config.max_history_size : length;
// Set the max length of the list.
length =
(length > config.max_history_size) ? config.max_history_size : length;
// Write out entries.
for ( unsigned int iter = 0; iter < length; iter++ ) {
fprintf ( fd, "%ld %s\n", list[iter]->index - min_value, list[iter]->name );
}
// Write out entries.
for (unsigned int iter = 0; iter < length; iter++) {
fprintf(fd, "%ld %s\n", list[iter]->index - min_value, list[iter]->name);
}
}
static char ** __history_get_element_list_fields ( FILE *fd, unsigned int *length )
{
unsigned int real_length = 0;
char **retv = NULL;;
if ( length == NULL ) {
return NULL;
}
*length = 0;
static char **__history_get_element_list_fields(FILE *fd,
unsigned int *length) {
unsigned int real_length = 0;
char **retv = NULL;
;
if (length == NULL) {
return NULL;
}
*length = 0;
if ( fd == NULL ) {
return NULL;
if (fd == NULL) {
return NULL;
}
char *buffer = NULL;
size_t buffer_length = 0;
ssize_t l = 0;
while ((l = getline(&buffer, &buffer_length, fd)) > 0) {
// Jump to the first space.
const char *start = strchr(buffer, ' ');
// not found, skip.
if (start == NULL) {
continue;
}
char *buffer = NULL;
size_t buffer_length = 0;
ssize_t l = 0;
while ( ( l = getline ( &buffer, &buffer_length, fd ) ) > 0 ) {
// Jump to the first space.
const char *start = strchr ( buffer, ' ' );
// not found, skip.
if ( start == NULL ) {
continue;
}
start++;
// remove trailing \n
buffer[l - 1] = '\0';
if ( real_length < ( *length + 2 ) ) {
real_length += 15;
// Resize and check.
retv = g_realloc ( retv, ( real_length ) * sizeof ( char* ) );
}
// Parse the number of times.
retv[( *length )] = g_strndup ( start, l - 1 - ( start - buffer ) );
// Force trailing '\0'
retv[( *length ) + 1] = NULL;
start++;
// remove trailing \n
buffer[l - 1] = '\0';
if (real_length < (*length + 2)) {
real_length += 15;
// Resize and check.
retv = g_realloc(retv, (real_length) * sizeof(char *));
}
// Parse the number of times.
retv[(*length)] = g_strndup(start, l - 1 - (start - buffer));
// Force trailing '\0'
retv[(*length) + 1] = NULL;
( *length )++;
}
if ( buffer_length > 0 ) {
g_free ( buffer );
}
return retv;
(*length)++;
}
if (buffer_length > 0) {
g_free(buffer);
}
return retv;
}
static _element ** __history_get_element_list ( FILE *fd, unsigned int *length )
{
unsigned int real_length = 0;
_element **retv = NULL;
static _element **__history_get_element_list(FILE *fd, unsigned int *length) {
unsigned int real_length = 0;
_element **retv = NULL;
if ( length == NULL ) {
return NULL;
if (length == NULL) {
return NULL;
}
*length = 0;
if (fd == NULL) {
return NULL;
}
char *buffer = NULL;
size_t buffer_length = 0;
ssize_t l = 0;
while ((l = getline(&buffer, &buffer_length, fd)) > 0) {
char *start = NULL;
// Skip empty lines.
if (l <= 1) {
continue;
}
*length = 0;
if ( fd == NULL ) {
return NULL;
long int index = strtol(buffer, &start, 10);
if (start == buffer || *start == '\0') {
continue;
}
char *buffer = NULL;
size_t buffer_length = 0;
ssize_t l = 0;
while ( ( l = getline ( &buffer, &buffer_length, fd ) ) > 0 ) {
char * start = NULL;
// Skip empty lines.
if ( l <= 1 ) {
continue;
}
long int index = strtol ( buffer, &start, 10 );
if ( start == buffer || *start == '\0' ) {
continue;
}
start++;
if ( ( l - ( start - buffer ) ) < 2 ) {
continue;
}
if ( real_length < ( *length + 2 ) ) {
real_length += 15;
// Resize and check.
retv = g_realloc ( retv, ( real_length ) * sizeof ( _element* ) );
}
retv[( *length )] = g_malloc ( sizeof ( _element ) );
// remove trailing \n
buffer[l - 1] = '\0';
// Parse the number of times.
retv[( *length )]->index = index;
retv[( *length )]->name = g_strndup ( start, l - 1 - ( start - buffer ) );
// Force trailing '\0'
retv[( *length ) + 1] = NULL;
( *length )++;
start++;
if ((l - (start - buffer)) < 2) {
continue;
}
if ( buffer != NULL ) {
free ( buffer );
buffer = NULL;
if (real_length < (*length + 2)) {
real_length += 15;
// Resize and check.
retv = g_realloc(retv, (real_length) * sizeof(_element *));
}
return retv;
retv[(*length)] = g_malloc(sizeof(_element));
// remove trailing \n
buffer[l - 1] = '\0';
// Parse the number of times.
retv[(*length)]->index = index;
retv[(*length)]->name = g_strndup(start, l - 1 - (start - buffer));
// Force trailing '\0'
retv[(*length) + 1] = NULL;
(*length)++;
}
if (buffer != NULL) {
free(buffer);
buffer = NULL;
}
return retv;
}
void history_set ( const char *filename, const char *entry )
{
if ( config.disable_history ) {
return;
void history_set(const char *filename, const char *entry) {
if (config.disable_history) {
return;
}
// Check if program should be ignored
for (char *checked_prefix = strtok(config.ignored_prefixes, ";");
checked_prefix != NULL; checked_prefix = strtok(NULL, ";")) {
// For each ignored prefix
while (g_unichar_isspace(g_utf8_get_char(checked_prefix))) {
checked_prefix = g_utf8_next_char(
checked_prefix); // Some users will probably want "; " as their
// separator for aesthetics.
}
// Check if program should be ignored
for ( char *checked_prefix = strtok ( config.ignored_prefixes, ";" ); checked_prefix != NULL; checked_prefix = strtok ( NULL, ";" ) ) {
// For each ignored prefix
if (g_str_has_prefix(entry, checked_prefix)) {
return;
}
}
while ( g_unichar_isspace ( g_utf8_get_char ( checked_prefix ) ) ) {
checked_prefix = g_utf8_next_char ( checked_prefix ); // Some users will probably want "; " as their separator for aesthetics.
}
if ( g_str_has_prefix ( entry, checked_prefix ) ) {
return;
}
}
int found = 0;
unsigned int curr = 0;
unsigned int length = 0;
_element **list = NULL;
// Open file for reading and writing.
FILE *fd = g_fopen ( filename, "r" );
if ( fd != NULL ) {
// Get list.
list = __history_get_element_list ( fd, &length );
// Close file, if fails let user know on stderr.
if ( fclose ( fd ) != 0 ) {
g_warning ( "Failed to close history file: %s", g_strerror ( errno ) );
}
}
// Look if the entry exists.
for ( unsigned int iter = 0; !found && iter < length; iter++ ) {
if ( strcmp ( list[iter]->name, entry ) == 0 ) {
curr = iter;
found = 1;
}
}
if ( found ) {
// If exists, increment list index number
list[curr]->index++;
}
else{
// If not exists, add it.
// Increase list by one
list = g_realloc ( list, ( length + 2 ) * sizeof ( _element* ) );
list[length] = g_malloc ( sizeof ( _element ) );
// Copy name
if ( list[length] != NULL ) {
list[length]->name = g_strdup ( entry );
// set # hits
list[length]->index = 1;
length++;
list[length] = NULL;
}
}
fd = fopen ( filename, "w" );
if ( fd == NULL ) {
g_warning ( "Failed to open file: %s", g_strerror ( errno ) );
}
else {
// Write list.
__history_write_element_list ( fd, list, length );
// Close file, if fails let user know on stderr.
if ( fclose ( fd ) != 0 ) {
g_warning ( "Failed to close history file: %s", g_strerror ( errno ) );
}
}
// Free the list.
for ( unsigned int iter = 0; iter < length; iter++ ) {
g_free ( list[iter]->name );
g_free ( list[iter] );
}
g_free ( list );
}
void history_remove ( const char *filename, const char *entry )
{
if ( config.disable_history ) {
return;
}
_element ** list = NULL;
int found = 0;
unsigned int curr = 0;
unsigned int length = 0;
// Open file for reading and writing.
FILE *fd = g_fopen ( filename, "r" );
if ( fd == NULL ) {
g_warning ( "Failed to open file: %s", g_strerror ( errno ) );
return;
}
int found = 0;
unsigned int curr = 0;
unsigned int length = 0;
_element **list = NULL;
// Open file for reading and writing.
FILE *fd = g_fopen(filename, "r");
if (fd != NULL) {
// Get list.
list = __history_get_element_list ( fd, &length );
list = __history_get_element_list(fd, &length);
// Close file, if fails let user know on stderr.
if ( fclose ( fd ) != 0 ) {
g_warning ( "Failed to close history file: %s", g_strerror ( errno ) );
if (fclose(fd) != 0) {
g_warning("Failed to close history file: %s", g_strerror(errno));
}
// Find entry.
for ( unsigned int iter = 0; !found && iter < length; iter++ ) {
if ( strcmp ( list[iter]->name, entry ) == 0 ) {
curr = iter;
found = 1;
}
}
// Look if the entry exists.
for (unsigned int iter = 0; !found && iter < length; iter++) {
if (strcmp(list[iter]->name, entry) == 0) {
curr = iter;
found = 1;
}
}
// If found, remove it and write out new file.
if ( found ) {
// Remove the entry.
g_free ( list[curr]->name );
g_free ( list[curr] );
// Swap last to here (if list is size 1, we just swap empty sets).
list[curr] = list[length - 1];
// Empty last.
list[length - 1] = NULL;
length--;
if (found) {
// If exists, increment list index number
list[curr]->index++;
} else {
// If not exists, add it.
// Increase list by one
list = g_realloc(list, (length + 2) * sizeof(_element *));
list[length] = g_malloc(sizeof(_element));
// Copy name
if (list[length] != NULL) {
list[length]->name = g_strdup(entry);
// set # hits
list[length]->index = 1;
fd = g_fopen ( filename, "w" );
// Clear list.
if ( fd != NULL ) {
// Write list.
__history_write_element_list ( fd, list, length );
// Close file, if fails let user know on stderr.
if ( fclose ( fd ) != 0 ) {
g_warning ( "Failed to close history file: %s", g_strerror ( errno ) );
}
}
else{
g_warning ( "Failed to open file: %s", g_strerror ( errno ) );
}
length++;
list[length] = NULL;
}
}
// Free the list.
for ( unsigned int iter = 0; iter < length; iter++ ) {
g_free ( list[iter]->name );
g_free ( list[iter] );
}
if ( list != NULL ) {
g_free ( list );
fd = fopen(filename, "w");
if (fd == NULL) {
g_warning("Failed to open file: %s", g_strerror(errno));
} else {
// Write list.
__history_write_element_list(fd, list, length);
// Close file, if fails let user know on stderr.
if (fclose(fd) != 0) {
g_warning("Failed to close history file: %s", g_strerror(errno));
}
}
// Free the list.
for (unsigned int iter = 0; iter < length; iter++) {
g_free(list[iter]->name);
g_free(list[iter]);
}
g_free(list);
}
char ** history_get_list ( const char *filename, unsigned int *length )
{
*length = 0;
void history_remove(const char *filename, const char *entry) {
if (config.disable_history) {
return;
}
_element **list = NULL;
int found = 0;
unsigned int curr = 0;
unsigned int length = 0;
// Open file for reading and writing.
FILE *fd = g_fopen(filename, "r");
if (fd == NULL) {
g_warning("Failed to open file: %s", g_strerror(errno));
return;
}
// Get list.
list = __history_get_element_list(fd, &length);
if ( config.disable_history ) {
return NULL;
// Close file, if fails let user know on stderr.
if (fclose(fd) != 0) {
g_warning("Failed to close history file: %s", g_strerror(errno));
}
// Find entry.
for (unsigned int iter = 0; !found && iter < length; iter++) {
if (strcmp(list[iter]->name, entry) == 0) {
curr = iter;
found = 1;
}
char **retv = NULL;
// Open file.
FILE *fd = g_fopen ( filename, "r" );
if ( fd == NULL ) {
// File that does not exists is not an error, so ignore it.
// Everything else? panic.
if ( errno != ENOENT ) {
g_warning ( "Failed to open file: %s", g_strerror ( errno ) );
}
return NULL;
}
// Get list.
retv = __history_get_element_list_fields ( fd, length );
}
// Close file, if fails let user know on stderr.
if ( fclose ( fd ) != 0 ) {
g_warning ( "Failed to close history file: %s", g_strerror ( errno ) );
// If found, remove it and write out new file.
if (found) {
// Remove the entry.
g_free(list[curr]->name);
g_free(list[curr]);
// Swap last to here (if list is size 1, we just swap empty sets).
list[curr] = list[length - 1];
// Empty last.
list[length - 1] = NULL;
length--;
fd = g_fopen(filename, "w");
// Clear list.
if (fd != NULL) {
// Write list.
__history_write_element_list(fd, list, length);
// Close file, if fails let user know on stderr.
if (fclose(fd) != 0) {
g_warning("Failed to close history file: %s", g_strerror(errno));
}
} else {
g_warning("Failed to open file: %s", g_strerror(errno));
}
return retv;
}
// Free the list.
for (unsigned int iter = 0; iter < length; iter++) {
g_free(list[iter]->name);
g_free(list[iter]);
}
if (list != NULL) {
g_free(list);
}
}
char **history_get_list(const char *filename, unsigned int *length) {
*length = 0;
if (config.disable_history) {
return NULL;
}
char **retv = NULL;
// Open file.
FILE *fd = g_fopen(filename, "r");
if (fd == NULL) {
// File that does not exists is not an error, so ignore it.
// Everything else? panic.
if (errno != ENOENT) {
g_warning("Failed to open file: %s", g_strerror(errno));
}
return NULL;
}
// Get list.
retv = __history_get_element_list_fields(fd, length);
// Close file, if fails let user know on stderr.
if (fclose(fd) != 0) {
g_warning("Failed to close history file: %s", g_strerror(errno));
}
return retv;
}

View file

@ -25,176 +25,412 @@
*
*/
#include <config.h>
#include "config.h"
#include <string.h>
#include "rofi.h"
#include "nkutils-bindings.h"
#include "xrmoptions.h"
typedef struct
{
guint id;
guint scope;
char *name;
char *binding;
char *comment;
typedef struct {
guint id;
guint scope;
char *name;
char *binding;
char *comment;
} ActionBindingEntry;
/**
* Data structure holding all the action keybinding.
*/
ActionBindingEntry rofi_bindings[] =
{
{ .id = PASTE_PRIMARY, .name = "kb-primary-paste", .binding = "Control+V,Shift+Insert", .comment = "Paste primary selection" },
{ .id = PASTE_SECONDARY, .name = "kb-secondary-paste", .binding = "Control+v,Insert", .comment = "Paste clipboard" },
{ .id = CLEAR_LINE, .name = "kb-clear-line", .binding = "Control+w", .comment = "Clear input line" },
{ .id = MOVE_FRONT, .name = "kb-move-front", .binding = "Control+a", .comment = "Beginning of line" },
{ .id = MOVE_END, .name = "kb-move-end", .binding = "Control+e", .comment = "End of line" },
{ .id = MOVE_WORD_BACK, .name = "kb-move-word-back", .binding = "Alt+b,Control+Left", .comment = "Move back one word" },
{ .id = MOVE_WORD_FORWARD, .name = "kb-move-word-forward", .binding = "Alt+f,Control+Right", .comment = "Move forward one word" },
{ .id = MOVE_CHAR_BACK, .name = "kb-move-char-back", .binding = "Left,Control+b", .comment = "Move back one char" },
{ .id = MOVE_CHAR_FORWARD, .name = "kb-move-char-forward", .binding = "Right,Control+f", .comment = "Move forward one char" },
{ .id = REMOVE_WORD_BACK, .name = "kb-remove-word-back", .binding = "Control+Alt+h,Control+BackSpace", .comment = "Delete previous word" },
{ .id = REMOVE_WORD_FORWARD, .name = "kb-remove-word-forward", .binding = "Control+Alt+d", .comment = "Delete next word" },
{ .id = REMOVE_CHAR_FORWARD, .name = "kb-remove-char-forward", .binding = "Delete,Control+d", .comment = "Delete next char" },
{ .id = REMOVE_CHAR_BACK, .name = "kb-remove-char-back", .binding = "BackSpace,Shift+BackSpace,Control+h", .comment = "Delete previous char" },
{ .id = REMOVE_TO_EOL, .name = "kb-remove-to-eol", .binding = "Control+k", .comment = "Delete till the end of line" },
{ .id = REMOVE_TO_SOL, .name = "kb-remove-to-sol", .binding = "Control+u", .comment = "Delete till the start of line" },
{ .id = ACCEPT_ENTRY, .name = "kb-accept-entry", .binding = "Control+j,Control+m,Return,KP_Enter", .comment = "Accept entry" },
{ .id = ACCEPT_CUSTOM, .name = "kb-accept-custom", .binding = "Control+Return", .comment = "Use entered text as command (in ssh/run modi)" },
{ .id = ACCEPT_CUSTOM_ALT, .name = "kb-accept-custom-alt", .binding = "Control+Shift+Return", .comment = "Use entered text as command (in ssh/run modi)" },
{ .id = ACCEPT_ALT, .name = "kb-accept-alt", .binding = "Shift+Return", .comment = "Use alternate accept command." },
{ .id = DELETE_ENTRY, .name = "kb-delete-entry", .binding = "Shift+Delete", .comment = "Delete entry from history" },
{ .id = MODE_NEXT, .name = "kb-mode-next", .binding = "Shift+Right,Control+Tab", .comment = "Switch to the next mode." },
{ .id = MODE_PREVIOUS, .name = "kb-mode-previous", .binding = "Shift+Left,Control+ISO_Left_Tab", .comment = "Switch to the previous mode." },
{ .id = MODE_COMPLETE, .name = "kb-mode-complete", .binding = "Control+l", .comment = "Start completion for mode." },
{ .id = ROW_LEFT, .name = "kb-row-left", .binding = "Control+Page_Up", .comment = "Go to the previous column" },
{ .id = ROW_RIGHT, .name = "kb-row-right", .binding = "Control+Page_Down", .comment = "Go to the next column" },
{ .id = ROW_UP, .name = "kb-row-up", .binding = "Up,Control+p,ISO_Left_Tab", .comment = "Select previous entry" },
{ .id = ROW_DOWN, .name = "kb-row-down", .binding = "Down,Control+n", .comment = "Select next entry" },
{ .id = ROW_TAB, .name = "kb-row-tab", .binding = "Tab", .comment = "Go to next row, if one left, accept it, if no left next mode." },
{ .id = PAGE_PREV, .name = "kb-page-prev", .binding = "Page_Up", .comment = "Go to the previous page" },
{ .id = PAGE_NEXT, .name = "kb-page-next", .binding = "Page_Down", .comment = "Go to the next page" },
{ .id = ROW_FIRST, .name = "kb-row-first", .binding = "Home,KP_Home", .comment = "Go to the first entry" },
{ .id = ROW_LAST, .name = "kb-row-last", .binding = "End,KP_End", .comment = "Go to the last entry" },
{ .id = ROW_SELECT, .name = "kb-row-select", .binding = "Control+space", .comment = "Set selected item as input text" },
{ .id = SCREENSHOT, .name = "kb-screenshot", .binding = "Alt+S", .comment = "Take a screenshot of the rofi window" },
{ .id = CHANGE_ELLIPSIZE, .name = "kb-ellipsize", .binding = "Alt+period", .comment = "Toggle between ellipsize modes for displayed data" },
{ .id = TOGGLE_CASE_SENSITIVITY, .name = "kb-toggle-case-sensitivity", .binding = "grave,dead_grave", .comment = "Toggle case sensitivity" },
{ .id = TOGGLE_SORT, .name = "kb-toggle-sort", .binding = "Alt+grave", .comment = "Toggle sort" },
{ .id = CANCEL, .name = "kb-cancel", .binding = "Escape,Control+g,Control+bracketleft", .comment = "Quit rofi" },
{ .id = CUSTOM_1, .name = "kb-custom-1", .binding = "Alt+1", .comment = "Custom keybinding 1" },
{ .id = CUSTOM_2, .name = "kb-custom-2", .binding = "Alt+2", .comment = "Custom keybinding 2" },
{ .id = CUSTOM_3, .name = "kb-custom-3", .binding = "Alt+3", .comment = "Custom keybinding 3" },
{ .id = CUSTOM_4, .name = "kb-custom-4", .binding = "Alt+4", .comment = "Custom keybinding 4" },
{ .id = CUSTOM_5, .name = "kb-custom-5", .binding = "Alt+5", .comment = "Custom Keybinding 5" },
{ .id = CUSTOM_6, .name = "kb-custom-6", .binding = "Alt+6", .comment = "Custom keybinding 6" },
{ .id = CUSTOM_7, .name = "kb-custom-7", .binding = "Alt+7", .comment = "Custom Keybinding 7" },
{ .id = CUSTOM_8, .name = "kb-custom-8", .binding = "Alt+8", .comment = "Custom keybinding 8" },
{ .id = CUSTOM_9, .name = "kb-custom-9", .binding = "Alt+9", .comment = "Custom keybinding 9" },
{ .id = CUSTOM_10, .name = "kb-custom-10", .binding = "Alt+0", .comment = "Custom keybinding 10" },
{ .id = CUSTOM_11, .name = "kb-custom-11", .binding = "Alt+exclam", .comment = "Custom keybinding 11" },
{ .id = CUSTOM_12, .name = "kb-custom-12", .binding = "Alt+at", .comment = "Custom keybinding 12" },
{ .id = CUSTOM_13, .name = "kb-custom-13", .binding = "Alt+numbersign", .comment = "Custom keybinding 13" },
{ .id = CUSTOM_14, .name = "kb-custom-14", .binding = "Alt+dollar", .comment = "Custom keybinding 14" },
{ .id = CUSTOM_15, .name = "kb-custom-15", .binding = "Alt+percent", .comment = "Custom keybinding 15" },
{ .id = CUSTOM_16, .name = "kb-custom-16", .binding = "Alt+dead_circumflex", .comment = "Custom keybinding 16" },
{ .id = CUSTOM_17, .name = "kb-custom-17", .binding = "Alt+ampersand", .comment = "Custom keybinding 17" },
{ .id = CUSTOM_18, .name = "kb-custom-18", .binding = "Alt+asterisk", .comment = "Custom keybinding 18" },
{ .id = CUSTOM_19, .name = "kb-custom-19", .binding = "Alt+parenleft", .comment = "Custom Keybinding 19" },
{ .id = SELECT_ELEMENT_1, .name = "kb-select-1", .binding = "Super+1", .comment = "Select row 1" },
{ .id = SELECT_ELEMENT_2, .name = "kb-select-2", .binding = "Super+2", .comment = "Select row 2" },
{ .id = SELECT_ELEMENT_3, .name = "kb-select-3", .binding = "Super+3", .comment = "Select row 3" },
{ .id = SELECT_ELEMENT_4, .name = "kb-select-4", .binding = "Super+4", .comment = "Select row 4" },
{ .id = SELECT_ELEMENT_5, .name = "kb-select-5", .binding = "Super+5", .comment = "Select row 5" },
{ .id = SELECT_ELEMENT_6, .name = "kb-select-6", .binding = "Super+6", .comment = "Select row 6" },
{ .id = SELECT_ELEMENT_7, .name = "kb-select-7", .binding = "Super+7", .comment = "Select row 7" },
{ .id = SELECT_ELEMENT_8, .name = "kb-select-8", .binding = "Super+8", .comment = "Select row 8" },
{ .id = SELECT_ELEMENT_9, .name = "kb-select-9", .binding = "Super+9", .comment = "Select row 9" },
{ .id = SELECT_ELEMENT_10, .name = "kb-select-10", .binding = "Super+0", .comment = "Select row 10" },
ActionBindingEntry rofi_bindings[] = {
{.id = PASTE_PRIMARY,
.name = "kb-primary-paste",
.binding = "Control+V,Shift+Insert",
.comment = "Paste primary selection"},
{.id = PASTE_SECONDARY,
.name = "kb-secondary-paste",
.binding = "Control+v,Insert",
.comment = "Paste clipboard"},
{.id = CLEAR_LINE,
.name = "kb-clear-line",
.binding = "Control+w",
.comment = "Clear input line"},
{.id = MOVE_FRONT,
.name = "kb-move-front",
.binding = "Control+a",
.comment = "Beginning of line"},
{.id = MOVE_END,
.name = "kb-move-end",
.binding = "Control+e",
.comment = "End of line"},
{.id = MOVE_WORD_BACK,
.name = "kb-move-word-back",
.binding = "Alt+b,Control+Left",
.comment = "Move back one word"},
{.id = MOVE_WORD_FORWARD,
.name = "kb-move-word-forward",
.binding = "Alt+f,Control+Right",
.comment = "Move forward one word"},
{.id = MOVE_CHAR_BACK,
.name = "kb-move-char-back",
.binding = "Left,Control+b",
.comment = "Move back one char"},
{.id = MOVE_CHAR_FORWARD,
.name = "kb-move-char-forward",
.binding = "Right,Control+f",
.comment = "Move forward one char"},
{.id = REMOVE_WORD_BACK,
.name = "kb-remove-word-back",
.binding = "Control+Alt+h,Control+BackSpace",
.comment = "Delete previous word"},
{.id = REMOVE_WORD_FORWARD,
.name = "kb-remove-word-forward",
.binding = "Control+Alt+d",
.comment = "Delete next word"},
{.id = REMOVE_CHAR_FORWARD,
.name = "kb-remove-char-forward",
.binding = "Delete,Control+d",
.comment = "Delete next char"},
{.id = REMOVE_CHAR_BACK,
.name = "kb-remove-char-back",
.binding = "BackSpace,Shift+BackSpace,Control+h",
.comment = "Delete previous char"},
{.id = REMOVE_TO_EOL,
.name = "kb-remove-to-eol",
.binding = "Control+k",
.comment = "Delete till the end of line"},
{.id = REMOVE_TO_SOL,
.name = "kb-remove-to-sol",
.binding = "Control+u",
.comment = "Delete till the start of line"},
{.id = ACCEPT_ENTRY,
.name = "kb-accept-entry",
.binding = "Control+j,Control+m,Return,KP_Enter",
.comment = "Accept entry"},
{.id = ACCEPT_CUSTOM,
.name = "kb-accept-custom",
.binding = "Control+Return",
.comment = "Use entered text as command (in ssh/run modi)"},
{.id = ACCEPT_CUSTOM_ALT,
.name = "kb-accept-custom-alt",
.binding = "Control+Shift+Return",
.comment = "Use entered text as command (in ssh/run modi)"},
{.id = ACCEPT_ALT,
.name = "kb-accept-alt",
.binding = "Shift+Return",
.comment = "Use alternate accept command."},
{.id = DELETE_ENTRY,
.name = "kb-delete-entry",
.binding = "Shift+Delete",
.comment = "Delete entry from history"},
{.id = MODE_NEXT,
.name = "kb-mode-next",
.binding = "Shift+Right,Control+Tab",
.comment = "Switch to the next mode."},
{.id = MODE_PREVIOUS,
.name = "kb-mode-previous",
.binding = "Shift+Left,Control+ISO_Left_Tab",
.comment = "Switch to the previous mode."},
{.id = MODE_COMPLETE,
.name = "kb-mode-complete",
.binding = "Control+l",
.comment = "Start completion for mode."},
{.id = ROW_LEFT,
.name = "kb-row-left",
.binding = "Control+Page_Up",
.comment = "Go to the previous column"},
{.id = ROW_RIGHT,
.name = "kb-row-right",
.binding = "Control+Page_Down",
.comment = "Go to the next column"},
{.id = ROW_UP,
.name = "kb-row-up",
.binding = "Up,Control+p,ISO_Left_Tab",
.comment = "Select previous entry"},
{.id = ROW_DOWN,
.name = "kb-row-down",
.binding = "Down,Control+n",
.comment = "Select next entry"},
{.id = ROW_TAB,
.name = "kb-row-tab",
.binding = "Tab",
.comment =
"Go to next row, if one left, accept it, if no left next mode."},
{.id = PAGE_PREV,
.name = "kb-page-prev",
.binding = "Page_Up",
.comment = "Go to the previous page"},
{.id = PAGE_NEXT,
.name = "kb-page-next",
.binding = "Page_Down",
.comment = "Go to the next page"},
{.id = ROW_FIRST,
.name = "kb-row-first",
.binding = "Home,KP_Home",
.comment = "Go to the first entry"},
{.id = ROW_LAST,
.name = "kb-row-last",
.binding = "End,KP_End",
.comment = "Go to the last entry"},
{.id = ROW_SELECT,
.name = "kb-row-select",
.binding = "Control+space",
.comment = "Set selected item as input text"},
{.id = SCREENSHOT,
.name = "kb-screenshot",
.binding = "Alt+S",
.comment = "Take a screenshot of the rofi window"},
{.id = CHANGE_ELLIPSIZE,
.name = "kb-ellipsize",
.binding = "Alt+period",
.comment = "Toggle between ellipsize modes for displayed data"},
{.id = TOGGLE_CASE_SENSITIVITY,
.name = "kb-toggle-case-sensitivity",
.binding = "grave,dead_grave",
.comment = "Toggle case sensitivity"},
{.id = TOGGLE_SORT,
.name = "kb-toggle-sort",
.binding = "Alt+grave",
.comment = "Toggle sort"},
{.id = CANCEL,
.name = "kb-cancel",
.binding = "Escape,Control+g,Control+bracketleft",
.comment = "Quit rofi"},
{.id = CUSTOM_1,
.name = "kb-custom-1",
.binding = "Alt+1",
.comment = "Custom keybinding 1"},
{.id = CUSTOM_2,
.name = "kb-custom-2",
.binding = "Alt+2",
.comment = "Custom keybinding 2"},
{.id = CUSTOM_3,
.name = "kb-custom-3",
.binding = "Alt+3",
.comment = "Custom keybinding 3"},
{.id = CUSTOM_4,
.name = "kb-custom-4",
.binding = "Alt+4",
.comment = "Custom keybinding 4"},
{.id = CUSTOM_5,
.name = "kb-custom-5",
.binding = "Alt+5",
.comment = "Custom Keybinding 5"},
{.id = CUSTOM_6,
.name = "kb-custom-6",
.binding = "Alt+6",
.comment = "Custom keybinding 6"},
{.id = CUSTOM_7,
.name = "kb-custom-7",
.binding = "Alt+7",
.comment = "Custom Keybinding 7"},
{.id = CUSTOM_8,
.name = "kb-custom-8",
.binding = "Alt+8",
.comment = "Custom keybinding 8"},
{.id = CUSTOM_9,
.name = "kb-custom-9",
.binding = "Alt+9",
.comment = "Custom keybinding 9"},
{.id = CUSTOM_10,
.name = "kb-custom-10",
.binding = "Alt+0",
.comment = "Custom keybinding 10"},
{.id = CUSTOM_11,
.name = "kb-custom-11",
.binding = "Alt+exclam",
.comment = "Custom keybinding 11"},
{.id = CUSTOM_12,
.name = "kb-custom-12",
.binding = "Alt+at",
.comment = "Custom keybinding 12"},
{.id = CUSTOM_13,
.name = "kb-custom-13",
.binding = "Alt+numbersign",
.comment = "Custom keybinding 13"},
{.id = CUSTOM_14,
.name = "kb-custom-14",
.binding = "Alt+dollar",
.comment = "Custom keybinding 14"},
{.id = CUSTOM_15,
.name = "kb-custom-15",
.binding = "Alt+percent",
.comment = "Custom keybinding 15"},
{.id = CUSTOM_16,
.name = "kb-custom-16",
.binding = "Alt+dead_circumflex",
.comment = "Custom keybinding 16"},
{.id = CUSTOM_17,
.name = "kb-custom-17",
.binding = "Alt+ampersand",
.comment = "Custom keybinding 17"},
{.id = CUSTOM_18,
.name = "kb-custom-18",
.binding = "Alt+asterisk",
.comment = "Custom keybinding 18"},
{.id = CUSTOM_19,
.name = "kb-custom-19",
.binding = "Alt+parenleft",
.comment = "Custom Keybinding 19"},
{.id = SELECT_ELEMENT_1,
.name = "kb-select-1",
.binding = "Super+1",
.comment = "Select row 1"},
{.id = SELECT_ELEMENT_2,
.name = "kb-select-2",
.binding = "Super+2",
.comment = "Select row 2"},
{.id = SELECT_ELEMENT_3,
.name = "kb-select-3",
.binding = "Super+3",
.comment = "Select row 3"},
{.id = SELECT_ELEMENT_4,
.name = "kb-select-4",
.binding = "Super+4",
.comment = "Select row 4"},
{.id = SELECT_ELEMENT_5,
.name = "kb-select-5",
.binding = "Super+5",
.comment = "Select row 5"},
{.id = SELECT_ELEMENT_6,
.name = "kb-select-6",
.binding = "Super+6",
.comment = "Select row 6"},
{.id = SELECT_ELEMENT_7,
.name = "kb-select-7",
.binding = "Super+7",
.comment = "Select row 7"},
{.id = SELECT_ELEMENT_8,
.name = "kb-select-8",
.binding = "Super+8",
.comment = "Select row 8"},
{.id = SELECT_ELEMENT_9,
.name = "kb-select-9",
.binding = "Super+9",
.comment = "Select row 9"},
{.id = SELECT_ELEMENT_10,
.name = "kb-select-10",
.binding = "Super+0",
.comment = "Select row 10"},
/* Mouse-aware bindings */
{ .id = SCROLL_LEFT, .scope = SCOPE_MOUSE_LISTVIEW, .name = "ml-row-left", .binding = "ScrollLeft", .comment = "Go to the previous column" },
{ .id = SCROLL_RIGHT, .scope = SCOPE_MOUSE_LISTVIEW, .name = "ml-row-right", .binding = "ScrollRight", .comment = "Go to the next column" },
{ .id = SCROLL_UP, .scope = SCOPE_MOUSE_LISTVIEW, .name = "ml-row-up", .binding = "ScrollUp", .comment = "Select previous entry" },
{ .id = SCROLL_DOWN, .scope = SCOPE_MOUSE_LISTVIEW, .name = "ml-row-down", .binding = "ScrollDown", .comment = "Select next entry" },
{.id = SCROLL_LEFT,
.scope = SCOPE_MOUSE_LISTVIEW,
.name = "ml-row-left",
.binding = "ScrollLeft",
.comment = "Go to the previous column"},
{.id = SCROLL_RIGHT,
.scope = SCOPE_MOUSE_LISTVIEW,
.name = "ml-row-right",
.binding = "ScrollRight",
.comment = "Go to the next column"},
{.id = SCROLL_UP,
.scope = SCOPE_MOUSE_LISTVIEW,
.name = "ml-row-up",
.binding = "ScrollUp",
.comment = "Select previous entry"},
{.id = SCROLL_DOWN,
.scope = SCOPE_MOUSE_LISTVIEW,
.name = "ml-row-down",
.binding = "ScrollDown",
.comment = "Select next entry"},
{ .id = SELECT_HOVERED_ENTRY, .scope = SCOPE_MOUSE_LISTVIEW_ELEMENT, .name = "me-select-entry", .binding = "MousePrimary", .comment = "Select hovered row" },
{ .id = ACCEPT_HOVERED_ENTRY, .scope = SCOPE_MOUSE_LISTVIEW_ELEMENT, .name = "me-accept-entry", .binding = "MouseDPrimary", .comment = "Accept hovered row" },
{ .id = ACCEPT_HOVERED_CUSTOM, .scope = SCOPE_MOUSE_LISTVIEW_ELEMENT, .name = "me-accept-custom", .binding = "Control+MouseDPrimary", .comment = "Accept hovered row with custom action"},
{.id = SELECT_HOVERED_ENTRY,
.scope = SCOPE_MOUSE_LISTVIEW_ELEMENT,
.name = "me-select-entry",
.binding = "MousePrimary",
.comment = "Select hovered row"},
{.id = ACCEPT_HOVERED_ENTRY,
.scope = SCOPE_MOUSE_LISTVIEW_ELEMENT,
.name = "me-accept-entry",
.binding = "MouseDPrimary",
.comment = "Accept hovered row"},
{.id = ACCEPT_HOVERED_CUSTOM,
.scope = SCOPE_MOUSE_LISTVIEW_ELEMENT,
.name = "me-accept-custom",
.binding = "Control+MouseDPrimary",
.comment = "Accept hovered row with custom action"},
};
/** Default binding of mouse button to action. */
static const gchar *mouse_default_bindings[] = {
[MOUSE_CLICK_DOWN] = "MousePrimary",
[MOUSE_CLICK_UP] = "!MousePrimary",
[MOUSE_CLICK_DOWN] = "MousePrimary",
[MOUSE_CLICK_UP] = "!MousePrimary",
[MOUSE_DCLICK_DOWN] = "MouseDPrimary",
[MOUSE_DCLICK_UP] = "!MouseDPrimary",
[MOUSE_DCLICK_UP] = "!MouseDPrimary",
};
void setup_abe ( void )
{
for ( gsize i = 0; i < G_N_ELEMENTS ( rofi_bindings ); ++i ) {
ActionBindingEntry *b = &rofi_bindings[i];
b->binding = g_strdup ( b->binding );
config_parser_add_option ( xrm_String, b->name, (void * *) &( b->binding ), b->comment );
}
}
static gboolean binding_trigger_action ( guint64 scope, G_GNUC_UNUSED gpointer target, gpointer user_data )
{
return rofi_view_trigger_action ( rofi_view_get_active (), scope, GPOINTER_TO_UINT ( user_data ) );
}
guint key_binding_get_action_from_name ( const char *name )
{
for ( gsize i = 0; i < G_N_ELEMENTS ( rofi_bindings ); ++i ) {
void setup_abe(void) {
for (gsize i = 0; i < G_N_ELEMENTS(rofi_bindings); ++i) {
ActionBindingEntry *b = &rofi_bindings[i];
if ( g_strcmp0(b->name, name) == 0 ) {
b->binding = g_strdup(b->binding);
config_parser_add_option(xrm_String, b->name, (void **)&(b->binding),
b->comment);
}
}
static gboolean binding_trigger_action(guint64 scope,
G_GNUC_UNUSED gpointer target,
gpointer user_data) {
return rofi_view_trigger_action(rofi_view_get_active(), scope,
GPOINTER_TO_UINT(user_data));
}
guint key_binding_get_action_from_name(const char *name) {
for (gsize i = 0; i < G_N_ELEMENTS(rofi_bindings); ++i) {
ActionBindingEntry *b = &rofi_bindings[i];
if (g_strcmp0(b->name, name) == 0) {
return b->id;
}
}
return UINT32_MAX;
}
gboolean parse_keys_abe(NkBindings *bindings) {
GError *error = NULL;
GString *error_msg = g_string_new("");
for (gsize i = 0; i < G_N_ELEMENTS(rofi_bindings); ++i) {
ActionBindingEntry *b = &rofi_bindings[i];
char *keystr = g_strdup(b->binding);
char *sp = NULL;
gboolean parse_keys_abe ( NkBindings *bindings )
{
GError *error = NULL;
GString *error_msg = g_string_new ( "" );
for ( gsize i = 0; i < G_N_ELEMENTS ( rofi_bindings ); ++i ) {
ActionBindingEntry *b = &rofi_bindings[i];
char *keystr = g_strdup ( b->binding );
char *sp = NULL;
// Iter over bindings.
const char *const sep = ",";
for ( char *entry = strtok_r ( keystr, sep, &sp ); entry != NULL; entry = strtok_r ( NULL, sep, &sp ) ) {
if ( !nk_bindings_add_binding ( bindings, b->scope, entry, binding_trigger_action, GUINT_TO_POINTER ( b->id ), NULL, &error ) ) {
char *str = g_markup_printf_escaped ( "Failed to set binding <i>%s</i> for: <i>%s (%s)</i>:\n\t<span size=\"smaller\" style=\"italic\">%s</span>\n",
b->binding, b->comment, b->name, error->message );
g_string_append ( error_msg, str );
g_free ( str );
g_clear_error ( &error );
}
}
g_free ( keystr );
}
if ( error_msg->len > 0 ) {
//rofi_view_error_dialog ( error_msg->str, TRUE );
rofi_add_error_message ( error_msg );
// g_string_free ( error_msg, TRUE );
return FALSE;
// Iter over bindings.
const char *const sep = ",";
for (char *entry = strtok_r(keystr, sep, &sp); entry != NULL;
entry = strtok_r(NULL, sep, &sp)) {
if (!nk_bindings_add_binding(bindings, b->scope, entry,
binding_trigger_action,
GUINT_TO_POINTER(b->id), NULL, &error)) {
char *str = g_markup_printf_escaped(
"Failed to set binding <i>%s</i> for: <i>%s (%s)</i>:\n\t<span "
"size=\"smaller\" style=\"italic\">%s</span>\n",
b->binding, b->comment, b->name, error->message);
g_string_append(error_msg, str);
g_free(str);
g_clear_error(&error);
}
}
for ( gsize i = SCOPE_MIN_FIXED; i <= SCOPE_MAX_FIXED; ++i ) {
for ( gsize j = 1; j < G_N_ELEMENTS ( mouse_default_bindings ); ++j ) {
nk_bindings_add_binding ( bindings, i, mouse_default_bindings[j], binding_trigger_action, GSIZE_TO_POINTER ( j ), NULL, NULL );
}
}
g_free(keystr);
}
if (error_msg->len > 0) {
// rofi_view_error_dialog ( error_msg->str, TRUE );
rofi_add_error_message(error_msg);
// g_string_free ( error_msg, TRUE );
return FALSE;
}
g_string_free ( error_msg, TRUE );
return TRUE;
for (gsize i = SCOPE_MIN_FIXED; i <= SCOPE_MAX_FIXED; ++i) {
for (gsize j = 1; j < G_N_ELEMENTS(mouse_default_bindings); ++j) {
nk_bindings_add_binding(bindings, i, mouse_default_bindings[j],
binding_trigger_action, GSIZE_TO_POINTER(j), NULL,
NULL);
}
}
g_string_free(error_msg, TRUE);
return TRUE;
}

View file

@ -25,12 +25,12 @@
*
*/
#include <stdio.h>
#include <glib.h>
#include <string.h>
#include "mode.h"
#include "rofi.h"
#include "xrmoptions.h"
#include "mode.h"
#include <glib.h>
#include <stdio.h>
#include <string.h>
// This one should only be in mode implementations.
#include "mode-private.h"
@ -39,153 +39,141 @@
* @{
*/
int mode_init ( Mode *mode )
{
g_return_val_if_fail ( mode != NULL, FALSE );
g_return_val_if_fail ( mode->_init != NULL, FALSE );
return mode->_init ( mode );
int mode_init(Mode *mode) {
g_return_val_if_fail(mode != NULL, FALSE);
g_return_val_if_fail(mode->_init != NULL, FALSE);
return mode->_init(mode);
}
void mode_destroy ( Mode *mode )
{
g_assert ( mode != NULL );
g_assert ( mode->_destroy != NULL );
mode->_destroy ( mode );
void mode_destroy(Mode *mode) {
g_assert(mode != NULL);
g_assert(mode->_destroy != NULL);
mode->_destroy(mode);
}
unsigned int mode_get_num_entries ( const Mode *mode )
{
g_assert ( mode != NULL );
g_assert ( mode->_get_num_entries != NULL );
return mode->_get_num_entries ( mode );
unsigned int mode_get_num_entries(const Mode *mode) {
g_assert(mode != NULL);
g_assert(mode->_get_num_entries != NULL);
return mode->_get_num_entries(mode);
}
char * mode_get_display_value ( const Mode *mode, unsigned int selected_line, int *state, GList **attribute_list, int get_entry )
{
g_assert ( mode != NULL );
g_assert ( state != NULL );
g_assert ( mode->_get_display_value != NULL );
char *mode_get_display_value(const Mode *mode, unsigned int selected_line,
int *state, GList **attribute_list,
int get_entry) {
g_assert(mode != NULL);
g_assert(state != NULL);
g_assert(mode->_get_display_value != NULL);
return mode->_get_display_value ( mode, selected_line, state, attribute_list, get_entry );
return mode->_get_display_value(mode, selected_line, state, attribute_list,
get_entry);
}
cairo_surface_t * mode_get_icon ( const Mode *mode, unsigned int selected_line, int height )
{
g_assert ( mode != NULL );
cairo_surface_t *mode_get_icon(const Mode *mode, unsigned int selected_line,
int height) {
g_assert(mode != NULL);
if ( mode->_get_icon != NULL ) {
return mode->_get_icon ( mode, selected_line, height );
}
else {
return NULL;
}
if (mode->_get_icon != NULL) {
return mode->_get_icon(mode, selected_line, height);
}
return NULL;
}
char * mode_get_completion ( const Mode *mode, unsigned int selected_line )
{
g_assert ( mode != NULL );
if ( mode->_get_completion != NULL ) {
return mode->_get_completion ( mode, selected_line );
}
else {
int state;
g_assert ( mode->_get_display_value != NULL );
return mode->_get_display_value ( mode, selected_line, &state, NULL, TRUE );
}
char *mode_get_completion(const Mode *mode, unsigned int selected_line) {
g_assert(mode != NULL);
if (mode->_get_completion != NULL) {
return mode->_get_completion(mode, selected_line);
}
int state;
g_assert(mode->_get_display_value != NULL);
return mode->_get_display_value(mode, selected_line, &state, NULL, TRUE);
}
ModeMode mode_result ( Mode *mode, int menu_retv, char **input, unsigned int selected_line )
{
if ( menu_retv & MENU_NEXT ) {
return NEXT_DIALOG;
}
else if ( menu_retv & MENU_PREVIOUS ) {
return PREVIOUS_DIALOG;
}
else if ( menu_retv & MENU_QUICK_SWITCH ) {
return menu_retv & MENU_LOWER_MASK;
}
ModeMode mode_result(Mode *mode, int menu_retv, char **input,
unsigned int selected_line) {
if (menu_retv & MENU_NEXT) {
return NEXT_DIALOG;
}
if (menu_retv & MENU_PREVIOUS) {
return PREVIOUS_DIALOG;
}
if (menu_retv & MENU_QUICK_SWITCH) {
return menu_retv & MENU_LOWER_MASK;
}
g_assert ( mode != NULL );
g_assert ( mode->_result != NULL );
g_assert ( input != NULL );
g_assert(mode != NULL);
g_assert(mode->_result != NULL);
g_assert(input != NULL);
return mode->_result ( mode, menu_retv, input, selected_line );
return mode->_result(mode, menu_retv, input, selected_line);
}
int mode_token_match ( const Mode *mode, rofi_int_matcher **tokens, unsigned int selected_line )
{
g_assert ( mode != NULL );
g_assert ( mode->_token_match != NULL );
return mode->_token_match ( mode, tokens, selected_line );
int mode_token_match(const Mode *mode, rofi_int_matcher **tokens,
unsigned int selected_line) {
g_assert(mode != NULL);
g_assert(mode->_token_match != NULL);
return mode->_token_match(mode, tokens, selected_line);
}
const char *mode_get_name ( const Mode *mode )
{
g_assert ( mode != NULL );
return mode->name;
const char *mode_get_name(const Mode *mode) {
g_assert(mode != NULL);
return mode->name;
}
void mode_free ( Mode **mode )
{
g_assert ( mode != NULL );
g_assert ( ( *mode ) != NULL );
if ( ( *mode )->free != NULL ) {
( *mode )->free ( *mode );
}
( *mode ) = NULL;
void mode_free(Mode **mode) {
g_assert(mode != NULL);
g_assert((*mode) != NULL);
if ((*mode)->free != NULL) {
(*mode)->free(*mode);
}
(*mode) = NULL;
}
void *mode_get_private_data ( const Mode *mode )
{
g_assert ( mode != NULL );
return mode->private_data;
void *mode_get_private_data(const Mode *mode) {
g_assert(mode != NULL);
return mode->private_data;
}
void mode_set_private_data ( Mode *mode, void *pd )
{
g_assert ( mode != NULL );
if ( pd != NULL ) {
g_assert ( mode->private_data == NULL );
}
mode->private_data = pd;
void mode_set_private_data(Mode *mode, void *pd) {
g_assert(mode != NULL);
if (pd != NULL) {
g_assert(mode->private_data == NULL);
}
mode->private_data = pd;
}
const char *mode_get_display_name ( const Mode *mode )
{
const char *mode_get_display_name(const Mode *mode) {
/** Find the widget */
ThemeWidget *wid = rofi_config_find_widget ( mode->name, NULL, TRUE );
if ( wid ) {
ThemeWidget *wid = rofi_config_find_widget(mode->name, NULL, TRUE);
if (wid) {
/** Check string property */
Property *p = rofi_theme_find_property ( wid, P_STRING, "display-name", TRUE );
if ( p != NULL && p->type == P_STRING ) {
Property *p = rofi_theme_find_property(wid, P_STRING, "display-name", TRUE);
if (p != NULL && p->type == P_STRING) {
return p->value.s;
}
}
if ( mode->display_name != NULL ) {
if (mode->display_name != NULL) {
return mode->display_name;
}
return mode->name;
}
return mode->name;
}
void mode_set_config ( Mode *mode )
{
snprintf ( mode->cfg_name_key, 128, "display-%s", mode->name );
config_parser_add_option ( xrm_String, mode->cfg_name_key, (void * *) &( mode->display_name ), "The display name of this browser" );
void mode_set_config(Mode *mode) {
snprintf(mode->cfg_name_key, 128, "display-%s", mode->name);
config_parser_add_option(xrm_String, mode->cfg_name_key,
(void **)&(mode->display_name),
"The display name of this browser");
}
char * mode_preprocess_input ( Mode *mode, const char *input )
{
if ( mode->_preprocess_input ) {
return mode->_preprocess_input ( mode, input );
}
return g_strdup ( input );
char *mode_preprocess_input(Mode *mode, const char *input) {
if (mode->_preprocess_input) {
return mode->_preprocess_input(mode, input);
}
return g_strdup(input);
}
char *mode_get_message ( const Mode *mode )
{
if ( mode->_get_message ) {
return mode->_get_message ( mode );
}
return NULL;
char *mode_get_message(const Mode *mode) {
if (mode->_get_message) {
return mode->_get_message(mode);
}
return NULL;
}
/**@}*/

View file

@ -26,63 +26,61 @@
*/
/** The log domain of this Helper. */
#define G_LOG_DOMAIN "Helpers.IconFetcher"
#define G_LOG_DOMAIN "Helpers.IconFetcher"
#include "config.h"
#include <stdlib.h>
#include <config.h>
#include <xcb/xproto.h>
#include "helper.h"
#include "rofi-icon-fetcher.h"
#include "rofi-types.h"
#include "helper.h"
#include "settings.h"
#include "xcb.h"
#include "keyb.h"
#include "view.h"
#include "xcb.h"
#include "nkutils-xdg-theme.h"
#include "nkutils-enum.h"
#include "nkutils-xdg-theme.h"
#include <stdint.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "helper.h"
#include <gdk-pixbuf/gdk-pixbuf.h>
typedef struct
{
// Context for icon-themes.
NkXdgThemeContext *xdg_context;
typedef struct {
// Context for icon-themes.
NkXdgThemeContext *xdg_context;
// On name.
GHashTable *icon_cache;
// On uid.
GHashTable *icon_cache_uid;
// On name.
GHashTable *icon_cache;
// On uid.
GHashTable *icon_cache_uid;
// list extensions
GList *supported_extensions;
uint32_t last_uid;
// list extensions
GList *supported_extensions;
uint32_t last_uid;
} IconFetcher;
typedef struct
{
char *name;
GList *sizes;
typedef struct {
char *name;
GList *sizes;
} IconFetcherNameEntry;
typedef struct
{
thread_state state;
typedef struct {
thread_state state;
GCond *cond;
GMutex *mutex;
unsigned int *acount;
GCond *cond;
GMutex *mutex;
unsigned int *acount;
uint32_t uid;
int wsize;
int hsize;
cairo_surface_t *surface;
uint32_t uid;
int wsize;
int hsize;
cairo_surface_t *surface;
IconFetcherNameEntry *entry;
IconFetcherNameEntry *entry;
} IconFetcherEntry;
/**
@ -90,77 +88,76 @@ typedef struct
*/
IconFetcher *rofi_icon_fetcher_data = NULL;
static void rofi_icon_fetch_entry_free ( gpointer data )
{
IconFetcherNameEntry *entry = (IconFetcherNameEntry *) data;
static void rofi_icon_fetch_entry_free(gpointer data) {
IconFetcherNameEntry *entry = (IconFetcherNameEntry *)data;
// Free name/key.
g_free ( entry->name );
// Free name/key.
g_free(entry->name);
for ( GList *iter = g_list_first ( entry->sizes ); iter; iter = g_list_next ( iter ) ) {
IconFetcherEntry *sentry = (IconFetcherEntry *) ( iter->data );
for (GList *iter = g_list_first(entry->sizes); iter;
iter = g_list_next(iter)) {
IconFetcherEntry *sentry = (IconFetcherEntry *)(iter->data);
cairo_surface_destroy ( sentry->surface );
g_free ( sentry );
}
cairo_surface_destroy(sentry->surface);
g_free(sentry);
}
g_list_free ( entry->sizes );
g_free ( entry );
g_list_free(entry->sizes);
g_free(entry);
}
void rofi_icon_fetcher_init ( void )
{
g_assert ( rofi_icon_fetcher_data == NULL );
void rofi_icon_fetcher_init(void) {
g_assert(rofi_icon_fetcher_data == NULL);
static const gchar * const icon_fallback_themes[] = {
"Adwaita",
"gnome",
NULL
};
const char *themes[2] = { config.icon_theme, NULL };
static const gchar *const icon_fallback_themes[] = {"Adwaita", "gnome", NULL};
const char *themes[2] = {config.icon_theme, NULL};
rofi_icon_fetcher_data = g_malloc0 ( sizeof ( IconFetcher ) );
rofi_icon_fetcher_data = g_malloc0(sizeof(IconFetcher));
rofi_icon_fetcher_data->xdg_context = nk_xdg_theme_context_new ( icon_fallback_themes, NULL );
nk_xdg_theme_preload_themes_icon ( rofi_icon_fetcher_data->xdg_context, themes );
rofi_icon_fetcher_data->xdg_context =
nk_xdg_theme_context_new(icon_fallback_themes, NULL);
nk_xdg_theme_preload_themes_icon(rofi_icon_fetcher_data->xdg_context, themes);
rofi_icon_fetcher_data->icon_cache_uid = g_hash_table_new ( g_direct_hash, g_direct_equal );
rofi_icon_fetcher_data->icon_cache = g_hash_table_new_full ( g_str_hash, g_str_equal, NULL, rofi_icon_fetch_entry_free );
rofi_icon_fetcher_data->icon_cache_uid =
g_hash_table_new(g_direct_hash, g_direct_equal);
rofi_icon_fetcher_data->icon_cache = g_hash_table_new_full(
g_str_hash, g_str_equal, NULL, rofi_icon_fetch_entry_free);
GSList *l = gdk_pixbuf_get_formats ();
for ( GSList *li = l; li != NULL; li = g_slist_next ( li ) ) {
gchar **exts = gdk_pixbuf_format_get_extensions ( (GdkPixbufFormat *) li->data );
GSList *l = gdk_pixbuf_get_formats();
for (GSList *li = l; li != NULL; li = g_slist_next(li)) {
gchar **exts =
gdk_pixbuf_format_get_extensions((GdkPixbufFormat *)li->data);
for ( unsigned int i = 0; exts && exts[i]; i++ ) {
rofi_icon_fetcher_data->supported_extensions = g_list_append ( rofi_icon_fetcher_data->supported_extensions, exts[i] );
g_info ( "Add image extension: %s", exts[i] );
exts[i] = NULL;
}
g_free ( exts );
}
g_slist_free ( l );
}
static void free_wrapper ( gpointer data, G_GNUC_UNUSED gpointer user_data )
{
g_free ( data ) ;
}
void rofi_icon_fetcher_destroy ( void )
{
if ( rofi_icon_fetcher_data == NULL ) {
return;
for (unsigned int i = 0; exts && exts[i]; i++) {
rofi_icon_fetcher_data->supported_extensions =
g_list_append(rofi_icon_fetcher_data->supported_extensions, exts[i]);
g_info("Add image extension: %s", exts[i]);
exts[i] = NULL;
}
nk_xdg_theme_context_free ( rofi_icon_fetcher_data->xdg_context );
g_free(exts);
}
g_slist_free(l);
}
g_hash_table_unref ( rofi_icon_fetcher_data->icon_cache_uid );
g_hash_table_unref ( rofi_icon_fetcher_data->icon_cache );
static void free_wrapper(gpointer data, G_GNUC_UNUSED gpointer user_data) {
g_free(data);
}
g_list_foreach ( rofi_icon_fetcher_data->supported_extensions, free_wrapper, NULL );
g_list_free ( rofi_icon_fetcher_data->supported_extensions );
g_free ( rofi_icon_fetcher_data );
void rofi_icon_fetcher_destroy(void) {
if (rofi_icon_fetcher_data == NULL) {
return;
}
nk_xdg_theme_context_free(rofi_icon_fetcher_data->xdg_context);
g_hash_table_unref(rofi_icon_fetcher_data->icon_cache_uid);
g_hash_table_unref(rofi_icon_fetcher_data->icon_cache);
g_list_foreach(rofi_icon_fetcher_data->supported_extensions, free_wrapper,
NULL);
g_list_free(rofi_icon_fetcher_data->supported_extensions);
g_free(rofi_icon_fetcher_data);
}
/*
@ -171,255 +168,256 @@ void rofi_icon_fetcher_destroy ( void )
*/
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
/** Location of red byte */
#define RED_BYTE 2
#define RED_BYTE 2
/** Location of green byte */
#define GREEN_BYTE 1
#define GREEN_BYTE 1
/** Location of blue byte */
#define BLUE_BYTE 0
#define BLUE_BYTE 0
/** Location of alpha byte */
#define ALPHA_BYTE 3
#define ALPHA_BYTE 3
#else
/** Location of red byte */
#define RED_BYTE 1
#define RED_BYTE 1
/** Location of green byte */
#define GREEN_BYTE 2
#define GREEN_BYTE 2
/** Location of blue byte */
#define BLUE_BYTE 3
#define BLUE_BYTE 3
/** Location of alpha byte */
#define ALPHA_BYTE 0
#define ALPHA_BYTE 0
#endif
static inline guchar alpha_mult ( guchar c, guchar a )
{
guint16 t;
switch ( a )
{
case 0xff:
return c;
case 0x00:
return 0x00;
default:
t = c * a + 0x7f;
return ( ( t >> 8 ) + t ) >> 8;
}
static inline guchar alpha_mult(guchar c, guchar a) {
guint16 t;
switch (a) {
case 0xff:
return c;
case 0x00:
return 0x00;
default:
t = c * a + 0x7f;
return ((t >> 8) + t) >> 8;
}
}
static cairo_surface_t * rofi_icon_fetcher_get_surface_from_pixbuf ( GdkPixbuf
*pixbuf )
{
gint width, height;
const guchar *pixels;
gint stride;
gboolean alpha;
static cairo_surface_t *
rofi_icon_fetcher_get_surface_from_pixbuf(GdkPixbuf *pixbuf) {
gint width, height;
const guchar *pixels;
gint stride;
gboolean alpha;
if ( pixbuf == NULL ) {
return NULL;
}
width = gdk_pixbuf_get_width ( pixbuf );
height = gdk_pixbuf_get_height ( pixbuf );
pixels = gdk_pixbuf_read_pixels ( pixbuf );
stride = gdk_pixbuf_get_rowstride ( pixbuf );
alpha = gdk_pixbuf_get_has_alpha ( pixbuf );
cairo_surface_t *surface = NULL;
gint cstride;
guint lo, o;
guchar a = 0xff;
const guchar *pixels_end, *line;
guchar *cpixels;
pixels_end = pixels + height * stride;
o = alpha ? 4 : 3;
lo = o * width;
surface = cairo_image_surface_create ( CAIRO_FORMAT_ARGB32, width, height );
cpixels = cairo_image_surface_get_data ( surface );
cstride = cairo_image_surface_get_stride ( surface );
cairo_surface_flush ( surface );
while ( pixels < pixels_end ) {
line = pixels;
const guchar *line_end = line + lo;
guchar *cline = cpixels;
while ( line < line_end ) {
if ( alpha ) {
a = line[3];
}
cline[RED_BYTE] = alpha_mult ( line[0], a );
cline[GREEN_BYTE] = alpha_mult ( line[1], a );
cline[BLUE_BYTE] = alpha_mult ( line[2], a );
cline[ALPHA_BYTE] = a;
line += o;
cline += 4;
}
pixels += stride;
cpixels += cstride;
}
cairo_surface_mark_dirty ( surface );
cairo_surface_flush ( surface );
return surface;
}
gboolean rofi_icon_fetcher_file_is_image ( const char * const path )
{
if ( path == NULL ) {
return FALSE;
}
const char *suf = strrchr ( path, '.' );
if ( suf == NULL ) {
return FALSE;
}
suf++;
for ( GList *iter = rofi_icon_fetcher_data->supported_extensions; iter != NULL; iter = g_list_next ( iter ) ) {
if ( g_ascii_strcasecmp ( iter->data, suf ) == 0 ) {
return TRUE;
}
}
return FALSE;
}
static void rofi_icon_fetcher_worker ( thread_state *sdata, G_GNUC_UNUSED gpointer user_data )
{
g_debug ( "starting up icon fetching thread." );
// as long as dr->icon is updated atomicly.. (is a pointer write atomic?)
// this should be fine running in another thread.
IconFetcherEntry *sentry = (IconFetcherEntry *) sdata;
const gchar *themes[] = {
config.icon_theme,
NULL
};
const gchar *icon_path;
gchar *icon_path_ = NULL;
if ( g_path_is_absolute ( sentry->entry->name ) ) {
icon_path = sentry->entry->name;
}
else {
icon_path = icon_path_ = nk_xdg_theme_get_icon ( rofi_icon_fetcher_data->xdg_context, themes, NULL, sentry->entry->name, MIN(sentry->wsize,sentry->hsize), 1, TRUE );
if ( icon_path_ == NULL ) {
g_debug ( "failed to get icon %s(%dx%d): n/a", sentry->entry->name, sentry->wsize, sentry->hsize );
const char *ext = g_strrstr(sentry->entry->name, ".");
if ( ext ) {
printf("%s %s\r\n", sentry->entry->name, ext);
icon_path = helper_get_theme_path ( sentry->entry->name, ext );
}
if ( icon_path == NULL ) {
return;
}
}
else{
g_debug ( "found icon %s(%dx%d): %s", sentry->entry->name, sentry->wsize, sentry->hsize, icon_path );
}
}
cairo_surface_t *icon_surf = NULL;
const char *suf = strrchr ( icon_path, '.' );
if ( suf == NULL ) {
return;
}
GError *error = NULL;
GdkPixbuf *pb = gdk_pixbuf_new_from_file_at_scale ( icon_path, sentry->wsize, sentry->hsize, TRUE, &error );
if ( error != NULL ) {
g_warning ( "Failed to load image: %s", error->message );
g_error_free ( error );
if ( pb ) {
g_object_unref ( pb );
}
}
else {
icon_surf = rofi_icon_fetcher_get_surface_from_pixbuf ( pb );
g_object_unref ( pb );
}
sentry->surface = icon_surf;
g_free ( icon_path_ );
rofi_view_reload ();
}
uint32_t rofi_icon_fetcher_query_advanced ( const char *name, const int wsize, const int hsize )
{
g_debug ( "Query: %s(%dx%d)", name, wsize, hsize );
IconFetcherNameEntry *entry = g_hash_table_lookup ( rofi_icon_fetcher_data->icon_cache, name );
if ( entry == NULL ) {
entry = g_new0 ( IconFetcherNameEntry, 1 );
entry->name = g_strdup ( name );
g_hash_table_insert ( rofi_icon_fetcher_data->icon_cache, entry->name, entry );
}
IconFetcherEntry *sentry;
for ( GList *iter = g_list_first ( entry->sizes ); iter; iter = g_list_next ( iter ) ) {
sentry = iter->data;
if ( sentry->wsize == wsize && sentry->hsize == hsize ) {
return sentry->uid;
}
}
// Not found.
sentry = g_new0 ( IconFetcherEntry, 1 );
sentry->uid = ++( rofi_icon_fetcher_data->last_uid );
sentry->wsize = wsize;
sentry->hsize = hsize;
sentry->entry = entry;
sentry->surface = NULL;
entry->sizes = g_list_prepend ( entry->sizes, sentry );
g_hash_table_insert ( rofi_icon_fetcher_data->icon_cache_uid, GINT_TO_POINTER ( sentry->uid ), sentry );
// Push into fetching queue.
sentry->state.callback = rofi_icon_fetcher_worker;
g_thread_pool_push ( tpool, sentry, NULL );
return sentry->uid;
}
uint32_t rofi_icon_fetcher_query ( const char *name, const int size )
{
g_debug ( "Query: %s(%d)", name, size );
IconFetcherNameEntry *entry = g_hash_table_lookup ( rofi_icon_fetcher_data->icon_cache, name );
if ( entry == NULL ) {
entry = g_new0 ( IconFetcherNameEntry, 1 );
entry->name = g_strdup ( name );
g_hash_table_insert ( rofi_icon_fetcher_data->icon_cache, entry->name, entry );
}
IconFetcherEntry *sentry;
for ( GList *iter = g_list_first ( entry->sizes ); iter; iter = g_list_next ( iter ) ) {
sentry = iter->data;
if ( sentry->wsize == size && sentry->hsize == size ) {
return sentry->uid;
}
}
// Not found.
sentry = g_new0 ( IconFetcherEntry, 1 );
sentry->uid = ++( rofi_icon_fetcher_data->last_uid );
sentry->wsize = size;
sentry->hsize = size;
sentry->entry = entry;
sentry->surface = NULL;
entry->sizes = g_list_prepend ( entry->sizes, sentry );
g_hash_table_insert ( rofi_icon_fetcher_data->icon_cache_uid, GINT_TO_POINTER ( sentry->uid ), sentry );
// Push into fetching queue.
sentry->state.callback = rofi_icon_fetcher_worker;
g_thread_pool_push ( tpool, sentry, NULL );
return sentry->uid;
}
cairo_surface_t * rofi_icon_fetcher_get ( const uint32_t uid )
{
IconFetcherEntry *sentry = g_hash_table_lookup ( rofi_icon_fetcher_data->icon_cache_uid, GINT_TO_POINTER ( uid ) );
if ( sentry ) {
return sentry->surface;
}
if (pixbuf == NULL) {
return NULL;
}
width = gdk_pixbuf_get_width(pixbuf);
height = gdk_pixbuf_get_height(pixbuf);
pixels = gdk_pixbuf_read_pixels(pixbuf);
stride = gdk_pixbuf_get_rowstride(pixbuf);
alpha = gdk_pixbuf_get_has_alpha(pixbuf);
cairo_surface_t *surface = NULL;
gint cstride;
guint lo, o;
guchar a = 0xff;
const guchar *pixels_end, *line;
guchar *cpixels;
pixels_end = pixels + height * stride;
o = alpha ? 4 : 3;
lo = o * width;
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
cpixels = cairo_image_surface_get_data(surface);
cstride = cairo_image_surface_get_stride(surface);
cairo_surface_flush(surface);
while (pixels < pixels_end) {
line = pixels;
const guchar *line_end = line + lo;
guchar *cline = cpixels;
while (line < line_end) {
if (alpha) {
a = line[3];
}
cline[RED_BYTE] = alpha_mult(line[0], a);
cline[GREEN_BYTE] = alpha_mult(line[1], a);
cline[BLUE_BYTE] = alpha_mult(line[2], a);
cline[ALPHA_BYTE] = a;
line += o;
cline += 4;
}
pixels += stride;
cpixels += cstride;
}
cairo_surface_mark_dirty(surface);
cairo_surface_flush(surface);
return surface;
}
gboolean rofi_icon_fetcher_file_is_image(const char *const path) {
if (path == NULL) {
return FALSE;
}
const char *suf = strrchr(path, '.');
if (suf == NULL) {
return FALSE;
}
suf++;
for (GList *iter = rofi_icon_fetcher_data->supported_extensions; iter != NULL;
iter = g_list_next(iter)) {
if (g_ascii_strcasecmp(iter->data, suf) == 0) {
return TRUE;
}
}
return FALSE;
}
static void rofi_icon_fetcher_worker(thread_state *sdata,
G_GNUC_UNUSED gpointer user_data) {
g_debug("starting up icon fetching thread.");
// as long as dr->icon is updated atomicly.. (is a pointer write atomic?)
// this should be fine running in another thread.
IconFetcherEntry *sentry = (IconFetcherEntry *)sdata;
const gchar *themes[] = {config.icon_theme, NULL};
const gchar *icon_path;
gchar *icon_path_ = NULL;
if (g_path_is_absolute(sentry->entry->name)) {
icon_path = sentry->entry->name;
} else {
icon_path = icon_path_ = nk_xdg_theme_get_icon(
rofi_icon_fetcher_data->xdg_context, themes, NULL, sentry->entry->name,
MIN(sentry->wsize, sentry->hsize), 1, TRUE);
if (icon_path_ == NULL) {
g_debug("failed to get icon %s(%dx%d): n/a", sentry->entry->name,
sentry->wsize, sentry->hsize);
const char *ext = g_strrstr(sentry->entry->name, ".");
if (ext) {
printf("%s %s\r\n", sentry->entry->name, ext);
icon_path = helper_get_theme_path(sentry->entry->name, ext);
}
if (icon_path == NULL) {
return;
}
} else {
g_debug("found icon %s(%dx%d): %s", sentry->entry->name, sentry->wsize,
sentry->hsize, icon_path);
}
}
cairo_surface_t *icon_surf = NULL;
const char *suf = strrchr(icon_path, '.');
if (suf == NULL) {
return;
}
GError *error = NULL;
GdkPixbuf *pb = gdk_pixbuf_new_from_file_at_scale(
icon_path, sentry->wsize, sentry->hsize, TRUE, &error);
if (error != NULL) {
g_warning("Failed to load image: %s", error->message);
g_error_free(error);
if (pb) {
g_object_unref(pb);
}
} else {
icon_surf = rofi_icon_fetcher_get_surface_from_pixbuf(pb);
g_object_unref(pb);
}
sentry->surface = icon_surf;
g_free(icon_path_);
rofi_view_reload();
}
uint32_t rofi_icon_fetcher_query_advanced(const char *name, const int wsize,
const int hsize) {
g_debug("Query: %s(%dx%d)", name, wsize, hsize);
IconFetcherNameEntry *entry =
g_hash_table_lookup(rofi_icon_fetcher_data->icon_cache, name);
if (entry == NULL) {
entry = g_new0(IconFetcherNameEntry, 1);
entry->name = g_strdup(name);
g_hash_table_insert(rofi_icon_fetcher_data->icon_cache, entry->name, entry);
}
IconFetcherEntry *sentry;
for (GList *iter = g_list_first(entry->sizes); iter;
iter = g_list_next(iter)) {
sentry = iter->data;
if (sentry->wsize == wsize && sentry->hsize == hsize) {
return sentry->uid;
}
}
// Not found.
sentry = g_new0(IconFetcherEntry, 1);
sentry->uid = ++(rofi_icon_fetcher_data->last_uid);
sentry->wsize = wsize;
sentry->hsize = hsize;
sentry->entry = entry;
sentry->surface = NULL;
entry->sizes = g_list_prepend(entry->sizes, sentry);
g_hash_table_insert(rofi_icon_fetcher_data->icon_cache_uid,
GINT_TO_POINTER(sentry->uid), sentry);
// Push into fetching queue.
sentry->state.callback = rofi_icon_fetcher_worker;
g_thread_pool_push(tpool, sentry, NULL);
return sentry->uid;
}
uint32_t rofi_icon_fetcher_query(const char *name, const int size) {
g_debug("Query: %s(%d)", name, size);
IconFetcherNameEntry *entry =
g_hash_table_lookup(rofi_icon_fetcher_data->icon_cache, name);
if (entry == NULL) {
entry = g_new0(IconFetcherNameEntry, 1);
entry->name = g_strdup(name);
g_hash_table_insert(rofi_icon_fetcher_data->icon_cache, entry->name, entry);
}
IconFetcherEntry *sentry;
for (GList *iter = g_list_first(entry->sizes); iter;
iter = g_list_next(iter)) {
sentry = iter->data;
if (sentry->wsize == size && sentry->hsize == size) {
return sentry->uid;
}
}
// Not found.
sentry = g_new0(IconFetcherEntry, 1);
sentry->uid = ++(rofi_icon_fetcher_data->last_uid);
sentry->wsize = size;
sentry->hsize = size;
sentry->entry = entry;
sentry->surface = NULL;
entry->sizes = g_list_prepend(entry->sizes, sentry);
g_hash_table_insert(rofi_icon_fetcher_data->icon_cache_uid,
GINT_TO_POINTER(sentry->uid), sentry);
// Push into fetching queue.
sentry->state.callback = rofi_icon_fetcher_worker;
g_thread_pool_push(tpool, sentry, NULL);
return sentry->uid;
}
cairo_surface_t *rofi_icon_fetcher_get(const uint32_t uid) {
IconFetcherEntry *sentry = g_hash_table_lookup(
rofi_icon_fetcher_data->icon_cache_uid, GINT_TO_POINTER(uid));
if (sentry) {
return sentry->surface;
}
return NULL;
}

View file

@ -3,7 +3,7 @@
/**
* Name of the property type
*/
const char * const PropertyTypeName[P_NUM_TYPES] = {
const char *const PropertyTypeName[P_NUM_TYPES] = {
/** Integer */
"Integer",
/** Double */

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -26,12 +26,12 @@
*/
/** Log domain used by timings.*/
#define G_LOG_DOMAIN "Timings"
#define G_LOG_DOMAIN "Timings"
#include "config.h"
#include <stdio.h>
#include "rofi.h"
#include "timings.h"
#include "config.h"
#include "rofi.h"
#include <stdio.h>
/**
* Timer used to calculate time stamps.
*/
@ -41,24 +41,23 @@ GTimer *global_timer = NULL;
*/
double global_timer_last = 0.0;
void rofi_timings_init ( void )
{
global_timer = g_timer_new ();
double now = g_timer_elapsed ( global_timer, NULL );
g_debug ( "%4.6f (%2.6f): Started", now, 0.0 );
void rofi_timings_init(void) {
global_timer = g_timer_new();
double now = g_timer_elapsed(global_timer, NULL);
g_debug("%4.6f (%2.6f): Started", now, 0.0);
}
void rofi_timings_tick ( const char *file, char const *str, int line, char const *msg )
{
double now = g_timer_elapsed ( global_timer, NULL );
void rofi_timings_tick(const char *file, char const *str, int line,
char const *msg) {
double now = g_timer_elapsed(global_timer, NULL);
g_debug ( "%4.6f (%2.6f): %s:%s:%-3d %s", now, now - global_timer_last, file, str, line, msg );
global_timer_last = now;
g_debug("%4.6f (%2.6f): %s:%s:%-3d %s", now, now - global_timer_last, file,
str, line, msg);
global_timer_last = now;
}
void rofi_timings_quit ( void )
{
double now = g_timer_elapsed ( global_timer, NULL );
g_debug ( "%4.6f (%2.6f): Stopped", now, 0.0 );
g_timer_destroy ( global_timer );
void rofi_timings_quit(void) {
double now = g_timer_elapsed(global_timer, NULL);
g_debug("%4.6f (%2.6f): Stopped", now, 0.0);
g_timer_destroy(global_timer);
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -26,38 +26,38 @@
*/
/** The Rofi View log domain */
#define G_LOG_DOMAIN "View"
#define G_LOG_DOMAIN "View"
#include <config.h>
#include <errno.h>
#include <locale.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdint.h>
#include <signal.h>
#include <errno.h>
#include <time.h>
#include <locale.h>
#include <unistd.h>
#include <cairo.h>
/** Indicated we understand the startup notification api is not yet stable.*/
#define SN_API_NOT_YET_FROZEN
#include <libsn/sn.h>
#include "rofi.h"
#include <libsn/sn.h>
#include "timings.h"
#include "settings.h"
#include "timings.h"
#include "mode.h"
#include "display.h"
#include "helper.h"
#include "helper-theme.h"
#include "xrmoptions.h"
#include "dialogs/dialogs.h"
#include "display.h"
#include "helper-theme.h"
#include "helper.h"
#include "mode.h"
#include "xrmoptions.h"
#include "view.h"
#include "view-internal.h"
#include "view.h"
#include "theme.h"
@ -67,218 +67,198 @@
*
* Update the state of the view. This involves filter state.
*/
static void wayland_rofi_view_update ( RofiViewState *state, gboolean qr );
static void wayland_rofi_view_update(RofiViewState *state, gboolean qr);
static void wayland_rofi_view_maybe_update ( RofiViewState *state );
static void wayland_rofi_view_maybe_update(RofiViewState *state);
/**
* Structure holding some state
*/
static struct
{
/** Main flags */
MenuFlags flags;
/** timeout for reloading */
guint idle_timeout;
/** debug counter for redraws */
unsigned long long count;
/** redraw idle time. */
guint repaint_source;
/** Window fullscreen */
gboolean fullscreen;
static struct {
/** Main flags */
MenuFlags flags;
/** timeout for reloading */
guint idle_timeout;
/** debug counter for redraws */
unsigned long long count;
/** redraw idle time. */
guint repaint_source;
/** Window fullscreen */
gboolean fullscreen;
} WlState = {
.flags = MENU_NORMAL,
.idle_timeout = 0,
.count = 0L,
.flags = MENU_NORMAL,
.idle_timeout = 0,
.count = 0L,
.repaint_source = 0,
.fullscreen = FALSE,
.fullscreen = FALSE,
};
static void wayland_rofi_view_get_current_monitor ( int *width, int *height )
{
display_get_surface_dimensions ( width, height );
static void wayland_rofi_view_get_current_monitor(int *width, int *height) {
display_get_surface_dimensions(width, height);
}
/**
* Stores a screenshot of Rofi at that point in time.
*/
static void wayland_rofi_view_capture_screenshot ( void )
{
}
static void wayland_rofi_view_capture_screenshot(void) {}
static gboolean wayland_rofi_view_repaint ( G_GNUC_UNUSED void * data )
{
RofiViewState * state = rofi_view_get_active ();
if ( state ) {
// Repaint the view (if needed).
// After a resize the edit_pixmap surface might not contain anything anymore.
// If we already re-painted, this does nothing.
wayland_rofi_view_maybe_update ( state );
WlState.repaint_source = 0;
}
return G_SOURCE_REMOVE;
static gboolean wayland_rofi_view_repaint(G_GNUC_UNUSED void *data) {
RofiViewState *state = rofi_view_get_active();
if (state) {
// Repaint the view (if needed).
// After a resize the edit_pixmap surface might not contain anything
// anymore. If we already re-painted, this does nothing.
wayland_rofi_view_maybe_update(state);
WlState.repaint_source = 0;
}
return G_SOURCE_REMOVE;
}
static const int loc_transtable[9] = {
WL_CENTER,
WL_NORTH | WL_WEST,
WL_NORTH,
WL_NORTH | WL_EAST,
WL_EAST,
WL_SOUTH | WL_EAST,
WL_SOUTH,
WL_SOUTH | WL_WEST,
WL_WEST
};
WL_CENTER, WL_NORTH | WL_WEST, WL_NORTH, WL_NORTH | WL_EAST,
WL_EAST, WL_SOUTH | WL_EAST, WL_SOUTH, WL_SOUTH | WL_WEST,
WL_WEST};
static void wayland_rofi_view_calculate_window_position ( RofiViewState *state )
{
static void wayland_rofi_view_calculate_window_position(RofiViewState *state) {}
static int rofi_get_location(RofiViewState *state) {
return rofi_theme_get_position(WIDGET(state->main_window), "location",
loc_transtable[config.location]);
}
static int rofi_get_location ( RofiViewState *state )
{
return rofi_theme_get_position ( WIDGET ( state->main_window ), "location", loc_transtable[config.location] );
static void wayland_rofi_view_window_update_size(RofiViewState *state) {
if (state == NULL) {
return;
}
widget_resize(WIDGET(state->main_window), state->width, state->height);
display_set_surface_dimensions(state->width, state->height,
rofi_get_location(state));
}
static void wayland_rofi_view_window_update_size ( RofiViewState * state )
{
if ( state == NULL ) {
return;
}
widget_resize ( WIDGET ( state->main_window ), state->width, state->height );
display_set_surface_dimensions ( state->width, state->height, rofi_get_location ( state ) );
static void wayland_rofi_view_set_size(RofiViewState *state, gint width,
gint height) {
if (width > -1) {
state->width = width;
}
if (height > -1) {
state->height = height;
}
wayland_rofi_view_window_update_size(state);
}
static void wayland_rofi_view_set_size ( RofiViewState * state, gint width, gint height )
{
if ( width > -1 ) {
state->width = width;
}
if ( height > -1 ) {
state->height = height;
}
wayland_rofi_view_window_update_size ( state );
static void wayland_rofi_view_get_size(RofiViewState *state, gint *width,
gint *height) {
*width = state->width;
*height = state->height;
}
static void wayland_rofi_view_get_size ( RofiViewState * state, gint *width, gint *height )
{
*width = state->width;
*height = state->height;
static void wayland_rofi_view_set_cursor(RofiCursorType type) {
(void)type;
// TODO
}
static void wayland_rofi_view_set_cursor ( RofiCursorType type )
{
(void) type;
static void wayland_rofi_view_ping_mouse(RofiViewState *state) { (void)state; }
// TODO
static gboolean wayland_rofi_view_reload_idle(G_GNUC_UNUSED gpointer data) {
RofiViewState *state = rofi_view_get_active();
if (state) {
state->reload = TRUE;
state->refilter = TRUE;
wayland_rofi_view_maybe_update(state);
}
WlState.idle_timeout = 0;
return G_SOURCE_REMOVE;
}
static void wayland_rofi_view_ping_mouse ( RofiViewState *state )
{
(void) state;
static void wayland_rofi_view_reload(void) {
// @TODO add check if current view is equal to the callee
if (WlState.idle_timeout == 0) {
WlState.idle_timeout =
g_timeout_add(1000 / 15, wayland_rofi_view_reload_idle, NULL);
}
}
static void wayland_rofi_view_queue_redraw(void) {
RofiViewState *state = rofi_view_get_active();
if (state && WlState.repaint_source == 0) {
WlState.count++;
g_debug("redraw %llu", WlState.count);
static gboolean wayland_rofi_view_reload_idle ( G_GNUC_UNUSED gpointer data )
{
RofiViewState *state = rofi_view_get_active ();
widget_queue_redraw(WIDGET(state->main_window));
if ( state ) {
state->reload = TRUE;
state->refilter = TRUE;
wayland_rofi_view_maybe_update ( state );
}
WlState.idle_timeout = 0;
return G_SOURCE_REMOVE;
}
static void wayland_rofi_view_reload ( void )
{
// @TODO add check if current view is equal to the callee
if ( WlState.idle_timeout == 0 ) {
WlState.idle_timeout = g_timeout_add ( 1000 / 15, wayland_rofi_view_reload_idle, NULL );
}
}
static void wayland_rofi_view_queue_redraw ( void )
{
RofiViewState *state = rofi_view_get_active ();
if ( state && WlState.repaint_source == 0 ) {
WlState.count++;
g_debug ( "redraw %llu", WlState.count );
widget_queue_redraw ( WIDGET ( state->main_window ) );
WlState.repaint_source = g_idle_add_full ( G_PRIORITY_HIGH_IDLE, wayland_rofi_view_repaint, NULL, NULL );
}
WlState.repaint_source = g_idle_add_full(
G_PRIORITY_HIGH_IDLE, wayland_rofi_view_repaint, NULL, NULL);
}
}
/**
* Thread state for workers started for the view.
*/
typedef struct _thread_state_view
{
/** Generic thread state. */
thread_state st;
typedef struct _thread_state_view {
/** Generic thread state. */
thread_state st;
/** Condition. */
GCond *cond;
/** Lock for condition. */
GMutex *mutex;
/** Count that is protected by lock. */
unsigned int *acount;
/** Condition. */
GCond *cond;
/** Lock for condition. */
GMutex *mutex;
/** Count that is protected by lock. */
unsigned int *acount;
/** Current state. */
RofiViewState *state;
/** Start row for this worker. */
unsigned int start;
/** Stop row for this worker. */
unsigned int stop;
/** Rows processed. */
unsigned int count;
/** Current state. */
RofiViewState *state;
/** Start row for this worker. */
unsigned int start;
/** Stop row for this worker. */
unsigned int stop;
/** Rows processed. */
unsigned int count;
/** Pattern input to filter. */
const char *pattern;
/** Length of pattern. */
glong plen;
/** Pattern input to filter. */
const char *pattern;
/** Length of pattern. */
glong plen;
} thread_state_view;
static void wayland___create_window ( MenuFlags menu_flags )
{
// FIXME: create surface
// FIXME: roll next buffer
static void wayland___create_window(MenuFlags menu_flags) {
// FIXME: create surface
// FIXME: roll next buffer
TICK_N ( "create cairo surface" );
// TODO should we update the drawable each time?
PangoContext *p = pango_context_new ( );
pango_context_set_font_map ( p, pango_cairo_font_map_get_default () );
TICK_N ( "pango cairo font setup" );
TICK_N("create cairo surface");
// TODO should we update the drawable each time?
PangoContext *p = pango_context_new();
pango_context_set_font_map(p, pango_cairo_font_map_get_default());
TICK_N("pango cairo font setup");
WlState.flags = menu_flags;
// Setup font.
// Dummy widget.
box *win = box_create ( NULL, "window", ROFI_ORIENTATION_HORIZONTAL );
const char *font = rofi_theme_get_string ( WIDGET ( win ), "font", config.menu_font );
if ( font ) {
PangoFontDescription *pfd = pango_font_description_from_string ( font );
if ( helper_validate_font ( pfd, font ) ) {
pango_context_set_font_description ( p, pfd );
}
pango_font_description_free ( pfd );
WlState.flags = menu_flags;
// Setup font.
// Dummy widget.
box *win = box_create(NULL, "window", ROFI_ORIENTATION_HORIZONTAL);
const char *font =
rofi_theme_get_string(WIDGET(win), "font", config.menu_font);
if (font) {
PangoFontDescription *pfd = pango_font_description_from_string(font);
if (helper_validate_font(pfd, font)) {
pango_context_set_font_description(p, pfd);
}
PangoLanguage *l = pango_language_get_default ();
pango_context_set_language ( p, l );
TICK_N ( "configure font" );
pango_font_description_free(pfd);
}
PangoLanguage *l = pango_language_get_default();
pango_context_set_language(p, l);
TICK_N("configure font");
// Tell textbox to use this context.
textbox_set_pango_context ( font, p );
// cleanup
g_object_unref ( p );
// Tell textbox to use this context.
textbox_set_pango_context(font, p);
// cleanup
g_object_unref(p);
WlState.fullscreen = rofi_theme_get_boolean ( WIDGET ( win ), "fullscreen", FALSE );
WlState.fullscreen = rofi_theme_get_boolean(WIDGET(win), "fullscreen", FALSE);
widget_free ( WIDGET ( win ) );
widget_free(WIDGET(win));
TICK_N ( "done" );
TICK_N("done");
}
/**
@ -286,58 +266,57 @@ static void wayland___create_window ( MenuFlags menu_flags )
*
* Calculate the width of the window and the width of an element.
*/
static void wayland_rofi_view_calculate_window_width ( RofiViewState *state )
{
int screen_width = 1920;
display_get_surface_dimensions ( &screen_width, NULL );
static void wayland_rofi_view_calculate_window_width(RofiViewState *state) {
int screen_width = 1920;
display_get_surface_dimensions(&screen_width, NULL);
if ( WlState.fullscreen == TRUE ) {
state->width = screen_width;
return;
}
if (WlState.fullscreen == TRUE) {
state->width = screen_width;
return;
}
// Calculate as float to stop silly, big rounding down errors.
state->width = ( screen_width / 100.0f ) * DEFAULT_MENU_WIDTH;
// Use theme configured width, if set.
RofiDistance width = rofi_theme_get_distance ( WIDGET ( state->main_window ), "width", state->width );
state->width = distance_get_pixel ( width, ROFI_ORIENTATION_HORIZONTAL );
// Calculate as float to stop silly, big rounding down errors.
state->width = (screen_width / 100.0f) * DEFAULT_MENU_WIDTH;
// Use theme configured width, if set.
RofiDistance width = rofi_theme_get_distance(WIDGET(state->main_window),
"width", state->width);
state->width = distance_get_pixel(width, ROFI_ORIENTATION_HORIZONTAL);
}
static void wayland_rofi_view_update ( RofiViewState *state, gboolean qr )
{
if ( !widget_need_redraw ( WIDGET ( state->main_window ) ) ) {
return;
}
g_debug ( "Redraw view" );
TICK ();
if ( state->pool == NULL ) {
state->pool = display_buffer_pool_new ( state->width, state->height );
}
cairo_surface_t *surface = display_buffer_pool_get_next_buffer ( state->pool );
if ( surface == NULL ) {
// no available buffer, bail out
return;
}
cairo_t *d = cairo_create ( surface );
cairo_set_operator ( d, CAIRO_OPERATOR_SOURCE );
// Paint the background transparent.
cairo_set_source_rgba ( d, 0, 0, 0, 0.0 );
guint scale = display_scale ( );
cairo_surface_set_device_scale ( surface, scale, scale );
cairo_paint ( d );
TICK_N ( "Background" );
static void wayland_rofi_view_update(RofiViewState *state, gboolean qr) {
if (!widget_need_redraw(WIDGET(state->main_window))) {
return;
}
g_debug("Redraw view");
TICK();
if (state->pool == NULL) {
state->pool = display_buffer_pool_new(state->width, state->height);
}
cairo_surface_t *surface = display_buffer_pool_get_next_buffer(state->pool);
if (surface == NULL) {
// no available buffer, bail out
return;
}
cairo_t *d = cairo_create(surface);
cairo_set_operator(d, CAIRO_OPERATOR_SOURCE);
// Paint the background transparent.
cairo_set_source_rgba(d, 0, 0, 0, 0.0);
guint scale = display_scale();
cairo_surface_set_device_scale(surface, scale, scale);
cairo_paint(d);
TICK_N("Background");
// Always paint as overlay over the background.
cairo_set_operator ( d, CAIRO_OPERATOR_OVER );
widget_draw ( WIDGET ( state->main_window ), d );
// Always paint as overlay over the background.
cairo_set_operator(d, CAIRO_OPERATOR_OVER);
widget_draw(WIDGET(state->main_window), d);
TICK_N ( "widgets" );
cairo_destroy ( d );
display_surface_commit ( surface );
TICK_N("widgets");
cairo_destroy(d);
display_surface_commit(surface);
if ( qr ) {
wayland_rofi_view_queue_redraw ();
}
if (qr) {
wayland_rofi_view_queue_redraw();
}
}
/**
@ -345,120 +324,113 @@ static void wayland_rofi_view_update ( RofiViewState *state, gboolean qr )
*
* Check if a finalize function is set, and if sets executes it.
*/
void process_result ( RofiViewState *state );
void process_result(RofiViewState *state);
static void wayland_rofi_view_maybe_update ( RofiViewState *state )
{
if ( rofi_view_get_completed ( state ) ) {
// This menu is done.
rofi_view_finalize ( state );
// If there a state. (for example error) reload it.
state = rofi_view_get_active ();
static void wayland_rofi_view_maybe_update(RofiViewState *state) {
if (rofi_view_get_completed(state)) {
// This menu is done.
rofi_view_finalize(state);
// If there a state. (for example error) reload it.
state = rofi_view_get_active();
// cleanup, if no more state to display.
if ( state == NULL ) {
// Quit main-loop.
rofi_quit_main_loop ();
return;
}
// cleanup, if no more state to display.
if (state == NULL) {
// Quit main-loop.
rofi_quit_main_loop();
return;
}
}
// Update if requested.
if ( state->refilter ) {
rofi_view_refilter ( state );
}
wayland_rofi_view_update ( state, TRUE );
// Update if requested.
if (state->refilter) {
rofi_view_refilter(state);
}
wayland_rofi_view_update(state, TRUE);
}
static void wayland_rofi_view_frame_callback ( void )
{
if ( WlState.repaint_source == 0 ) {
WlState.repaint_source = g_idle_add_full ( G_PRIORITY_HIGH_IDLE, wayland_rofi_view_repaint, NULL, NULL );
}
static void wayland_rofi_view_frame_callback(void) {
if (WlState.repaint_source == 0) {
WlState.repaint_source = g_idle_add_full(
G_PRIORITY_HIGH_IDLE, wayland_rofi_view_repaint, NULL, NULL);
}
}
static int wayland_rofi_view_calculate_window_height ( RofiViewState *state )
{
if ( WlState.fullscreen == TRUE ) {
int height = 1080;
display_get_surface_dimensions ( NULL, &height );
return height;
}
RofiDistance h = rofi_theme_get_distance ( WIDGET ( state->main_window ), "height", 0 );
unsigned int height = distance_get_pixel ( h, ROFI_ORIENTATION_VERTICAL );
// If height is set, return it.
if ( height > 0 ) {
return height;
}
// Autosize based on widgets.
widget *main_window = WIDGET ( state->main_window );
height = widget_get_desired_height ( main_window );
static int wayland_rofi_view_calculate_window_height(RofiViewState *state) {
if (WlState.fullscreen == TRUE) {
int height = 1080;
display_get_surface_dimensions(NULL, &height);
return height;
}
RofiDistance h =
rofi_theme_get_distance(WIDGET(state->main_window), "height", 0);
unsigned int height = distance_get_pixel(h, ROFI_ORIENTATION_VERTICAL);
// If height is set, return it.
if (height > 0) {
return height;
}
// Autosize based on widgets.
widget *main_window = WIDGET(state->main_window);
height = widget_get_desired_height(main_window);
return height;
}
static void wayland_rofi_view_hide ( void )
{
static void wayland_rofi_view_hide(void) {}
static void wayland_rofi_view_cleanup() {
g_debug("Cleanup.");
if (WlState.idle_timeout > 0) {
g_source_remove(WlState.idle_timeout);
WlState.idle_timeout = 0;
}
if (WlState.repaint_source > 0) {
g_source_remove(WlState.repaint_source);
WlState.repaint_source = 0;
}
}
static void wayland_rofi_view_cleanup ()
{
g_debug ( "Cleanup." );
if ( WlState.idle_timeout > 0 ) {
g_source_remove ( WlState.idle_timeout );
WlState.idle_timeout = 0;
}
if ( WlState.repaint_source > 0 ) {
g_source_remove ( WlState.repaint_source );
WlState.repaint_source = 0;
}
}
static void wayland_rofi_view_set_window_title(const char *title) {}
static void wayland_rofi_view_set_window_title ( const char * title )
{
}
static void wayland_rofi_view_pool_refresh ( void )
{
RofiViewState *state = rofi_view_get_active ();
if ( state == NULL ) {
return;
}
display_buffer_pool_free ( state->pool );
state->pool = NULL;
wayland_rofi_view_update ( state, TRUE );
static void wayland_rofi_view_pool_refresh(void) {
RofiViewState *state = rofi_view_get_active();
if (state == NULL) {
return;
}
display_buffer_pool_free(state->pool);
state->pool = NULL;
wayland_rofi_view_update(state, TRUE);
}
static view_proxy view_ = {
.update = wayland_rofi_view_update,
.maybe_update = wayland_rofi_view_maybe_update,
.update = wayland_rofi_view_update,
.maybe_update = wayland_rofi_view_maybe_update,
.temp_configure_notify = NULL,
.temp_click_to_exit = NULL,
.frame_callback = wayland_rofi_view_frame_callback,
.queue_redraw = wayland_rofi_view_queue_redraw,
.temp_click_to_exit = NULL,
.frame_callback = wayland_rofi_view_frame_callback,
.queue_redraw = wayland_rofi_view_queue_redraw,
.set_window_title = wayland_rofi_view_set_window_title,
.set_window_title = wayland_rofi_view_set_window_title,
.calculate_window_position = wayland_rofi_view_calculate_window_position,
.calculate_window_height = wayland_rofi_view_calculate_window_height,
.calculate_window_width = wayland_rofi_view_calculate_window_width,
.window_update_size = wayland_rofi_view_window_update_size,
.set_cursor = wayland_rofi_view_set_cursor,
.ping_mouse = wayland_rofi_view_ping_mouse,
.calculate_window_height = wayland_rofi_view_calculate_window_height,
.calculate_window_width = wayland_rofi_view_calculate_window_width,
.window_update_size = wayland_rofi_view_window_update_size,
.set_cursor = wayland_rofi_view_set_cursor,
.ping_mouse = wayland_rofi_view_ping_mouse,
.cleanup = wayland_rofi_view_cleanup,
.hide = wayland_rofi_view_hide,
.reload = wayland_rofi_view_reload,
.hide = wayland_rofi_view_hide,
.reload = wayland_rofi_view_reload,
.__create_window = wayland___create_window,
.get_window = NULL,
.__create_window = wayland___create_window,
.get_window = NULL,
.get_current_monitor = wayland_rofi_view_get_current_monitor,
.capture_screenshot = wayland_rofi_view_capture_screenshot,
.capture_screenshot = wayland_rofi_view_capture_screenshot,
.set_size = wayland_rofi_view_set_size,
.get_size = wayland_rofi_view_get_size,
.pool_refresh = wayland_rofi_view_pool_refresh,
.pool_refresh = wayland_rofi_view_pool_refresh,
};
const view_proxy *wayland_view_proxy = &view_;
const view_proxy *wayland_view_proxy = &view_;

View file

@ -26,354 +26,353 @@
*/
/** The log domain of this widget. */
#define G_LOG_DOMAIN "Widgets.Box"
#define G_LOG_DOMAIN "Widgets.Box"
#include <config.h>
#include <stdio.h>
#include "widgets/widget.h"
#include "widgets/widget-internal.h"
#include "widgets/box.h"
#include "theme.h"
#include "widgets/widget-internal.h"
#include "widgets/widget.h"
#include <stdio.h>
/** Default spacing used in the box*/
#define DEFAULT_SPACING 2
#define DEFAULT_SPACING 2
struct _box
{
widget widget;
RofiOrientation type;
int max_size;
// RofiPadding between elements
RofiDistance spacing;
struct _box {
widget widget;
RofiOrientation type;
int max_size;
// RofiPadding between elements
RofiDistance spacing;
GList *children;
GList *children;
};
static void box_update ( widget *wid );
static void box_update(widget *wid);
static int box_get_desired_width ( widget *wid )
{
box *b = (box *) wid;
int spacing = distance_get_pixel ( b->spacing, b->type );
int width = 0;
static int box_get_desired_width(widget *wid) {
box *b = (box *)wid;
int spacing = distance_get_pixel(b->spacing, b->type);
int width = 0;
// Allow user to override.
RofiDistance w = rofi_theme_get_distance ( wid, "width", 0 );
width = distance_get_pixel ( w, ROFI_ORIENTATION_HORIZONTAL );
if ( width > 0 ) {
return width;
}
if ( b->type == ROFI_ORIENTATION_HORIZONTAL ) {
int active_widgets = 0;
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
widget * child = (widget *) iter->data;
if ( !child->enabled ) {
continue;
}
active_widgets++;
if ( child->expand == TRUE ) {
width += widget_get_desired_width ( child );
continue;
}
width += widget_get_desired_width ( child );
}
if ( active_widgets > 0 ) {
width += ( active_widgets - 1 ) * spacing;
}
}
else {
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
widget * child = (widget *) iter->data;
if ( !child->enabled ) {
continue;
}
width = MAX ( widget_get_desired_width ( child ), width );
}
}
width += widget_padding_get_padding_width ( wid );
// Allow user to override.
RofiDistance w = rofi_theme_get_distance(wid, "width", 0);
width = distance_get_pixel(w, ROFI_ORIENTATION_HORIZONTAL);
if (width > 0) {
return width;
}
if (b->type == ROFI_ORIENTATION_HORIZONTAL) {
int active_widgets = 0;
for (GList *iter = g_list_first(b->children); iter != NULL;
iter = g_list_next(iter)) {
widget *child = (widget *)iter->data;
if (!child->enabled) {
continue;
}
active_widgets++;
if (child->expand == TRUE) {
width += widget_get_desired_width(child);
continue;
}
width += widget_get_desired_width(child);
}
if (active_widgets > 0) {
width += (active_widgets - 1) * spacing;
}
} else {
for (GList *iter = g_list_first(b->children); iter != NULL;
iter = g_list_next(iter)) {
widget *child = (widget *)iter->data;
if (!child->enabled) {
continue;
}
width = MAX(widget_get_desired_width(child), width);
}
}
width += widget_padding_get_padding_width(wid);
return width;
}
static int box_get_desired_height ( widget *wid )
{
box *b = (box *) wid;
int spacing = distance_get_pixel ( b->spacing, b->type );
int height = 0;
if ( b->type == ROFI_ORIENTATION_VERTICAL ) {
int active_widgets = 0;
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
widget * child = (widget *) iter->data;
if ( !child->enabled ) {
continue;
}
active_widgets++;
height += widget_get_desired_height ( child );
}
if ( active_widgets > 0 ) {
height += ( active_widgets - 1 ) * spacing;
}
static int box_get_desired_height(widget *wid) {
box *b = (box *)wid;
int spacing = distance_get_pixel(b->spacing, b->type);
int height = 0;
if (b->type == ROFI_ORIENTATION_VERTICAL) {
int active_widgets = 0;
for (GList *iter = g_list_first(b->children); iter != NULL;
iter = g_list_next(iter)) {
widget *child = (widget *)iter->data;
if (!child->enabled) {
continue;
}
active_widgets++;
height += widget_get_desired_height(child);
}
else {
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
widget * child = (widget *) iter->data;
if ( !child->enabled ) {
continue;
}
height = MAX ( widget_get_desired_height ( child ), height );
}
if (active_widgets > 0) {
height += (active_widgets - 1) * spacing;
}
height += widget_padding_get_padding_height ( wid );
return height;
} else {
for (GList *iter = g_list_first(b->children); iter != NULL;
iter = g_list_next(iter)) {
widget *child = (widget *)iter->data;
if (!child->enabled) {
continue;
}
height = MAX(widget_get_desired_height(child), height);
}
}
height += widget_padding_get_padding_height(wid);
return height;
}
static void vert_calculate_size ( box *b )
{
int spacing = distance_get_pixel ( b->spacing, ROFI_ORIENTATION_VERTICAL );
int expanding_widgets = 0;
int active_widgets = 0;
int rem_width = widget_padding_get_remaining_width ( WIDGET ( b ) );
int rem_height = widget_padding_get_remaining_height ( WIDGET ( b ) );
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
widget * child = (widget *) iter->data;
if ( child->enabled && child->expand == FALSE ) {
widget_resize ( child, rem_width, widget_get_desired_height ( child ) );
}
static void vert_calculate_size(box *b) {
int spacing = distance_get_pixel(b->spacing, ROFI_ORIENTATION_VERTICAL);
int expanding_widgets = 0;
int active_widgets = 0;
int rem_width = widget_padding_get_remaining_width(WIDGET(b));
int rem_height = widget_padding_get_remaining_height(WIDGET(b));
for (GList *iter = g_list_first(b->children); iter != NULL;
iter = g_list_next(iter)) {
widget *child = (widget *)iter->data;
if (child->enabled && child->expand == FALSE) {
widget_resize(child, rem_width, widget_get_desired_height(child));
}
b->max_size = 0;
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
widget * child = (widget *) iter->data;
if ( !child->enabled ) {
continue;
}
active_widgets++;
if ( child->expand == TRUE ) {
expanding_widgets++;
continue;
}
if ( child->h > 0 ) {
b->max_size += child->h;
}
}
b->max_size = 0;
for (GList *iter = g_list_first(b->children); iter != NULL;
iter = g_list_next(iter)) {
widget *child = (widget *)iter->data;
if (!child->enabled) {
continue;
}
if ( active_widgets > 0 ) {
b->max_size += ( active_widgets - 1 ) * spacing;
active_widgets++;
if (child->expand == TRUE) {
expanding_widgets++;
continue;
}
if ( b->max_size > rem_height ) {
b->max_size = rem_height;
g_debug ( "Widgets to large (height) for box: %d %d", b->max_size, b->widget.h );
return;
if (child->h > 0) {
b->max_size += child->h;
}
if ( active_widgets > 0 ) {
int top = widget_padding_get_top ( WIDGET ( b ) );
double rem = rem_height - b->max_size;
int index = 0;
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
widget * child = (widget *) iter->data;
if ( child->enabled == FALSE ) {
continue;
}
if ( child->expand == TRUE ) {
// Re-calculate to avoid round issues leaving one pixel left.
int expanding_widgets_size = ( rem ) / ( expanding_widgets - index );
widget_move ( child, widget_padding_get_left ( WIDGET ( b ) ), top );
top += expanding_widgets_size;
widget_resize ( child, rem_width, expanding_widgets_size );
top += spacing;
rem -= expanding_widgets_size;
index++;
}
else {
widget_move ( child, widget_padding_get_left ( WIDGET ( b ) ), top );
top += widget_get_height ( child );
top += spacing;
}
}
}
if (active_widgets > 0) {
b->max_size += (active_widgets - 1) * spacing;
}
if (b->max_size > rem_height) {
b->max_size = rem_height;
g_debug("Widgets to large (height) for box: %d %d", b->max_size,
b->widget.h);
return;
}
if (active_widgets > 0) {
int top = widget_padding_get_top(WIDGET(b));
double rem = rem_height - b->max_size;
int index = 0;
for (GList *iter = g_list_first(b->children); iter != NULL;
iter = g_list_next(iter)) {
widget *child = (widget *)iter->data;
if (child->enabled == FALSE) {
continue;
}
if (child->expand == TRUE) {
// Re-calculate to avoid round issues leaving one pixel left.
int expanding_widgets_size = (rem) / (expanding_widgets - index);
widget_move(child, widget_padding_get_left(WIDGET(b)), top);
top += expanding_widgets_size;
widget_resize(child, rem_width, expanding_widgets_size);
top += spacing;
rem -= expanding_widgets_size;
index++;
} else {
widget_move(child, widget_padding_get_left(WIDGET(b)), top);
top += widget_get_height(child);
top += spacing;
}
}
b->max_size += widget_padding_get_padding_height ( WIDGET ( b ) );
}
b->max_size += widget_padding_get_padding_height(WIDGET(b));
}
static void hori_calculate_size ( box *b )
{
int spacing = distance_get_pixel ( b->spacing, ROFI_ORIENTATION_HORIZONTAL );
int expanding_widgets = 0;
int active_widgets = 0;
int rem_width = widget_padding_get_remaining_width ( WIDGET ( b ) );
int rem_height = widget_padding_get_remaining_height ( WIDGET ( b ) );
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
widget * child = (widget *) iter->data;
if ( child->enabled && child->expand == FALSE ) {
widget_resize ( child,
widget_get_desired_width ( child ), //child->w,
rem_height );
}
static void hori_calculate_size(box *b) {
int spacing = distance_get_pixel(b->spacing, ROFI_ORIENTATION_HORIZONTAL);
int expanding_widgets = 0;
int active_widgets = 0;
int rem_width = widget_padding_get_remaining_width(WIDGET(b));
int rem_height = widget_padding_get_remaining_height(WIDGET(b));
for (GList *iter = g_list_first(b->children); iter != NULL;
iter = g_list_next(iter)) {
widget *child = (widget *)iter->data;
if (child->enabled && child->expand == FALSE) {
widget_resize(child,
widget_get_desired_width(child), // child->w,
rem_height);
}
b->max_size = 0;
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
widget * child = (widget *) iter->data;
if ( !child->enabled ) {
continue;
}
active_widgets++;
if ( child->expand == TRUE ) {
expanding_widgets++;
continue;
}
// Size used by fixed width widgets.
if ( child->h > 0 ) {
b->max_size += child->w;
}
}
b->max_size = 0;
for (GList *iter = g_list_first(b->children); iter != NULL;
iter = g_list_next(iter)) {
widget *child = (widget *)iter->data;
if (!child->enabled) {
continue;
}
b->max_size += MAX ( 0, ( ( active_widgets - 1 ) * spacing ) );
if ( b->max_size > ( rem_width ) ) {
b->max_size = rem_width;
g_debug ( "Widgets to large (width) for box: %d %d", b->max_size, b->widget.w );
//return;
active_widgets++;
if (child->expand == TRUE) {
expanding_widgets++;
continue;
}
if ( active_widgets > 0 ) {
int left = widget_padding_get_left ( WIDGET ( b ) );
double rem = rem_width - b->max_size;
int index = 0;
if ( rem < 0 ) {
rem = 0;
}
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
widget * child = (widget *) iter->data;
if ( child->enabled == FALSE ) {
continue;
}
if ( child->expand == TRUE ) {
// Re-calculate to avoid round issues leaving one pixel left.
int expanding_widgets_size = ( rem ) / ( expanding_widgets - index );
widget_move ( child, left, widget_padding_get_top ( WIDGET ( b ) ) );
left += expanding_widgets_size;
widget_resize ( child, expanding_widgets_size, rem_height );
left += spacing;
rem -= expanding_widgets_size;
index++;
}
else {
widget_move ( child, left, widget_padding_get_top ( WIDGET ( b ) ) );
left += widget_get_width ( child );
left += spacing;
}
}
// Size used by fixed width widgets.
if (child->h > 0) {
b->max_size += child->w;
}
b->max_size += widget_padding_get_padding_width ( WIDGET ( b ) );
}
b->max_size += MAX(0, ((active_widgets - 1) * spacing));
if (b->max_size > (rem_width)) {
b->max_size = rem_width;
g_debug("Widgets to large (width) for box: %d %d", b->max_size,
b->widget.w);
// return;
}
if (active_widgets > 0) {
int left = widget_padding_get_left(WIDGET(b));
double rem = rem_width - b->max_size;
int index = 0;
if (rem < 0) {
rem = 0;
}
for (GList *iter = g_list_first(b->children); iter != NULL;
iter = g_list_next(iter)) {
widget *child = (widget *)iter->data;
if (child->enabled == FALSE) {
continue;
}
if (child->expand == TRUE) {
// Re-calculate to avoid round issues leaving one pixel left.
int expanding_widgets_size = (rem) / (expanding_widgets - index);
widget_move(child, left, widget_padding_get_top(WIDGET(b)));
left += expanding_widgets_size;
widget_resize(child, expanding_widgets_size, rem_height);
left += spacing;
rem -= expanding_widgets_size;
index++;
} else {
widget_move(child, left, widget_padding_get_top(WIDGET(b)));
left += widget_get_width(child);
left += spacing;
}
}
}
b->max_size += widget_padding_get_padding_width(WIDGET(b));
}
static void box_draw ( widget *wid, cairo_t *draw )
{
box *b = (box *) wid;
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
widget * child = (widget *) iter->data;
widget_draw ( child, draw );
}
static void box_draw(widget *wid, cairo_t *draw) {
box *b = (box *)wid;
for (GList *iter = g_list_first(b->children); iter != NULL;
iter = g_list_next(iter)) {
widget *child = (widget *)iter->data;
widget_draw(child, draw);
}
}
static void box_free ( widget *wid )
{
box *b = (box *) wid;
static void box_free(widget *wid) {
box *b = (box *)wid;
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
widget * child = (widget *) iter->data;
widget_free ( child );
}
g_list_free ( b->children );
g_free ( b );
for (GList *iter = g_list_first(b->children); iter != NULL;
iter = g_list_next(iter)) {
widget *child = (widget *)iter->data;
widget_free(child);
}
g_list_free(b->children);
g_free(b);
}
void box_add ( box *box, widget *child, gboolean expand )
{
if ( box == NULL ) {
return;
}
// Make sure box is width/heigh enough.
if ( box->type == ROFI_ORIENTATION_VERTICAL ) {
int width = box->widget.w;
width = MAX ( width, child->w + widget_padding_get_padding_width ( WIDGET ( box ) ) );
box->widget.w = width;
}
else {
int height = box->widget.h;
height = MAX ( height, child->h + widget_padding_get_padding_height ( WIDGET ( box ) ) );
box->widget.h = height;
}
child->expand = rofi_theme_get_boolean ( child, "expand", expand );
g_assert ( child->parent == WIDGET ( box ) );
box->children = g_list_append ( box->children, (void *) child );
widget_update ( WIDGET ( box ) );
void box_add(box *box, widget *child, gboolean expand) {
if (box == NULL) {
return;
}
// Make sure box is width/heigh enough.
if (box->type == ROFI_ORIENTATION_VERTICAL) {
int width = box->widget.w;
width =
MAX(width, child->w + widget_padding_get_padding_width(WIDGET(box)));
box->widget.w = width;
} else {
int height = box->widget.h;
height =
MAX(height, child->h + widget_padding_get_padding_height(WIDGET(box)));
box->widget.h = height;
}
child->expand = rofi_theme_get_boolean(child, "expand", expand);
g_assert(child->parent == WIDGET(box));
box->children = g_list_append(box->children, (void *)child);
widget_update(WIDGET(box));
}
static void box_resize ( widget *widget, short w, short h )
{
box *b = (box *) widget;
if ( b->widget.w != w || b->widget.h != h ) {
b->widget.w = w;
b->widget.h = h;
widget_update ( widget );
}
static void box_resize(widget *widget, short w, short h) {
box *b = (box *)widget;
if (b->widget.w != w || b->widget.h != h) {
b->widget.w = w;
b->widget.h = h;
widget_update(widget);
}
}
static widget *box_find_mouse_target ( widget *wid, WidgetType type, gint x, gint y )
{
box *b = (box *) wid;
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
widget * child = (widget *) iter->data;
if ( !child->enabled ) {
continue;
}
if ( widget_intersect ( child, x, y ) ) {
gint rx = x - child->x;
gint ry = y - child->y;
widget *target = widget_find_mouse_target ( child, type, rx, ry );
if ( target != NULL ) {
return target;
}
}
static widget *box_find_mouse_target(widget *wid, WidgetType type, gint x,
gint y) {
box *b = (box *)wid;
for (GList *iter = g_list_first(b->children); iter != NULL;
iter = g_list_next(iter)) {
widget *child = (widget *)iter->data;
if (!child->enabled) {
continue;
}
return NULL;
if (widget_intersect(child, x, y)) {
gint rx = x - child->x;
gint ry = y - child->y;
widget *target = widget_find_mouse_target(child, type, rx, ry);
if (target != NULL) {
return target;
}
}
}
return NULL;
}
static void box_set_state ( widget *wid, const char *state )
{
for ( GList *iter = g_list_first ( ( (box *) wid )->children ); iter != NULL; iter = g_list_next ( iter ) ) {
widget * child = (widget *) iter->data;
widget_set_state ( child, state );
}
static void box_set_state(widget *wid, const char *state) {
for (GList *iter = g_list_first(((box *)wid)->children); iter != NULL;
iter = g_list_next(iter)) {
widget *child = (widget *)iter->data;
widget_set_state(child, state);
}
}
box * box_create ( widget *parent, const char *name, RofiOrientation type )
{
box *b = g_malloc0 ( sizeof ( box ) );
// Initialize widget.
widget_init ( WIDGET ( b ), parent, WIDGET_TYPE_UNKNOWN, name );
b->type = type;
b->widget.draw = box_draw;
b->widget.free = box_free;
b->widget.resize = box_resize;
b->widget.update = box_update;
b->widget.find_mouse_target = box_find_mouse_target;
b->widget.get_desired_height = box_get_desired_height;
b->widget.get_desired_width = box_get_desired_width;
b->widget.set_state = box_set_state;
box *box_create(widget *parent, const char *name, RofiOrientation type) {
box *b = g_malloc0(sizeof(box));
// Initialize widget.
widget_init(WIDGET(b), parent, WIDGET_TYPE_UNKNOWN, name);
b->type = type;
b->widget.draw = box_draw;
b->widget.free = box_free;
b->widget.resize = box_resize;
b->widget.update = box_update;
b->widget.find_mouse_target = box_find_mouse_target;
b->widget.get_desired_height = box_get_desired_height;
b->widget.get_desired_width = box_get_desired_width;
b->widget.set_state = box_set_state;
b->type = rofi_theme_get_orientation ( WIDGET ( b ), "orientation", b->type );
b->type = rofi_theme_get_orientation(WIDGET(b), "orientation", b->type);
b->spacing = rofi_theme_get_distance ( WIDGET ( b ), "spacing", DEFAULT_SPACING );
return b;
b->spacing = rofi_theme_get_distance(WIDGET(b), "spacing", DEFAULT_SPACING);
return b;
}
static void box_update ( widget *wid )
{
box *b = (box *) wid;
switch ( b->type )
{
case ROFI_ORIENTATION_VERTICAL:
vert_calculate_size ( b );
break;
case ROFI_ORIENTATION_HORIZONTAL:
default:
hori_calculate_size ( b );
}
if ( wid->parent ) {
widget_update ( wid->parent );
}
static void box_update(widget *wid) {
box *b = (box *)wid;
switch (b->type) {
case ROFI_ORIENTATION_VERTICAL:
vert_calculate_size(b);
break;
case ROFI_ORIENTATION_HORIZONTAL:
default:
hori_calculate_size(b);
}
if (wid->parent) {
widget_update(wid->parent);
}
}

View file

@ -26,113 +26,100 @@
*/
/** The log domain of this widget. */
#define G_LOG_DOMAIN "Widgets.Container"
#define G_LOG_DOMAIN "Widgets.Container"
#include <config.h>
#include <stdio.h>
#include "widgets/widget.h"
#include "widgets/widget-internal.h"
#include "widgets/container.h"
#include "theme.h"
#include "widgets/widget-internal.h"
#include "widgets/widget.h"
#include <stdio.h>
struct _container
{
widget widget;
widget *child;
struct _container {
widget widget;
widget *child;
};
static void container_update ( widget *wid );
static void container_update(widget *wid);
static int container_get_desired_height ( widget *widget )
{
container *b = (container *) widget;
int height = 0;
if ( b->child ) {
height += widget_get_desired_height ( b->child );
}
height += widget_padding_get_padding_height ( widget );
return height;
static int container_get_desired_height(widget *widget) {
container *b = (container *)widget;
int height = 0;
if (b->child) {
height += widget_get_desired_height(b->child);
}
height += widget_padding_get_padding_height(widget);
return height;
}
static void container_draw ( widget *wid, cairo_t *draw )
{
container *b = (container *) wid;
static void container_draw(widget *wid, cairo_t *draw) {
container *b = (container *)wid;
widget_draw ( b->child, draw );
widget_draw(b->child, draw);
}
static void container_free ( widget *wid )
{
container *b = (container *) wid;
static void container_free(widget *wid) {
container *b = (container *)wid;
widget_free ( b->child );
g_free ( b );
widget_free(b->child);
g_free(b);
}
void container_add ( container *container, widget *child )
{
if ( container == NULL ) {
return;
}
container->child = child;
g_assert ( child->parent == WIDGET ( container ) );
widget_update ( WIDGET ( container ) );
void container_add(container *container, widget *child) {
if (container == NULL) {
return;
}
container->child = child;
g_assert(child->parent == WIDGET(container));
widget_update(WIDGET(container));
}
static void container_resize ( widget *widget, short w, short h )
{
container *b = (container *) widget;
if ( b->widget.w != w || b->widget.h != h ) {
b->widget.w = w;
b->widget.h = h;
widget_update ( widget );
}
static void container_resize(widget *widget, short w, short h) {
container *b = (container *)widget;
if (b->widget.w != w || b->widget.h != h) {
b->widget.w = w;
b->widget.h = h;
widget_update(widget);
}
}
static widget *container_find_mouse_target ( widget *wid, WidgetType type, gint x, gint y )
{
container *b = (container *) wid;
if ( !widget_intersect ( b->child, x, y ) ) {
return NULL;
}
static widget *container_find_mouse_target(widget *wid, WidgetType type, gint x,
gint y) {
container *b = (container *)wid;
if (!widget_intersect(b->child, x, y)) {
return NULL;
}
x -= b->child->x;
y -= b->child->y;
return widget_find_mouse_target ( b->child, type, x, y );
x -= b->child->x;
y -= b->child->y;
return widget_find_mouse_target(b->child, type, x, y);
}
static void container_set_state ( widget *wid, const char *state )
{
container *b = (container *) wid;
widget_set_state ( b->child, state );
static void container_set_state(widget *wid, const char *state) {
container *b = (container *)wid;
widget_set_state(b->child, state);
}
container * container_create ( widget *parent, const char *name )
{
container *b = g_malloc0 ( sizeof ( container ) );
// Initialize widget.
widget_init ( WIDGET ( b ), parent, WIDGET_TYPE_UNKNOWN, name );
b->widget.draw = container_draw;
b->widget.free = container_free;
b->widget.resize = container_resize;
b->widget.update = container_update;
b->widget.find_mouse_target = container_find_mouse_target;
b->widget.get_desired_height = container_get_desired_height;
b->widget.set_state = container_set_state;
return b;
container *container_create(widget *parent, const char *name) {
container *b = g_malloc0(sizeof(container));
// Initialize widget.
widget_init(WIDGET(b), parent, WIDGET_TYPE_UNKNOWN, name);
b->widget.draw = container_draw;
b->widget.free = container_free;
b->widget.resize = container_resize;
b->widget.update = container_update;
b->widget.find_mouse_target = container_find_mouse_target;
b->widget.get_desired_height = container_get_desired_height;
b->widget.set_state = container_set_state;
return b;
}
static void container_update ( widget *wid )
{
container *b = (container *) wid;
if ( b->child && b->child->enabled ) {
widget_resize ( WIDGET ( b->child ),
widget_padding_get_remaining_width ( WIDGET ( b ) ),
widget_padding_get_remaining_height ( WIDGET ( b ) )
);
widget_move ( WIDGET ( b->child ),
widget_padding_get_left ( WIDGET ( b ) ),
widget_padding_get_top ( WIDGET ( b ) )
);
}
static void container_update(widget *wid) {
container *b = (container *)wid;
if (b->child && b->child->enabled) {
widget_resize(WIDGET(b->child),
widget_padding_get_remaining_width(WIDGET(b)),
widget_padding_get_remaining_height(WIDGET(b)));
widget_move(WIDGET(b->child), widget_padding_get_left(WIDGET(b)),
widget_padding_get_top(WIDGET(b)));
}
}

View file

@ -26,162 +26,153 @@
*/
/** The log domain of this widget. */
#define G_LOG_DOMAIN "Widgets.Icon"
#define G_LOG_DOMAIN "Widgets.Icon"
#include <config.h>
#include <stdio.h>
#include "widgets/widget.h"
#include "widgets/widget-internal.h"
#include "widgets/icon.h"
#include "theme.h"
#include "widgets/widget-internal.h"
#include "widgets/widget.h"
#include <stdio.h>
#include "rofi-icon-fetcher.h"
struct _icon
{
widget widget;
struct _icon {
widget widget;
// Size of the icon.
int size;
// Size of the icon.
int size;
int squared;
int squared;
uint32_t icon_fetch_id;
uint32_t icon_fetch_id;
double yalign, xalign;
double yalign, xalign;
// Source surface.
cairo_surface_t *icon;
// Source surface.
cairo_surface_t *icon;
};
static int icon_get_desired_height ( widget *widget )
{
icon *b = (icon *) widget;
int height = b->size;
if ( b->squared == FALSE ) {
if ( b->icon ) {
int iconh = cairo_image_surface_get_height ( b->icon );
int iconw = cairo_image_surface_get_width ( b->icon );
int icons = MAX ( iconh, iconw );
double scale = (double) b->size / icons;
height = iconh*scale;
}
static int icon_get_desired_height(widget *widget) {
icon *b = (icon *)widget;
int height = b->size;
if (b->squared == FALSE) {
if (b->icon) {
int iconh = cairo_image_surface_get_height(b->icon);
int iconw = cairo_image_surface_get_width(b->icon);
int icons = MAX(iconh, iconw);
double scale = (double)b->size / icons;
height = iconh * scale;
}
height += widget_padding_get_padding_height ( widget );
return height;
}
height += widget_padding_get_padding_height(widget);
return height;
}
static int icon_get_desired_width ( widget *widget )
{
icon *b = (icon *) widget;
int width = b->size;
if ( b->squared == FALSE ) {
if ( b->icon ) {
int iconh = cairo_image_surface_get_height ( b->icon );
int iconw = cairo_image_surface_get_width ( b->icon );
int icons = MAX ( iconh, iconw );
double scale = (double) b->size / icons;
width = iconw*scale;
}
static int icon_get_desired_width(widget *widget) {
icon *b = (icon *)widget;
int width = b->size;
if (b->squared == FALSE) {
if (b->icon) {
int iconh = cairo_image_surface_get_height(b->icon);
int iconw = cairo_image_surface_get_width(b->icon);
int icons = MAX(iconh, iconw);
double scale = (double)b->size / icons;
width = iconw * scale;
}
width += widget_padding_get_padding_width ( widget );
return width;
}
width += widget_padding_get_padding_width(widget);
return width;
}
static void icon_draw ( widget *wid, cairo_t *draw )
{
icon *b = (icon *) wid;
// If no icon is loaded. quit.
if ( b->icon == NULL && b->icon_fetch_id > 0 ) {
b->icon = rofi_icon_fetcher_get ( b->icon_fetch_id );
if ( b->icon ) {
cairo_surface_reference ( b->icon );
}
static void icon_draw(widget *wid, cairo_t *draw) {
icon *b = (icon *)wid;
// If no icon is loaded. quit.
if (b->icon == NULL && b->icon_fetch_id > 0) {
b->icon = rofi_icon_fetcher_get(b->icon_fetch_id);
if (b->icon) {
cairo_surface_reference(b->icon);
}
if ( b->icon == NULL ) {
return;
}
int iconh = cairo_image_surface_get_height ( b->icon );
int iconw = cairo_image_surface_get_width ( b->icon );
int icons = MAX ( iconh, iconw );
double scale = (double) b->size / icons;
}
if (b->icon == NULL) {
return;
}
int iconh = cairo_image_surface_get_height(b->icon);
int iconw = cairo_image_surface_get_width(b->icon);
int icons = MAX(iconh, iconw);
double scale = (double)b->size / icons;
int lpad = widget_padding_get_left ( WIDGET ( b ) );
int rpad = widget_padding_get_right ( WIDGET ( b ) );
int tpad = widget_padding_get_top ( WIDGET ( b ) );
int bpad = widget_padding_get_bottom ( WIDGET ( b ) );
int lpad = widget_padding_get_left(WIDGET(b));
int rpad = widget_padding_get_right(WIDGET(b));
int tpad = widget_padding_get_top(WIDGET(b));
int bpad = widget_padding_get_bottom(WIDGET(b));
cairo_save ( draw );
cairo_save(draw);
cairo_translate ( draw,
lpad + ( b->widget.w - iconw * scale - lpad - rpad ) * b->xalign,
tpad + ( b->widget.h - iconh * scale - tpad - bpad ) * b->yalign );
cairo_scale ( draw, scale, scale );
cairo_set_source_surface ( draw, b->icon, 0, 0 );
cairo_paint ( draw );
cairo_restore ( draw );
cairo_translate(
draw, lpad + (b->widget.w - iconw * scale - lpad - rpad) * b->xalign,
tpad + (b->widget.h - iconh * scale - tpad - bpad) * b->yalign);
cairo_scale(draw, scale, scale);
cairo_set_source_surface(draw, b->icon, 0, 0);
cairo_paint(draw);
cairo_restore(draw);
}
static void icon_free ( widget *wid )
{
icon *b = (icon *) wid;
static void icon_free(widget *wid) {
icon *b = (icon *)wid;
if ( b->icon ) {
cairo_surface_destroy ( b->icon );
}
if (b->icon) {
cairo_surface_destroy(b->icon);
}
g_free ( b );
g_free(b);
}
static void icon_resize ( widget *widget, short w, short h )
{
icon *b = (icon *) widget;
if ( b->widget.w != w || b->widget.h != h ) {
b->widget.w = w;
b->widget.h = h;
widget_update ( widget );
}
static void icon_resize(widget *widget, short w, short h) {
icon *b = (icon *)widget;
if (b->widget.w != w || b->widget.h != h) {
b->widget.w = w;
b->widget.h = h;
widget_update(widget);
}
}
void icon_set_surface ( icon *icon, cairo_surface_t *surf )
{
icon->icon_fetch_id = 0;
if ( icon->icon ) {
cairo_surface_destroy ( icon->icon );
icon->icon = NULL;
}
if ( surf ) {
cairo_surface_reference ( surf );
icon->icon = surf;
}
widget_queue_redraw ( WIDGET ( icon ) );
void icon_set_surface(icon *icon, cairo_surface_t *surf) {
icon->icon_fetch_id = 0;
if (icon->icon) {
cairo_surface_destroy(icon->icon);
icon->icon = NULL;
}
if (surf) {
cairo_surface_reference(surf);
icon->icon = surf;
}
widget_queue_redraw(WIDGET(icon));
}
icon * icon_create ( widget *parent, const char *name )
{
icon *b = g_malloc0 ( sizeof ( icon ) );
icon *icon_create(widget *parent, const char *name) {
icon *b = g_malloc0(sizeof(icon));
b->size = 16;
// Initialize widget.
widget_init ( WIDGET ( b ), parent, WIDGET_TYPE_UNKNOWN, name );
b->widget.draw = icon_draw;
b->widget.free = icon_free;
b->widget.resize = icon_resize;
b->widget.get_desired_height = icon_get_desired_height;
b->widget.get_desired_width = icon_get_desired_width;
b->size = 16;
// Initialize widget.
widget_init(WIDGET(b), parent, WIDGET_TYPE_UNKNOWN, name);
b->widget.draw = icon_draw;
b->widget.free = icon_free;
b->widget.resize = icon_resize;
b->widget.get_desired_height = icon_get_desired_height;
b->widget.get_desired_width = icon_get_desired_width;
RofiDistance d = rofi_theme_get_distance ( WIDGET ( b ), "size", b->size );
b->size = distance_get_pixel ( d, ROFI_ORIENTATION_VERTICAL );
RofiDistance d = rofi_theme_get_distance(WIDGET(b), "size", b->size);
b->size = distance_get_pixel(d, ROFI_ORIENTATION_VERTICAL);
b->squared = rofi_theme_get_boolean ( WIDGET ( b ), "squared", TRUE );
b->squared = rofi_theme_get_boolean(WIDGET(b), "squared", TRUE);
const char * filename = rofi_theme_get_string ( WIDGET ( b ), "filename", NULL );
if ( filename ) {
b->icon_fetch_id = rofi_icon_fetcher_query ( filename, b->size );
}
b->yalign = rofi_theme_get_double ( WIDGET ( b ), "vertical-align", 0.5 );
b->yalign = MAX ( 0, MIN ( 1.0, b->yalign ) );
b->xalign = rofi_theme_get_double ( WIDGET ( b ), "horizontal-align", 0.5 );
b->xalign = MAX ( 0, MIN ( 1.0, b->xalign ) );
const char *filename = rofi_theme_get_string(WIDGET(b), "filename", NULL);
if (filename) {
b->icon_fetch_id = rofi_icon_fetcher_query(filename, b->size);
}
b->yalign = rofi_theme_get_double(WIDGET(b), "vertical-align", 0.5);
b->yalign = MAX(0, MIN(1.0, b->yalign));
b->xalign = rofi_theme_get_double(WIDGET(b), "horizontal-align", 0.5);
b->xalign = MAX(0, MIN(1.0, b->xalign));
return b;
return b;
}

File diff suppressed because it is too large Load diff

View file

@ -25,130 +25,125 @@
*
*/
#include <config.h>
#include <xkbcommon/xkbcommon.h>
#include <glib.h>
#include "widgets/textbox.h"
#include "widgets/scrollbar.h"
#include "widgets/icon.h"
#include "widgets/listview.h"
#include "widgets/scrollbar.h"
#include "widgets/textbox.h"
#include <glib.h>
#include <xkbcommon/xkbcommon.h>
#include "theme.h"
/** The default width of the scrollbar */
#define DEFAULT_SCROLLBAR_WIDTH 8
#define DEFAULT_SCROLLBAR_WIDTH 8
static void scrollbar_draw ( widget *, cairo_t * );
static void scrollbar_free ( widget * );
static void scrollbar_draw(widget *, cairo_t *);
static void scrollbar_free(widget *);
static int scrollbar_get_desired_height ( widget *wid )
{
// Want height we are.
return wid->h;
static int scrollbar_get_desired_height(widget *wid) {
// Want height we are.
return wid->h;
}
// TODO
// This should behave more like a real scrollbar.
guint scrollbar_scroll_get_line ( const scrollbar *sb, int y )
{
y -= sb->widget.border.top.base.distance;
if ( y < 0 ) {
return 0;
}
guint scrollbar_scroll_get_line(const scrollbar *sb, int y) {
y -= sb->widget.border.top.base.distance;
if (y < 0) {
return 0;
}
if ( y > sb->widget.h ) {
return sb->length - 1;
}
if (y > sb->widget.h) {
return sb->length - 1;
}
short r = ( sb->length * sb->widget.h ) / ( (double) ( sb->length + sb->pos_length ) );
short handle = sb->widget.h - r;
double sec = ( ( r ) / (double) ( sb->length - 1 ) );
short half_handle = handle / 2;
y -= half_handle;
y = MIN ( MAX ( 0, y ), sb->widget.h - 2 * half_handle );
short r =
(sb->length * sb->widget.h) / ((double)(sb->length + sb->pos_length));
short handle = sb->widget.h - r;
double sec = ((r) / (double)(sb->length - 1));
short half_handle = handle / 2;
y -= half_handle;
y = MIN(MAX(0, y), sb->widget.h - 2 * half_handle);
unsigned int sel = ( ( y ) / sec );
return MIN ( sel, sb->length - 1 );
unsigned int sel = ((y) / sec);
return MIN(sel, sb->length - 1);
}
static void scrollbar_scroll ( scrollbar *sb, int y )
{
listview_set_selected ( (listview *) sb->widget.parent, scrollbar_scroll_get_line ( sb, y ) );
static void scrollbar_scroll(scrollbar *sb, int y) {
listview_set_selected((listview *)sb->widget.parent,
scrollbar_scroll_get_line(sb, y));
}
static WidgetTriggerActionResult scrollbar_trigger_action ( widget *wid, MouseBindingMouseDefaultAction action, G_GNUC_UNUSED gint x, gint y, G_GNUC_UNUSED void *user_data )
{
scrollbar *sb = (scrollbar *) wid;
switch ( action )
{
case MOUSE_CLICK_DOWN:
return WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_BEGIN;
case MOUSE_CLICK_UP:
scrollbar_scroll ( sb, y );
return WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_END;
case MOUSE_DCLICK_DOWN:
case MOUSE_DCLICK_UP:
break;
}
return FALSE;
static WidgetTriggerActionResult
scrollbar_trigger_action(widget *wid, MouseBindingMouseDefaultAction action,
G_GNUC_UNUSED gint x, gint y,
G_GNUC_UNUSED void *user_data) {
scrollbar *sb = (scrollbar *)wid;
switch (action) {
case MOUSE_CLICK_DOWN:
return WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_BEGIN;
case MOUSE_CLICK_UP:
scrollbar_scroll(sb, y);
return WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_END;
case MOUSE_DCLICK_DOWN:
case MOUSE_DCLICK_UP:
break;
}
return FALSE;
}
static gboolean scrollbar_motion_notify ( widget *wid, G_GNUC_UNUSED gint x, gint y )
{
scrollbar *sb = (scrollbar *) wid;
scrollbar_scroll ( sb, y );
return TRUE;
static gboolean scrollbar_motion_notify(widget *wid, G_GNUC_UNUSED gint x,
gint y) {
scrollbar *sb = (scrollbar *)wid;
scrollbar_scroll(sb, y);
return TRUE;
}
scrollbar *scrollbar_create ( widget *parent, const char *name )
{
scrollbar *sb = g_malloc0 ( sizeof ( scrollbar ) );
widget_init ( WIDGET ( sb ), parent, WIDGET_TYPE_SCROLLBAR, name );
sb->widget.x = 0;
sb->widget.y = 0;
sb->width = rofi_theme_get_distance ( WIDGET ( sb ), "handle-width", DEFAULT_SCROLLBAR_WIDTH );
int width = distance_get_pixel ( sb->width, ROFI_ORIENTATION_HORIZONTAL );
sb->widget.w = widget_padding_get_padding_width ( WIDGET ( sb ) ) + width;
sb->widget.h = widget_padding_get_padding_height ( WIDGET ( sb ) );
scrollbar *scrollbar_create(widget *parent, const char *name) {
scrollbar *sb = g_malloc0(sizeof(scrollbar));
widget_init(WIDGET(sb), parent, WIDGET_TYPE_SCROLLBAR, name);
sb->widget.x = 0;
sb->widget.y = 0;
sb->width = rofi_theme_get_distance(WIDGET(sb), "handle-width",
DEFAULT_SCROLLBAR_WIDTH);
int width = distance_get_pixel(sb->width, ROFI_ORIENTATION_HORIZONTAL);
sb->widget.w = widget_padding_get_padding_width(WIDGET(sb)) + width;
sb->widget.h = widget_padding_get_padding_height(WIDGET(sb));
sb->widget.draw = scrollbar_draw;
sb->widget.free = scrollbar_free;
sb->widget.trigger_action = scrollbar_trigger_action;
sb->widget.motion_notify = scrollbar_motion_notify;
sb->widget.get_desired_height = scrollbar_get_desired_height;
sb->widget.draw = scrollbar_draw;
sb->widget.free = scrollbar_free;
sb->widget.trigger_action = scrollbar_trigger_action;
sb->widget.motion_notify = scrollbar_motion_notify;
sb->widget.get_desired_height = scrollbar_get_desired_height;
sb->length = 10;
sb->pos = 0;
sb->pos_length = 4;
sb->length = 10;
sb->pos = 0;
sb->pos_length = 4;
return sb;
return sb;
}
static void scrollbar_free ( widget *wid )
{
scrollbar *sb = (scrollbar *) wid;
g_free ( sb );
static void scrollbar_free(widget *wid) {
scrollbar *sb = (scrollbar *)wid;
g_free(sb);
}
void scrollbar_set_max_value ( scrollbar *sb, unsigned int max )
{
if ( sb != NULL ) {
sb->length = MAX ( 1u, max );
}
void scrollbar_set_max_value(scrollbar *sb, unsigned int max) {
if (sb != NULL) {
sb->length = MAX(1u, max);
}
}
void scrollbar_set_handle ( scrollbar *sb, unsigned int pos )
{
if ( sb != NULL ) {
sb->pos = MIN ( sb->length, pos );
}
void scrollbar_set_handle(scrollbar *sb, unsigned int pos) {
if (sb != NULL) {
sb->pos = MIN(sb->length, pos);
}
}
void scrollbar_set_handle_length ( scrollbar *sb, unsigned int pos_length )
{
if ( sb != NULL ) {
sb->pos_length = MIN ( sb->length, MAX ( 1u, pos_length ) );
}
void scrollbar_set_handle_length(scrollbar *sb, unsigned int pos_length) {
if (sb != NULL) {
sb->pos_length = MIN(sb->length, MAX(1u, pos_length));
}
}
/**
@ -163,27 +158,24 @@ void scrollbar_set_handle_length ( scrollbar *sb, unsigned int pos_length )
* r ( num+hl ) = num*h
* r = (num*h)/(num+hl)
*/
static void scrollbar_draw ( widget *wid, cairo_t *draw )
{
scrollbar *sb = (scrollbar *) wid;
unsigned int wh = widget_padding_get_remaining_height ( wid );
// Calculate position and size.
unsigned int r = ( sb->length * wh ) / ( (double) ( sb->length + sb->pos_length ) );
unsigned int handle = wid->h - r;
double sec = ( ( r ) / (double) ( sb->length - 1 ) );
unsigned int height = handle;
unsigned int y = sb->pos * sec;
// Set max pos.
y = MIN ( y, wh - handle );
// Never go out of bar.
height = MAX ( 2, height );
// Cap length;
rofi_theme_get_color ( WIDGET ( sb ), "handle-color", draw );
static void scrollbar_draw(widget *wid, cairo_t *draw) {
scrollbar *sb = (scrollbar *)wid;
unsigned int wh = widget_padding_get_remaining_height(wid);
// Calculate position and size.
unsigned int r = (sb->length * wh) / ((double)(sb->length + sb->pos_length));
unsigned int handle = wid->h - r;
double sec = ((r) / (double)(sb->length - 1));
unsigned int height = handle;
unsigned int y = sb->pos * sec;
// Set max pos.
y = MIN(y, wh - handle);
// Never go out of bar.
height = MAX(2, height);
// Cap length;
rofi_theme_get_color(WIDGET(sb), "handle-color", draw);
cairo_rectangle ( draw,
widget_padding_get_left ( wid ),
widget_padding_get_top ( wid ) + y,
widget_padding_get_remaining_width ( wid ),
height );
cairo_fill ( draw );
cairo_rectangle(draw, widget_padding_get_left(wid),
widget_padding_get_top(wid) + y,
widget_padding_get_remaining_width(wid), height);
cairo_fill(draw);
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff