[Cleanup] Using clang-tidy

This commit is contained in:
Dave Davenport 2021-08-18 01:16:45 +02:00 committed by Dave Davenport
parent 9a62c5bc1a
commit 28b5bb8b78
41 changed files with 13115 additions and 12950 deletions

View File

@ -1,6 +1,7 @@
#ifndef ROFI_INCLUDE_CSS_COLORS_H #ifndef ROFI_INCLUDE_CSS_COLORS_H
#define ROFI_INCLUDE_CSS_COLORS_H #define ROFI_INCLUDE_CSS_COLORS_H
#include <stdint.h>
/** /**
* @defgroup CSSCOLORS CssColors * @defgroup CSSCOLORS CssColors
* @ingroup HELPERS * @ingroup HELPERS
@ -13,16 +14,16 @@
/** /**
* Structure of colors. * Structure of colors.
*/ */
typedef struct CSSColor typedef struct CSSColor {
{ /** CSS name of the color. */
/** CSS name of the color. */ char *name;
char *name; /** BGRA 8 bit color components. */
/** BGRA 8 bit color components. */ uint8_t b, g, r, a;
uint8_t b, g, r, a; } CSSColor;
}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[]; extern const CSSColor CSSColors[];
/** /**

View File

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

View File

@ -27,7 +27,7 @@
#ifndef ROFI_DIALOG_FILE_BROWSER_H #ifndef ROFI_DIALOG_FILE_BROWSER_H
#define ROFI_DIALOG_FILE_BROWSER_H #define ROFI_DIALOG_FILE_BROWSER_H
#include "mode.h"
/** /**
* @defgroup FileBrowserMode FileBrowser * @defgroup FileBrowserMode FileBrowser
* @ingroup MODES * @ingroup MODES
@ -42,7 +42,7 @@ extern Mode file_browser_mode;
* Create a new filebrowser. * Create a new filebrowser.
* @returns a new filebrowser structure. * @returns a new filebrowser structure.
*/ */
Mode *create_new_file_browser ( void ); Mode *create_new_file_browser(void);
/** /**
* @param sw Mode object. * @param sw Mode object.
* @param mretv return value passed in. * @param mretv return value passed in.
@ -52,6 +52,7 @@ Mode *create_new_file_browser ( void );
* *
* @returns the state the user selected. * @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 #endif // ROFI_DIALOG_FILE_BROWSER_H

View File

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

View File

@ -28,6 +28,8 @@
#ifndef ROFI_DIALOG_SCRIPT_H #ifndef ROFI_DIALOG_SCRIPT_H
#define ROFI_DIALOG_SCRIPT_H #define ROFI_DIALOG_SCRIPT_H
#include "mode.h"
/** /**
* @defgroup SCRIPTMode Script * @defgroup SCRIPTMode Script
* @ingroup MODES * @ingroup MODES
@ -42,7 +44,7 @@
* *
* @returns NULL when it fails, a newly allocated ScriptOptions when successful. * @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 * @param token The modi str to check
@ -51,6 +53,6 @@ Mode *script_switcher_parse_setup ( const char *str );
* *
* @returns true when valid. * @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 #endif // ROFI_DIALOG_SCRIPT_H

View File

@ -27,7 +27,7 @@
#ifndef ROFI_DIALOG_SSH_H #ifndef ROFI_DIALOG_SSH_H
#define ROFI_DIALOG_SSH_H #define ROFI_DIALOG_SSH_H
#include "mode.h"
/** /**
* @defgroup SSHMode SSH * @defgroup SSHMode SSH
* @ingroup MODES * @ingroup MODES

View File

@ -28,13 +28,14 @@
#ifndef ROFI_DIALOG_WINDOW_H #ifndef ROFI_DIALOG_WINDOW_H
#define ROFI_DIALOG_WINDOW_H #define ROFI_DIALOG_WINDOW_H
#include "mode.h"
/** /**
* @defgroup WINDOWMode Window * @defgroup WINDOWMode Window
* @ingroup MODES * @ingroup MODES
* *
* @{ * @{
*/ */
#include <config.h>
#ifdef WINDOW_MODE #ifdef WINDOW_MODE
extern Mode window_mode; extern Mode window_mode;

View File

@ -28,9 +28,9 @@
#ifndef ROFI_DISPLAY_H #ifndef ROFI_DISPLAY_H
#define ROFI_DISPLAY_H #define ROFI_DISPLAY_H
#include <glib.h>
#include "helper.h" #include "helper.h"
#include "nkutils-bindings.h" #include "nkutils-bindings.h"
#include <glib.h>
/** /**
* @param main_loop The GMainLoop * @param main_loop The GMainLoop
@ -40,29 +40,29 @@
* *
* @returns Whether the setup succeeded or not * @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 * Do some late setup of the display backend
* *
* @returns Whether the setup succeeded or not * @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 * Do some early cleanup, like unmapping the surface
*/ */
void display_early_cleanup ( void ); void display_early_cleanup(void);
/** /**
* Cleanup any remaining display related stuff * Cleanup any remaining display related stuff
*/ */
void display_cleanup ( void ); void display_cleanup(void);
/** /**
* Dumps the display layout for -help output * 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 * @param context The startup notification context for the application to launch
@ -71,6 +71,8 @@ void display_dump_monitor_layout ( void );
* *
* Provides the needed child setup function * 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);
#endif #endif

View File

@ -27,8 +27,8 @@
#ifndef ROFI_HELPER_H #ifndef ROFI_HELPER_H
#define ROFI_HELPER_H #define ROFI_HELPER_H
#include <cairo.h>
#include "rofi-types.h" #include "rofi-types.h"
#include <cairo.h>
G_BEGIN_DECLS G_BEGIN_DECLS
/** /**
@ -51,7 +51,7 @@ G_BEGIN_DECLS
* *
* @returns TRUE when successful, FALSE when failed. * @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. * @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 * @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 * @param tokens Array of regex objects
* *
* Frees the array of matching 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 * @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. * @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 * @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. * @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 * @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. * @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 * @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. * @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 * @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. * @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 * @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. * @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. * @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 * @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. * @param cmd The command to execute.
* *
* Execute cmd using config.run_command and outputs the result (stdout) to the opened file * Execute cmd using config.run_command and outputs the result (stdout) to the
* descriptor. * opened file descriptor.
* *
* @returns a valid file descriptor on success, or -1 on failure. * @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. * @param pidfile The pidfile to create.
* *
* returns file descriptor (or -1 when failed) * returns file descriptor (or -1 when failed)
*/ */
int create_pid_file ( const char *pidfile ); int create_pid_file(const char *pidfile);
/** /**
* Remove pid file * 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. * Do some input validation, especially the first few could break things.
* It is good to catch them beforehand. * 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. * @param arg string to parse.
@ -174,7 +175,7 @@ int config_sanity_check ( void );
* *
* @returns character. * @returns character.
*/ */
char helper_parse_char ( const char *arg ); char helper_parse_char(const char *arg);
/** /**
* @param argc number of arguments. * @param argc number of arguments.
@ -182,7 +183,7 @@ char helper_parse_char ( const char *arg );
* *
* Set the application arguments. * 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 * @param input The path to expand
@ -191,7 +192,7 @@ void cmd_set_arguments ( int argc, char **argv );
* *
* @returns path * @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 * @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 * @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 data the unvalidated character array holding possible UTF-8 data
* @param length the length of the data array * @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 * @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 * @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 * @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 * @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 * @return the escaped string
*/ */
gchar *rofi_escape_markup ( gchar *text ); gchar *rofi_escape_markup(gchar *text);
/** /**
* @param pattern The user input to match against. * @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 str The input to match against pattern.
* @param slen Length of str. * @param slen Length of str.
* *
* rofi_scorer_fuzzy_evaluate implements a global sequence alignment algorithm to find the maximum accumulated score by * rofi_scorer_fuzzy_evaluate implements a global sequence alignment algorithm
* aligning `pattern` to `str`. It applies when `pattern` is a subsequence of `str`. * to find the maximum accumulated score by aligning `pattern` to `str`. It
* applies when `pattern` is a subsequence of `str`.
* *
* Scoring criteria * 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. * - 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. * - The first characters of words of `pattern` receive bonus because they
* See PATTERN_START_MULTIPLIER/PATTERN_NON_START_MULTIPLIER. * usually have more significance than the rest. See
* - Superfluous characters in `str` will reduce the score (gap penalty). See GAP_SCORE. * PATTERN_START_MULTIPLIER/PATTERN_NON_START_MULTIPLIER.
* - Prefer early occurrence of the first character. See LEADING_GAP_SCORE/GAP_SCORE. * - 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: * The recurrence of the dynamic programming:
* dp[i][j]: maximum accumulated score by aligning pattern[0..i] to str[0..j] * 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[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 * The first dimension can be suppressed since we do not need a matching
* O(N*M) to O(M) * scheme, which reduces the space complexity from O(N*M) to O(M)
* *
* @returns the sorting weight. * @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. * 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` * @returns less than, equal to, or greater than zero if the first `n`
* are found, respectively, to be less than, to match, or be greater than the first `n` * characters (not bytes) of `a` are found, respectively, to be less than, to
* characters (not bytes) of `b`. * 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 * The startup notification context of the application to launch
*/ */
typedef struct typedef struct {
{ /** The name of the application */
/** The name of the application */ const gchar *name;
const gchar *name; /** The binary name of the application */
/** The binary name of the application */ const gchar *binary;
const gchar *binary; /** The description of the launch */
/** The description of the launch */ const gchar *description;
const gchar *description; /** The icon name of the application */
/** The icon name of the application */ const gchar *icon;
const gchar *icon; /** The application id (desktop file with the .desktop suffix) */
/** The application id (desktop file with the .desktop suffix) */ const gchar *app_id;
const gchar *app_id; /** The window manager class of the application */
/** The window manager class of the application */ const gchar *wmclass;
const gchar *wmclass; /** The command we run */
/** The command we run */ const gchar *command;
const gchar *command;
} RofiHelperExecuteContext; } RofiHelperExecuteContext;
/** /**
@ -309,7 +319,9 @@ typedef struct
* *
* @returns TRUE when successful, FALSE when failed. * @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) * @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 * @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 * @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 * @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. * Ranges.
@ -344,7 +359,7 @@ cairo_surface_t *cairo_image_surface_create_from_svg ( const gchar* file, int he
* *
* ranges * 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. * @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.
* * F: Print the entered filter, quoted * * F: Print the entered filter, quoted
* *
* This functions outputs the formatted string to stdout, appends a newline (\n) character and * This functions outputs the formatted string to stdout, appends a newline (\n)
* calls flush on the file descriptor. * 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 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. * Items {key} are replaced by the value if '{key}' is passed as key/value pair,
* If the {key} is in between [] all the text between [] are removed if {key} * otherwise removed from string. If the {key} is in between [] all the text
* is not found. Otherwise key is replaced and [ & ] removed. * 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 * This allows for optional replacement, f.e. '{ssh-client} [-t {title}] -e
* "{cmd}"' the '-t {title}' is only there if {title} is set. * "{cmd}"' the '-t {title}' is only there if {title} is set.
* *
* @returns a new string with the keys replaced. * @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. * @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. * @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 G_END_DECLS

View File

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

View File

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

View File

@ -29,6 +29,7 @@
#define ROFI_HBOX_H #define ROFI_HBOX_H
#include "widget.h" #include "widget.h"
#include "rofi-types.h"
/** /**
* @defgroup box box * @defgroup box box

View File

@ -28,6 +28,8 @@
#ifndef ROFI_LISTVIEW_H #ifndef ROFI_LISTVIEW_H
#define ROFI_LISTVIEW_H #define ROFI_LISTVIEW_H
#include "widgets/textbox.h"
/** /**
* @defgroup listview listview * @defgroup listview listview
* @ingroup widget * @ingroup widget

View File

@ -1,154 +1,152 @@
#include <stdint.h>
#include "css-colors.h" #include "css-colors.h"
const CSSColor CSSColors[] = { const CSSColor CSSColors[] = {
{ .name = "AliceBlue", .r = 0xF0, .g = 0xF8, .b = 0xFF }, {.name = "AliceBlue", .r = 0xF0, .g = 0xF8, .b = 0xFF},
{ .name = "AntiqueWhite", .r = 0xFA, .g = 0xEB, .b = 0xD7 }, {.name = "AntiqueWhite", .r = 0xFA, .g = 0xEB, .b = 0xD7},
{ .name = "Aqua", .r = 0x00, .g = 0xFF, .b = 0xFF }, {.name = "Aqua", .r = 0x00, .g = 0xFF, .b = 0xFF},
{ .name = "Aquamarine", .r = 0x7F, .g = 0xFF, .b = 0xD4 }, {.name = "Aquamarine", .r = 0x7F, .g = 0xFF, .b = 0xD4},
{ .name = "Azure", .r = 0xF0, .g = 0xFF, .b = 0xFF }, {.name = "Azure", .r = 0xF0, .g = 0xFF, .b = 0xFF},
{ .name = "Beige", .r = 0xF5, .g = 0xF5, .b = 0xDC }, {.name = "Beige", .r = 0xF5, .g = 0xF5, .b = 0xDC},
{ .name = "Bisque", .r = 0xFF, .g = 0xE4, .b = 0xC4 }, {.name = "Bisque", .r = 0xFF, .g = 0xE4, .b = 0xC4},
{ .name = "Black", .r = 0x00, .g = 0x00, .b = 0x00 }, {.name = "Black", .r = 0x00, .g = 0x00, .b = 0x00},
{ .name = "BlanchedAlmond", .r = 0xFF, .g = 0xEB, .b = 0xCD }, {.name = "BlanchedAlmond", .r = 0xFF, .g = 0xEB, .b = 0xCD},
{ .name = "Blue", .r = 0x00, .g = 0x00, .b = 0xFF }, {.name = "Blue", .r = 0x00, .g = 0x00, .b = 0xFF},
{ .name = "BlueViolet", .r = 0x8A, .g = 0x2B, .b = 0xE2 }, {.name = "BlueViolet", .r = 0x8A, .g = 0x2B, .b = 0xE2},
{ .name = "Brown", .r = 0xA5, .g = 0x2A, .b = 0x2A }, {.name = "Brown", .r = 0xA5, .g = 0x2A, .b = 0x2A},
{ .name = "BurlyWood", .r = 0xDE, .g = 0xB8, .b = 0x87 }, {.name = "BurlyWood", .r = 0xDE, .g = 0xB8, .b = 0x87},
{ .name = "CadetBlue", .r = 0x5F, .g = 0x9E, .b = 0xA0 }, {.name = "CadetBlue", .r = 0x5F, .g = 0x9E, .b = 0xA0},
{ .name = "Chartreuse", .r = 0x7F, .g = 0xFF, .b = 0x00 }, {.name = "Chartreuse", .r = 0x7F, .g = 0xFF, .b = 0x00},
{ .name = "Chocolate", .r = 0xD2, .g = 0x69, .b = 0x1E }, {.name = "Chocolate", .r = 0xD2, .g = 0x69, .b = 0x1E},
{ .name = "Coral", .r = 0xFF, .g = 0x7F, .b = 0x50 }, {.name = "Coral", .r = 0xFF, .g = 0x7F, .b = 0x50},
{ .name = "CornflowerBlue", .r = 0x64, .g = 0x95, .b = 0xED }, {.name = "CornflowerBlue", .r = 0x64, .g = 0x95, .b = 0xED},
{ .name = "Cornsilk", .r = 0xFF, .g = 0xF8, .b = 0xDC }, {.name = "Cornsilk", .r = 0xFF, .g = 0xF8, .b = 0xDC},
{ .name = "Crimson", .r = 0xDC, .g = 0x14, .b = 0x3C }, {.name = "Crimson", .r = 0xDC, .g = 0x14, .b = 0x3C},
{ .name = "Cyan", .r = 0x00, .g = 0xFF, .b = 0xFF }, {.name = "Cyan", .r = 0x00, .g = 0xFF, .b = 0xFF},
{ .name = "DarkBlue", .r = 0x00, .g = 0x00, .b = 0x8B }, {.name = "DarkBlue", .r = 0x00, .g = 0x00, .b = 0x8B},
{ .name = "DarkCyan", .r = 0x00, .g = 0x8B, .b = 0x8B }, {.name = "DarkCyan", .r = 0x00, .g = 0x8B, .b = 0x8B},
{ .name = "DarkGoldenRod", .r = 0xB8, .g = 0x86, .b = 0x0B }, {.name = "DarkGoldenRod", .r = 0xB8, .g = 0x86, .b = 0x0B},
{ .name = "DarkGray", .r = 0xA9, .g = 0xA9, .b = 0xA9 }, {.name = "DarkGray", .r = 0xA9, .g = 0xA9, .b = 0xA9},
{ .name = "DarkGrey", .r = 0xA9, .g = 0xA9, .b = 0xA9 }, {.name = "DarkGrey", .r = 0xA9, .g = 0xA9, .b = 0xA9},
{ .name = "DarkGreen", .r = 0x00, .g = 0x64, .b = 0x00 }, {.name = "DarkGreen", .r = 0x00, .g = 0x64, .b = 0x00},
{ .name = "DarkKhaki", .r = 0xBD, .g = 0xB7, .b = 0x6B }, {.name = "DarkKhaki", .r = 0xBD, .g = 0xB7, .b = 0x6B},
{ .name = "DarkMagenta", .r = 0x8B, .g = 0x00, .b = 0x8B }, {.name = "DarkMagenta", .r = 0x8B, .g = 0x00, .b = 0x8B},
{ .name = "DarkOliveGreen", .r = 0x55, .g = 0x6B, .b = 0x2F }, {.name = "DarkOliveGreen", .r = 0x55, .g = 0x6B, .b = 0x2F},
{ .name = "DarkOrange", .r = 0xFF, .g = 0x8C, .b = 0x00 }, {.name = "DarkOrange", .r = 0xFF, .g = 0x8C, .b = 0x00},
{ .name = "DarkOrchid", .r = 0x99, .g = 0x32, .b = 0xCC }, {.name = "DarkOrchid", .r = 0x99, .g = 0x32, .b = 0xCC},
{ .name = "DarkRed", .r = 0x8B, .g = 0x00, .b = 0x00 }, {.name = "DarkRed", .r = 0x8B, .g = 0x00, .b = 0x00},
{ .name = "DarkSalmon", .r = 0xE9, .g = 0x96, .b = 0x7A }, {.name = "DarkSalmon", .r = 0xE9, .g = 0x96, .b = 0x7A},
{ .name = "DarkSeaGreen", .r = 0x8F, .g = 0xBC, .b = 0x8F }, {.name = "DarkSeaGreen", .r = 0x8F, .g = 0xBC, .b = 0x8F},
{ .name = "DarkSlateBlue", .r = 0x48, .g = 0x3D, .b = 0x8B }, {.name = "DarkSlateBlue", .r = 0x48, .g = 0x3D, .b = 0x8B},
{ .name = "DarkSlateGray", .r = 0x2F, .g = 0x4F, .b = 0x4F }, {.name = "DarkSlateGray", .r = 0x2F, .g = 0x4F, .b = 0x4F},
{ .name = "DarkSlateGrey", .r = 0x2F, .g = 0x4F, .b = 0x4F }, {.name = "DarkSlateGrey", .r = 0x2F, .g = 0x4F, .b = 0x4F},
{ .name = "DarkTurquoise", .r = 0x00, .g = 0xCE, .b = 0xD1 }, {.name = "DarkTurquoise", .r = 0x00, .g = 0xCE, .b = 0xD1},
{ .name = "DarkViolet", .r = 0x94, .g = 0x00, .b = 0xD3 }, {.name = "DarkViolet", .r = 0x94, .g = 0x00, .b = 0xD3},
{ .name = "DeepPink", .r = 0xFF, .g = 0x14, .b = 0x93 }, {.name = "DeepPink", .r = 0xFF, .g = 0x14, .b = 0x93},
{ .name = "DeepSkyBlue", .r = 0x00, .g = 0xBF, .b = 0xFF }, {.name = "DeepSkyBlue", .r = 0x00, .g = 0xBF, .b = 0xFF},
{ .name = "DimGray", .r = 0x69, .g = 0x69, .b = 0x69 }, {.name = "DimGray", .r = 0x69, .g = 0x69, .b = 0x69},
{ .name = "DimGrey", .r = 0x69, .g = 0x69, .b = 0x69 }, {.name = "DimGrey", .r = 0x69, .g = 0x69, .b = 0x69},
{ .name = "DodgerBlue", .r = 0x1E, .g = 0x90, .b = 0xFF }, {.name = "DodgerBlue", .r = 0x1E, .g = 0x90, .b = 0xFF},
{ .name = "FireBrick", .r = 0xB2, .g = 0x22, .b = 0x22 }, {.name = "FireBrick", .r = 0xB2, .g = 0x22, .b = 0x22},
{ .name = "FloralWhite", .r = 0xFF, .g = 0xFA, .b = 0xF0 }, {.name = "FloralWhite", .r = 0xFF, .g = 0xFA, .b = 0xF0},
{ .name = "ForestGreen", .r = 0x22, .g = 0x8B, .b = 0x22 }, {.name = "ForestGreen", .r = 0x22, .g = 0x8B, .b = 0x22},
{ .name = "Fuchsia", .r = 0xFF, .g = 0x00, .b = 0xFF }, {.name = "Fuchsia", .r = 0xFF, .g = 0x00, .b = 0xFF},
{ .name = "Gainsboro", .r = 0xDC, .g = 0xDC, .b = 0xDC }, {.name = "Gainsboro", .r = 0xDC, .g = 0xDC, .b = 0xDC},
{ .name = "GhostWhite", .r = 0xF8, .g = 0xF8, .b = 0xFF }, {.name = "GhostWhite", .r = 0xF8, .g = 0xF8, .b = 0xFF},
{ .name = "Gold", .r = 0xFF, .g = 0xD7, .b = 0x00 }, {.name = "Gold", .r = 0xFF, .g = 0xD7, .b = 0x00},
{ .name = "GoldenRod", .r = 0xDA, .g = 0xA5, .b = 0x20 }, {.name = "GoldenRod", .r = 0xDA, .g = 0xA5, .b = 0x20},
{ .name = "Gray", .r = 0x80, .g = 0x80, .b = 0x80 }, {.name = "Gray", .r = 0x80, .g = 0x80, .b = 0x80},
{ .name = "Grey", .r = 0x80, .g = 0x80, .b = 0x80 }, {.name = "Grey", .r = 0x80, .g = 0x80, .b = 0x80},
{ .name = "Green", .r = 0x00, .g = 0x80, .b = 0x00 }, {.name = "Green", .r = 0x00, .g = 0x80, .b = 0x00},
{ .name = "GreenYellow", .r = 0xAD, .g = 0xFF, .b = 0x2F }, {.name = "GreenYellow", .r = 0xAD, .g = 0xFF, .b = 0x2F},
{ .name = "HoneyDew", .r = 0xF0, .g = 0xFF, .b = 0xF0 }, {.name = "HoneyDew", .r = 0xF0, .g = 0xFF, .b = 0xF0},
{ .name = "HotPink", .r = 0xFF, .g = 0x69, .b = 0xB4 }, {.name = "HotPink", .r = 0xFF, .g = 0x69, .b = 0xB4},
{ .name = "IndianRed", .r = 0xCD, .g = 0x5C, .b = 0x5C }, {.name = "IndianRed", .r = 0xCD, .g = 0x5C, .b = 0x5C},
{ .name = "Indigo", .r = 0x4B, .g = 0x00, .b = 0x82 }, {.name = "Indigo", .r = 0x4B, .g = 0x00, .b = 0x82},
{ .name = "Ivory", .r = 0xFF, .g = 0xFF, .b = 0xF0 }, {.name = "Ivory", .r = 0xFF, .g = 0xFF, .b = 0xF0},
{ .name = "Khaki", .r = 0xF0, .g = 0xE6, .b = 0x8C }, {.name = "Khaki", .r = 0xF0, .g = 0xE6, .b = 0x8C},
{ .name = "Lavender", .r = 0xE6, .g = 0xE6, .b = 0xFA }, {.name = "Lavender", .r = 0xE6, .g = 0xE6, .b = 0xFA},
{ .name = "LavenderBlush", .r = 0xFF, .g = 0xF0, .b = 0xF5 }, {.name = "LavenderBlush", .r = 0xFF, .g = 0xF0, .b = 0xF5},
{ .name = "LawnGreen", .r = 0x7C, .g = 0xFC, .b = 0x00 }, {.name = "LawnGreen", .r = 0x7C, .g = 0xFC, .b = 0x00},
{ .name = "LemonChiffon", .r = 0xFF, .g = 0xFA, .b = 0xCD }, {.name = "LemonChiffon", .r = 0xFF, .g = 0xFA, .b = 0xCD},
{ .name = "LightBlue", .r = 0xAD, .g = 0xD8, .b = 0xE6 }, {.name = "LightBlue", .r = 0xAD, .g = 0xD8, .b = 0xE6},
{ .name = "LightCoral", .r = 0xF0, .g = 0x80, .b = 0x80 }, {.name = "LightCoral", .r = 0xF0, .g = 0x80, .b = 0x80},
{ .name = "LightCyan", .r = 0xE0, .g = 0xFF, .b = 0xFF }, {.name = "LightCyan", .r = 0xE0, .g = 0xFF, .b = 0xFF},
{ .name = "LightGoldenRodYellow", .r = 0xFA, .g = 0xFA, .b = 0xD2 }, {.name = "LightGoldenRodYellow", .r = 0xFA, .g = 0xFA, .b = 0xD2},
{ .name = "LightGray", .r = 0xD3, .g = 0xD3, .b = 0xD3 }, {.name = "LightGray", .r = 0xD3, .g = 0xD3, .b = 0xD3},
{ .name = "LightGrey", .r = 0xD3, .g = 0xD3, .b = 0xD3 }, {.name = "LightGrey", .r = 0xD3, .g = 0xD3, .b = 0xD3},
{ .name = "LightGreen", .r = 0x90, .g = 0xEE, .b = 0x90 }, {.name = "LightGreen", .r = 0x90, .g = 0xEE, .b = 0x90},
{ .name = "LightPink", .r = 0xFF, .g = 0xB6, .b = 0xC1 }, {.name = "LightPink", .r = 0xFF, .g = 0xB6, .b = 0xC1},
{ .name = "LightSalmon", .r = 0xFF, .g = 0xA0, .b = 0x7A }, {.name = "LightSalmon", .r = 0xFF, .g = 0xA0, .b = 0x7A},
{ .name = "LightSeaGreen", .r = 0x20, .g = 0xB2, .b = 0xAA }, {.name = "LightSeaGreen", .r = 0x20, .g = 0xB2, .b = 0xAA},
{ .name = "LightSkyBlue", .r = 0x87, .g = 0xCE, .b = 0xFA }, {.name = "LightSkyBlue", .r = 0x87, .g = 0xCE, .b = 0xFA},
{ .name = "LightSlateGray", .r = 0x77, .g = 0x88, .b = 0x99 }, {.name = "LightSlateGray", .r = 0x77, .g = 0x88, .b = 0x99},
{ .name = "LightSlateGrey", .r = 0x77, .g = 0x88, .b = 0x99 }, {.name = "LightSlateGrey", .r = 0x77, .g = 0x88, .b = 0x99},
{ .name = "LightSteelBlue", .r = 0xB0, .g = 0xC4, .b = 0xDE }, {.name = "LightSteelBlue", .r = 0xB0, .g = 0xC4, .b = 0xDE},
{ .name = "LightYellow", .r = 0xFF, .g = 0xFF, .b = 0xE0 }, {.name = "LightYellow", .r = 0xFF, .g = 0xFF, .b = 0xE0},
{ .name = "Lime", .r = 0x00, .g = 0xFF, .b = 0x00 }, {.name = "Lime", .r = 0x00, .g = 0xFF, .b = 0x00},
{ .name = "LimeGreen", .r = 0x32, .g = 0xCD, .b = 0x32 }, {.name = "LimeGreen", .r = 0x32, .g = 0xCD, .b = 0x32},
{ .name = "Linen", .r = 0xFA, .g = 0xF0, .b = 0xE6 }, {.name = "Linen", .r = 0xFA, .g = 0xF0, .b = 0xE6},
{ .name = "Magenta", .r = 0xFF, .g = 0x00, .b = 0xFF }, {.name = "Magenta", .r = 0xFF, .g = 0x00, .b = 0xFF},
{ .name = "Maroon", .r = 0x80, .g = 0x00, .b = 0x00 }, {.name = "Maroon", .r = 0x80, .g = 0x00, .b = 0x00},
{ .name = "MediumAquaMarine", .r = 0x66, .g = 0xCD, .b = 0xAA }, {.name = "MediumAquaMarine", .r = 0x66, .g = 0xCD, .b = 0xAA},
{ .name = "MediumBlue", .r = 0x00, .g = 0x00, .b = 0xCD }, {.name = "MediumBlue", .r = 0x00, .g = 0x00, .b = 0xCD},
{ .name = "MediumOrchid", .r = 0xBA, .g = 0x55, .b = 0xD3 }, {.name = "MediumOrchid", .r = 0xBA, .g = 0x55, .b = 0xD3},
{ .name = "MediumPurple", .r = 0x93, .g = 0x70, .b = 0xDB }, {.name = "MediumPurple", .r = 0x93, .g = 0x70, .b = 0xDB},
{ .name = "MediumSeaGreen", .r = 0x3C, .g = 0xB3, .b = 0x71 }, {.name = "MediumSeaGreen", .r = 0x3C, .g = 0xB3, .b = 0x71},
{ .name = "MediumSlateBlue", .r = 0x7B, .g = 0x68, .b = 0xEE }, {.name = "MediumSlateBlue", .r = 0x7B, .g = 0x68, .b = 0xEE},
{ .name = "MediumSpringGreen", .r = 0x00, .g = 0xFA, .b = 0x9A }, {.name = "MediumSpringGreen", .r = 0x00, .g = 0xFA, .b = 0x9A},
{ .name = "MediumTurquoise", .r = 0x48, .g = 0xD1, .b = 0xCC }, {.name = "MediumTurquoise", .r = 0x48, .g = 0xD1, .b = 0xCC},
{ .name = "MediumVioletRed", .r = 0xC7, .g = 0x15, .b = 0x85 }, {.name = "MediumVioletRed", .r = 0xC7, .g = 0x15, .b = 0x85},
{ .name = "MidnightBlue", .r = 0x19, .g = 0x19, .b = 0x70 }, {.name = "MidnightBlue", .r = 0x19, .g = 0x19, .b = 0x70},
{ .name = "MintCream", .r = 0xF5, .g = 0xFF, .b = 0xFA }, {.name = "MintCream", .r = 0xF5, .g = 0xFF, .b = 0xFA},
{ .name = "MistyRose", .r = 0xFF, .g = 0xE4, .b = 0xE1 }, {.name = "MistyRose", .r = 0xFF, .g = 0xE4, .b = 0xE1},
{ .name = "Moccasin", .r = 0xFF, .g = 0xE4, .b = 0xB5 }, {.name = "Moccasin", .r = 0xFF, .g = 0xE4, .b = 0xB5},
{ .name = "NavajoWhite", .r = 0xFF, .g = 0xDE, .b = 0xAD }, {.name = "NavajoWhite", .r = 0xFF, .g = 0xDE, .b = 0xAD},
{ .name = "Navy", .r = 0x00, .g = 0x00, .b = 0x80 }, {.name = "Navy", .r = 0x00, .g = 0x00, .b = 0x80},
{ .name = "OldLace", .r = 0xFD, .g = 0xF5, .b = 0xE6 }, {.name = "OldLace", .r = 0xFD, .g = 0xF5, .b = 0xE6},
{ .name = "Olive", .r = 0x80, .g = 0x80, .b = 0x00 }, {.name = "Olive", .r = 0x80, .g = 0x80, .b = 0x00},
{ .name = "OliveDrab", .r = 0x6B, .g = 0x8E, .b = 0x23 }, {.name = "OliveDrab", .r = 0x6B, .g = 0x8E, .b = 0x23},
{ .name = "Orange", .r = 0xFF, .g = 0xA5, .b = 0x00 }, {.name = "Orange", .r = 0xFF, .g = 0xA5, .b = 0x00},
{ .name = "OrangeRed", .r = 0xFF, .g = 0x45, .b = 0x00 }, {.name = "OrangeRed", .r = 0xFF, .g = 0x45, .b = 0x00},
{ .name = "Orchid", .r = 0xDA, .g = 0x70, .b = 0xD6 }, {.name = "Orchid", .r = 0xDA, .g = 0x70, .b = 0xD6},
{ .name = "PaleGoldenRod", .r = 0xEE, .g = 0xE8, .b = 0xAA }, {.name = "PaleGoldenRod", .r = 0xEE, .g = 0xE8, .b = 0xAA},
{ .name = "PaleGreen", .r = 0x98, .g = 0xFB, .b = 0x98 }, {.name = "PaleGreen", .r = 0x98, .g = 0xFB, .b = 0x98},
{ .name = "PaleTurquoise", .r = 0xAF, .g = 0xEE, .b = 0xEE }, {.name = "PaleTurquoise", .r = 0xAF, .g = 0xEE, .b = 0xEE},
{ .name = "PaleVioletRed", .r = 0xDB, .g = 0x70, .b = 0x93 }, {.name = "PaleVioletRed", .r = 0xDB, .g = 0x70, .b = 0x93},
{ .name = "PapayaWhip", .r = 0xFF, .g = 0xEF, .b = 0xD5 }, {.name = "PapayaWhip", .r = 0xFF, .g = 0xEF, .b = 0xD5},
{ .name = "PeachPuff", .r = 0xFF, .g = 0xDA, .b = 0xB9 }, {.name = "PeachPuff", .r = 0xFF, .g = 0xDA, .b = 0xB9},
{ .name = "Peru", .r = 0xCD, .g = 0x85, .b = 0x3F }, {.name = "Peru", .r = 0xCD, .g = 0x85, .b = 0x3F},
{ .name = "Pink", .r = 0xFF, .g = 0xC0, .b = 0xCB }, {.name = "Pink", .r = 0xFF, .g = 0xC0, .b = 0xCB},
{ .name = "Plum", .r = 0xDD, .g = 0xA0, .b = 0xDD }, {.name = "Plum", .r = 0xDD, .g = 0xA0, .b = 0xDD},
{ .name = "PowderBlue", .r = 0xB0, .g = 0xE0, .b = 0xE6 }, {.name = "PowderBlue", .r = 0xB0, .g = 0xE0, .b = 0xE6},
{ .name = "Purple", .r = 0x80, .g = 0x00, .b = 0x80 }, {.name = "Purple", .r = 0x80, .g = 0x00, .b = 0x80},
{ .name = "RebeccaPurple", .r = 0x66, .g = 0x33, .b = 0x99 }, {.name = "RebeccaPurple", .r = 0x66, .g = 0x33, .b = 0x99},
{ .name = "Red", .r = 0xFF, .g = 0x00, .b = 0x00 }, {.name = "Red", .r = 0xFF, .g = 0x00, .b = 0x00},
{ .name = "RosyBrown", .r = 0xBC, .g = 0x8F, .b = 0x8F }, {.name = "RosyBrown", .r = 0xBC, .g = 0x8F, .b = 0x8F},
{ .name = "RoyalBlue", .r = 0x41, .g = 0x69, .b = 0xE1 }, {.name = "RoyalBlue", .r = 0x41, .g = 0x69, .b = 0xE1},
{ .name = "SaddleBrown", .r = 0x8B, .g = 0x45, .b = 0x13 }, {.name = "SaddleBrown", .r = 0x8B, .g = 0x45, .b = 0x13},
{ .name = "Salmon", .r = 0xFA, .g = 0x80, .b = 0x72 }, {.name = "Salmon", .r = 0xFA, .g = 0x80, .b = 0x72},
{ .name = "SandyBrown", .r = 0xF4, .g = 0xA4, .b = 0x60 }, {.name = "SandyBrown", .r = 0xF4, .g = 0xA4, .b = 0x60},
{ .name = "SeaGreen", .r = 0x2E, .g = 0x8B, .b = 0x57 }, {.name = "SeaGreen", .r = 0x2E, .g = 0x8B, .b = 0x57},
{ .name = "SeaShell", .r = 0xFF, .g = 0xF5, .b = 0xEE }, {.name = "SeaShell", .r = 0xFF, .g = 0xF5, .b = 0xEE},
{ .name = "Sienna", .r = 0xA0, .g = 0x52, .b = 0x2D }, {.name = "Sienna", .r = 0xA0, .g = 0x52, .b = 0x2D},
{ .name = "Silver", .r = 0xC0, .g = 0xC0, .b = 0xC0 }, {.name = "Silver", .r = 0xC0, .g = 0xC0, .b = 0xC0},
{ .name = "SkyBlue", .r = 0x87, .g = 0xCE, .b = 0xEB }, {.name = "SkyBlue", .r = 0x87, .g = 0xCE, .b = 0xEB},
{ .name = "SlateBlue", .r = 0x6A, .g = 0x5A, .b = 0xCD }, {.name = "SlateBlue", .r = 0x6A, .g = 0x5A, .b = 0xCD},
{ .name = "SlateGray", .r = 0x70, .g = 0x80, .b = 0x90 }, {.name = "SlateGray", .r = 0x70, .g = 0x80, .b = 0x90},
{ .name = "SlateGrey", .r = 0x70, .g = 0x80, .b = 0x90 }, {.name = "SlateGrey", .r = 0x70, .g = 0x80, .b = 0x90},
{ .name = "Snow", .r = 0xFF, .g = 0xFA, .b = 0xFA }, {.name = "Snow", .r = 0xFF, .g = 0xFA, .b = 0xFA},
{ .name = "SpringGreen", .r = 0x00, .g = 0xFF, .b = 0x7F }, {.name = "SpringGreen", .r = 0x00, .g = 0xFF, .b = 0x7F},
{ .name = "SteelBlue", .r = 0x46, .g = 0x82, .b = 0xB4 }, {.name = "SteelBlue", .r = 0x46, .g = 0x82, .b = 0xB4},
{ .name = "Tan", .r = 0xD2, .g = 0xB4, .b = 0x8C }, {.name = "Tan", .r = 0xD2, .g = 0xB4, .b = 0x8C},
{ .name = "Teal", .r = 0x00, .g = 0x80, .b = 0x80 }, {.name = "Teal", .r = 0x00, .g = 0x80, .b = 0x80},
{ .name = "Thistle", .r = 0xD8, .g = 0xBF, .b = 0xD8 }, {.name = "Thistle", .r = 0xD8, .g = 0xBF, .b = 0xD8},
{ .name = "Tomato", .r = 0xFF, .g = 0x63, .b = 0x47 }, {.name = "Tomato", .r = 0xFF, .g = 0x63, .b = 0x47},
{ .name = "Turquoise", .r = 0x40, .g = 0xE0, .b = 0xD0 }, {.name = "Turquoise", .r = 0x40, .g = 0xE0, .b = 0xD0},
{ .name = "Violet", .r = 0xEE, .g = 0x82, .b = 0xEE }, {.name = "Violet", .r = 0xEE, .g = 0x82, .b = 0xEE},
{ .name = "Wheat", .r = 0xF5, .g = 0xDE, .b = 0xB3 }, {.name = "Wheat", .r = 0xF5, .g = 0xDE, .b = 0xB3},
{ .name = "White", .r = 0xFF, .g = 0xFF, .b = 0xFF }, {.name = "White", .r = 0xFF, .g = 0xFF, .b = 0xFF},
{ .name = "WhiteSmoke", .r = 0xF5, .g = 0xF5, .b = 0xF5 }, {.name = "WhiteSmoke", .r = 0xF5, .g = 0xF5, .b = 0xF5},
{ .name = "Yellow", .r = 0xFF, .g = 0xFF, .b = 0x00 }, {.name = "Yellow", .r = 0xFF, .g = 0xFF, .b = 0x00},
{ .name = "YellowGreen", .r = 0x9A, .g = 0xCD, .b = 0x32 } {.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. */ /** 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 "helper.h"
#include "settings.h"
#include <rofi.h>
#include <stdio.h>
#include <stdlib.h>
#include "mode-private.h"
#include <dialogs/dialogs.h> #include <dialogs/dialogs.h>
#include <pango/pango.h> #include <pango/pango.h>
#include "mode-private.h"
#include <theme.h> #include <theme.h>
/** /**
* Combi Mode * Combi Mode
*/ */
typedef struct typedef struct {
{ Mode *mode;
Mode *mode; gboolean disable;
gboolean disable;
} CombiMode; } CombiMode;
typedef struct typedef struct {
{ // List of (combined) entries.
// List of (combined) entries. unsigned int cmd_list_length;
unsigned int cmd_list_length; // List to validate where each switcher starts.
// List to validate where each switcher starts. unsigned int *starts;
unsigned int *starts; unsigned int *lengths;
unsigned int *lengths; // List of switchers to combine.
// List of switchers to combine. unsigned int num_switchers;
unsigned int num_switchers; CombiMode *switchers;
CombiMode *switchers;
} CombiModePrivateData; } CombiModePrivateData;
static void combi_mode_parse_switchers ( Mode *sw ) static void combi_mode_parse_switchers(Mode *sw) {
{ CombiModePrivateData *pd = mode_get_private_data(sw);
CombiModePrivateData *pd = mode_get_private_data ( sw ); char *savept = NULL;
char *savept = NULL; // Make a copy, as strtok will modify it.
// Make a copy, as strtok will modify it. char *switcher_str = g_strdup(config.combi_modi);
char *switcher_str = g_strdup ( config.combi_modi ); const char *const sep = ",#";
const char * const sep = ",#"; // Split token on ','. This modifies switcher_str.
// Split token on ','. This modifies switcher_str. for (char *token = strtok_r(switcher_str, sep, &savept); token != NULL;
for ( char *token = strtok_r ( switcher_str, sep, &savept ); token != NULL; token = strtok_r(NULL, sep, &savept)) {
token = strtok_r ( NULL, sep, &savept ) ) { // Resize and add entry.
// Resize and add entry. pd->switchers = (CombiMode *)g_realloc(
pd->switchers = (CombiMode *) g_realloc ( pd->switchers, pd->switchers, sizeof(CombiMode) * (pd->num_switchers + 1));
sizeof ( CombiMode ) * ( pd->num_switchers + 1 ) );
Mode *mode = rofi_collect_modi_search ( token ); Mode *mode = rofi_collect_modi_search(token);
if ( mode != NULL ) { if (mode != NULL) {
pd->switchers[pd->num_switchers].disable = FALSE; pd->switchers[pd->num_switchers].disable = FALSE;
pd->switchers[pd->num_switchers++].mode = mode; pd->switchers[pd->num_switchers++].mode = mode;
continue; 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;
} }
// Free string that was modified by strtok_r // If not build in, use custom switchers.
g_free ( switcher_str ); 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 ) static unsigned int combi_mode_get_num_entries(const Mode *sw) {
{ const CombiModePrivateData *pd =
const CombiModePrivateData *pd = (const CombiModePrivateData *) mode_get_private_data ( sw ); (const CombiModePrivateData *)mode_get_private_data(sw);
unsigned int length = 0; unsigned int length = 0;
for ( unsigned int i = 0; i < pd->num_switchers; i++ ) { for (unsigned int i = 0; i < pd->num_switchers; i++) {
unsigned int entries = mode_get_num_entries ( pd->switchers[i].mode ); unsigned int entries = mode_get_num_entries(pd->switchers[i].mode);
pd->starts[i] = length; pd->starts[i] = length;
pd->lengths[i] = entries; pd->lengths[i] = entries;
length += entries; length += entries;
} }
return length; return length;
} }
static int combi_mode_init ( Mode *sw ) static int combi_mode_init(Mode *sw) {
{ if (mode_get_private_data(sw) == NULL) {
if ( mode_get_private_data ( sw ) == NULL ) { CombiModePrivateData *pd = g_malloc0(sizeof(*pd));
CombiModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) ); mode_set_private_data(sw, (void *)pd);
mode_set_private_data ( sw, (void *) pd ); combi_mode_parse_switchers(sw);
combi_mode_parse_switchers ( sw ); pd->starts = g_malloc0(sizeof(int) * pd->num_switchers);
pd->starts = g_malloc0 ( sizeof ( int ) * pd->num_switchers ); pd->lengths = 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++) {
for ( unsigned int i = 0; i < pd->num_switchers; i++ ) { if (!mode_init(pd->switchers[i].mode)) {
if ( !mode_init ( pd->switchers[i].mode ) ) { return FALSE;
return FALSE; }
}
}
if ( pd->cmd_list_length == 0 ) {
pd->cmd_list_length = combi_mode_get_num_entries ( sw );
}
} }
return TRUE; if (pd->cmd_list_length == 0) {
} pd->cmd_list_length = combi_mode_get_num_entries(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 );
} }
}
return TRUE;
} }
static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line ) static void combi_mode_destroy(Mode *sw) {
{ CombiModePrivateData *pd = (CombiModePrivateData *)mode_get_private_data(sw);
CombiModePrivateData *pd = 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] == '!' ) { if (input[0][0] == '!') {
int switcher = -1; int switcher = -1;
// Implement strchrnul behaviour. // Implement strchrnul behaviour.
char *eob = g_utf8_strchr ( input[0], -1, ' ' ); char *eob = g_utf8_strchr(input[0], -1, ' ');
if ( eob == NULL ) { if (eob == NULL) {
eob = &( input[0][strlen ( input[0] )] ); 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;
} }
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++ ) { for (unsigned i = 0; i < pd->num_switchers; i++) {
if ( selected_line >= pd->starts[i] && if (selected_line >= pd->starts[i] &&
selected_line < ( pd->starts[i] + pd->lengths[i] ) ) { selected_line < (pd->starts[i] + pd->lengths[i])) {
return mode_result ( pd->switchers[i].mode, mretv, input, selected_line - pd->starts[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 ); if ((mretv & MENU_CUSTOM_INPUT)) {
} return mode_result(pd->switchers[0].mode, mretv, input, selected_line);
return MODE_EXIT; }
return MODE_EXIT;
} }
static int combi_mode_match ( const Mode *sw, rofi_int_matcher **tokens, unsigned int index ) static int combi_mode_match(const Mode *sw, rofi_int_matcher **tokens,
{ unsigned int index) {
CombiModePrivateData *pd = mode_get_private_data ( sw ); CombiModePrivateData *pd = mode_get_private_data(sw);
for ( unsigned i = 0; i < pd->num_switchers; i++ ) { for (unsigned i = 0; i < pd->num_switchers; i++) {
if ( pd->switchers[i].disable ) { if (pd->switchers[i].disable) {
continue; 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] );
}
} }
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 ) 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 ); CombiModePrivateData *pd = mode_get_private_data(sw);
if ( !get_entry ) { if (!get_entry) {
for ( unsigned i = 0; i < pd->num_switchers; i++ ) { for (unsigned i = 0; i < pd->num_switchers; i++) {
if ( selected_line >= pd->starts[i] && selected_line < ( pd->starts[i] + pd->lengths[i] ) ) { if (selected_line >= pd->starts[i] &&
mode_get_display_value ( pd->switchers[i].mode, selected_line - pd->starts[i], state, attr_list, FALSE ); selected_line < (pd->starts[i] + pd->lengths[i])) {
return NULL; mode_get_display_value(pd->switchers[i].mode,
} selected_line - pd->starts[i], state, attr_list,
} FALSE);
return NULL; 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; 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 ) static cairo_surface_t *combi_get_icon(const Mode *sw, unsigned int index,
{ int height) {
CombiModePrivateData *pd = mode_get_private_data ( sw ); CombiModePrivateData *pd = mode_get_private_data(sw);
for ( unsigned i = 0; i < pd->num_switchers; i++ ) { for (unsigned i = 0; i < pd->num_switchers; i++) {
pd->switchers[i].disable = FALSE; 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. return NULL;
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 = static char *combi_preprocess_input(Mode *sw, const char *input) {
{ CombiModePrivateData *pd = mode_get_private_data(sw);
.name = "combi", for (unsigned i = 0; i < pd->num_switchers; i++) {
.cfg_name_key = "display-combi", pd->switchers[i].disable = FALSE;
._init = combi_mode_init, }
._get_num_entries = combi_mode_get_num_entries, if (input != NULL && input[0] == '!') {
._result = combi_mode_result, // Implement strchrnul behaviour.
._destroy = combi_mode_destroy, const char *eob = g_utf8_strchr(input, -1, ' ');
._token_match = combi_mode_match, if (eob == NULL) {
._get_completion = combi_get_completion, // Set it to end.
._get_display_value = combi_mgrv, eob = &(input[strlen(input)]);
._get_icon = combi_get_icon, }
._preprocess_input = combi_preprocess_input, ssize_t bang_len = g_utf8_pointer_to_offset(input, eob) - 1;
.private_data = NULL, if (bang_len > 0) {
.free = NULL 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 <config.h>
#include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <unistd.h> #include <dirent.h>
#include <errno.h>
#include <limits.h> #include <limits.h>
#include <signal.h> #include <signal.h>
#include <sys/types.h>
#include <dirent.h>
#include <strings.h>
#include <string.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 "rofi.h"
#include "settings.h" #include "settings.h"
#include "helper.h"
#include "xrmoptions.h"
#include "dialogs/help-keys.h"
#include "widgets/textbox.h" #include "widgets/textbox.h"
#include "xrmoptions.h"
typedef struct typedef struct {
{ char **messages;
char **messages; unsigned int messages_length;
unsigned int messages_length;
} KeysHelpModePrivateData; } KeysHelpModePrivateData;
static void get_apps ( KeysHelpModePrivateData *pd ) static void get_apps(KeysHelpModePrivateData *pd) {
{ pd->messages = config_parser_return_display_help(&(pd->messages_length));
pd->messages = config_parser_return_display_help ( &( pd->messages_length ) );
} }
static int help_keys_mode_init ( Mode *sw ) static int help_keys_mode_init(Mode *sw) {
{ if (mode_get_private_data(sw) == NULL) {
if ( mode_get_private_data ( sw ) == NULL ) { KeysHelpModePrivateData *pd = g_malloc0(sizeof(*pd));
KeysHelpModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) ); mode_set_private_data(sw, (void *)pd);
mode_set_private_data ( sw, (void *) pd ); get_apps(pd);
get_apps ( pd ); }
} return TRUE;
return TRUE;
} }
static ModeMode help_keys_mode_result ( G_GNUC_UNUSED Mode *sw, static ModeMode
int mretv, help_keys_mode_result(G_GNUC_UNUSED Mode *sw, int mretv,
G_GNUC_UNUSED char **input, G_GNUC_UNUSED char **input,
G_GNUC_UNUSED unsigned int selected_line ) G_GNUC_UNUSED unsigned int selected_line) {
{ if (mretv & MENU_CUSTOM_COMMAND) {
if ( mretv & MENU_CUSTOM_COMMAND ) { int retv = (mretv & MENU_LOWER_MASK);
int retv = ( mretv & MENU_LOWER_MASK ); return retv;
return retv; }
} return MODE_EXIT;
return MODE_EXIT;
} }
static void help_keys_mode_destroy ( Mode *sw ) static void help_keys_mode_destroy(Mode *sw) {
{ KeysHelpModePrivateData *rmpd =
KeysHelpModePrivateData *rmpd = (KeysHelpModePrivateData *) mode_get_private_data ( sw ); (KeysHelpModePrivateData *)mode_get_private_data(sw);
if ( rmpd != NULL ) { if (rmpd != NULL) {
g_strfreev ( rmpd->messages ); g_strfreev(rmpd->messages);
g_free ( rmpd ); g_free(rmpd);
mode_set_private_data ( sw, NULL ); 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 ) static char *_get_display_value(const Mode *sw, unsigned int selected_line,
{ int *state, G_GNUC_UNUSED GList **list,
KeysHelpModePrivateData *pd = (KeysHelpModePrivateData *) mode_get_private_data ( sw ); int get_entry) {
*state |= MARKUP; KeysHelpModePrivateData *pd =
if ( !get_entry ) { (KeysHelpModePrivateData *)mode_get_private_data(sw);
return NULL; *state |= MARKUP;
} if (!get_entry) {
return g_strdup ( pd->messages[selected_line] ); return NULL;
}
return g_strdup(pd->messages[selected_line]);
} }
static int help_keys_token_match ( const Mode *data, static int help_keys_token_match(const Mode *data, rofi_int_matcher **tokens,
rofi_int_matcher **tokens, unsigned int index) {
unsigned int index KeysHelpModePrivateData *rmpd =
) (KeysHelpModePrivateData *)mode_get_private_data(data);
{ return helper_token_match(tokens, rmpd->messages[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 ) static unsigned int help_keys_mode_get_num_entries(const Mode *sw) {
{ const KeysHelpModePrivateData *pd =
const KeysHelpModePrivateData *pd = (const KeysHelpModePrivateData *) mode_get_private_data ( sw ); (const KeysHelpModePrivateData *)mode_get_private_data(sw);
return pd->messages_length; return pd->messages_length;
} }
#include "mode-private.h" #include "mode-private.h"
Mode help_keys_mode = Mode help_keys_mode = {.name = "keys",
{ .cfg_name_key = "display-keys",
.name = "keys", ._init = help_keys_mode_init,
.cfg_name_key = "display-keys", ._get_num_entries = help_keys_mode_get_num_entries,
._init = help_keys_mode_init, ._result = help_keys_mode_result,
._get_num_entries = help_keys_mode_get_num_entries, ._destroy = help_keys_mode_destroy,
._result = help_keys_mode_result, ._token_match = help_keys_token_match,
._destroy = help_keys_mode_destroy, ._get_completion = NULL,
._token_match = help_keys_token_match, ._get_display_value = _get_display_value,
._get_completion = NULL, .private_data = NULL,
._get_display_value = _get_display_value, .free = NULL};
.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. */ /** 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 "dialogs/script.h"
#include "helper.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" #include "widgets/textbox.h"
@ -49,424 +48,415 @@
#include "dialogs/dmenuscriptshared.h" #include "dialogs/dmenuscriptshared.h"
typedef struct typedef struct {
{ /** ID of the current script. */
/** ID of the current script. */ unsigned int id;
unsigned int id; /** List of visible items. */
/** List of visible items. */ DmenuScriptEntry *cmd_list;
DmenuScriptEntry *cmd_list; /** length list of visible items. */
/** length list of visible items. */ unsigned int cmd_list_length;
unsigned int cmd_list_length;
/** Urgent list */ /** Urgent list */
struct rofi_range_pair * urgent_list; struct rofi_range_pair *urgent_list;
unsigned int num_urgent_list; unsigned int num_urgent_list;
/** Active list */ /** Active list */
struct rofi_range_pair * active_list; struct rofi_range_pair *active_list;
unsigned int num_active_list; unsigned int num_active_list;
/** Configuration settings. */ /** Configuration settings. */
char *message; char *message;
char *prompt; char *prompt;
gboolean do_markup; gboolean do_markup;
char delim; char delim;
/** no custom */ /** no custom */
gboolean no_custom; gboolean no_custom;
gboolean use_hot_keys; gboolean use_hot_keys;
} ScriptModePrivateData; } ScriptModePrivateData;
/** /**
* Shared function between DMENU and Script mode. * 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 ) void dmenuscript_parse_entry_extras(G_GNUC_UNUSED Mode *sw,
{ DmenuScriptEntry *entry, char *buffer,
gchar **extras = g_strsplit ( buffer, "\x1f", -1 ); G_GNUC_UNUSED size_t length) {
gchar **extra; gchar **extras = g_strsplit(buffer, "\x1f", -1);
for ( extra = extras; *extra != NULL && *( extra + 1 ) != NULL; extra += 2 ) { gchar **extra;
gchar *key = *extra; for (extra = extras; *extra != NULL && *(extra + 1) != NULL; extra += 2) {
gchar *value = *( extra + 1 ); gchar *key = *extra;
if ( strcasecmp ( key, "icon" ) == 0 ) { gchar *value = *(extra + 1);
entry->icon_name = value; if (strcasecmp(key, "icon") == 0) {
} entry->icon_name = value;
else if ( strcasecmp ( key, "meta" ) == 0 ) { } else if (strcasecmp(key, "meta") == 0) {
entry->meta = value; entry->meta = value;
} } else if (strcasecmp(key, "info") == 0) {
else if ( strcasecmp ( key, "info" ) == 0 ) { entry->info = value;
entry->info = value; } else if (strcasecmp(key, "nonselectable") == 0) {
} entry->nonselectable = strcasecmp(value, "true") == 0;
else if ( strcasecmp ( key, "nonselectable" ) == 0 ) { g_free(value);
entry->nonselectable = strcasecmp ( value, "true" ) == 0; } else {
g_free ( value ); g_free(value);
}
else {
g_free ( value );
}
g_free ( key );
} }
g_free ( extras ); g_free(key);
}
g_free(extras);
} }
/** /**
* End of shared functions. * End of shared functions.
*/ */
static void parse_header_entry ( Mode *sw, char *line, ssize_t length ) static void parse_header_entry(Mode *sw, char *line, ssize_t length) {
{ ScriptModePrivateData *pd = (ScriptModePrivateData *)sw->private_data;
ScriptModePrivateData *pd = (ScriptModePrivateData *) sw->private_data; ssize_t length_key = 0; // strlen ( line );
ssize_t length_key = 0;//strlen ( line ); while (length_key < length && line[length_key] != '\x1f') {
while ( length_key < length && line[length_key] != '\x1f' ) { length_key++;
length_key++; }
}
if ( ( length_key + 1 ) < length ) { if ((length_key + 1) < length) {
line[length_key] = '\0'; line[length_key] = '\0';
char *value = line + length_key + 1; char *value = line + length_key + 1;
if ( strcasecmp ( line, "message" ) == 0 ) { if (strcasecmp(line, "message") == 0) {
g_free ( pd->message ); g_free(pd->message);
pd->message = strlen ( value ) ? g_strdup ( value ) : NULL; pd->message = strlen(value) ? g_strdup(value) : NULL;
} } else if (strcasecmp(line, "prompt") == 0) {
else if ( strcasecmp ( line, "prompt" ) == 0 ) { g_free(pd->prompt);
g_free ( pd->prompt ); pd->prompt = g_strdup(value);
pd->prompt = g_strdup ( value ); sw->display_name = pd->prompt;
sw->display_name = pd->prompt; } else if (strcasecmp(line, "markup-rows") == 0) {
} pd->do_markup = (strcasecmp(value, "true") == 0);
else if ( strcasecmp ( line, "markup-rows" ) == 0 ) { } else if (strcasecmp(line, "urgent") == 0) {
pd->do_markup = ( strcasecmp ( value, "true" ) == 0 ); parse_ranges(value, &(pd->urgent_list), &(pd->num_urgent_list));
} } else if (strcasecmp(line, "active") == 0) {
else if ( strcasecmp ( line, "urgent" ) == 0 ) { parse_ranges(value, &(pd->active_list), &(pd->num_active_list));
parse_ranges ( value, &( pd->urgent_list ), &( pd->num_urgent_list ) ); } else if (strcasecmp(line, "delim") == 0) {
} pd->delim = helper_parse_char(value);
else if ( strcasecmp ( line, "active" ) == 0 ) { } else if (strcasecmp(line, "no-custom") == 0) {
parse_ranges ( value, &( pd->active_list ), &( pd->num_active_list ) ); pd->no_custom = (strcasecmp(value, "true") == 0);
} } else if (strcasecmp(line, "use-hot-keys") == 0) {
else if ( strcasecmp ( line, "delim" ) == 0 ) { pd->use_hot_keys = (strcasecmp(value, "true") == 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 ) static DmenuScriptEntry *execute_executor(Mode *sw, char *arg,
{ unsigned int *length, int value,
ScriptModePrivateData *pd = (ScriptModePrivateData *) sw->private_data; DmenuScriptEntry *entry) {
int fd = -1; ScriptModePrivateData *pd = (ScriptModePrivateData *)sw->private_data;
GError *error = NULL; int fd = -1;
DmenuScriptEntry *retv = NULL; GError *error = NULL;
char **argv = NULL; DmenuScriptEntry *retv = NULL;
int argc = 0; char **argv = NULL;
*length = 0; int argc = 0;
*length = 0;
// Environment // Environment
char ** env = g_get_environ (); char **env = g_get_environ();
char *str_value = g_strdup_printf ( "%d", value ); char *str_value = g_strdup_printf("%d", value);
env = g_environ_setenv ( env, "ROFI_RETV", str_value, TRUE ); env = g_environ_setenv(env, "ROFI_RETV", str_value, TRUE);
g_free ( str_value ); g_free(str_value);
str_value = g_strdup_printf ( "%d", (int) getpid () ); str_value = g_strdup_printf("%d", (int)getpid());
env = g_environ_setenv ( env, "ROFI_OUTSIDE", str_value, TRUE ); env = g_environ_setenv(env, "ROFI_OUTSIDE", str_value, TRUE);
g_free ( str_value ); g_free(str_value);
if ( entry && entry->info ) { if (entry && entry->info) {
env = g_environ_setenv ( env, "ROFI_INFO", entry->info, TRUE ); env = g_environ_setenv(env, "ROFI_INFO", entry->info, TRUE);
} }
if ( g_shell_parse_argv ( sw->ed, &argc, &argv, &error ) ) { if (g_shell_parse_argv(sw->ed, &argc, &argv, &error)) {
argv = g_realloc ( argv, ( argc + 2 ) * sizeof ( char* ) ); argv = g_realloc(argv, (argc + 2) * sizeof(char *));
argv[argc] = g_strdup ( arg ); argv[argc] = g_strdup(arg);
argv[argc + 1] = NULL; argv[argc + 1] = NULL;
g_spawn_async_with_pipes ( NULL, argv, env, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL, &fd, NULL, &error ); 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 ) { g_strfreev(env);
char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", (char *) sw->ed, error->message ); if (error != NULL) {
rofi_view_error_dialog ( msg, FALSE ); char *msg = g_strdup_printf("Failed to execute: '%s'\nError: '%s'",
g_free ( msg ); (char *)sw->ed, error->message);
// print error. rofi_view_error_dialog(msg, FALSE);
g_error_free ( error ); g_free(msg);
fd = -1; // print error.
} g_error_free(error);
if ( fd >= 0 ) { fd = -1;
FILE *inp = fdopen ( fd, "r" ); }
if ( inp ) { if (fd >= 0) {
char *buffer = NULL; FILE *inp = fdopen(fd, "r");
size_t buffer_length = 0; if (inp) {
ssize_t read_length = 0; char *buffer = NULL;
size_t actual_size = 0; size_t buffer_length = 0;
while ( ( read_length = getdelim ( &buffer, &buffer_length, pd->delim, inp ) ) > 0 ) { ssize_t read_length = 0;
// Filter out line-end. size_t actual_size = 0;
if ( buffer[read_length - 1] == pd->delim ) { while ((read_length = getdelim(&buffer, &buffer_length, pd->delim, inp)) >
buffer[read_length - 1] = '\0'; 0) {
} // Filter out line-end.
if ( buffer[0] == '\0' ) { if (buffer[read_length - 1] == pd->delim) {
parse_header_entry ( sw, &buffer[1], read_length - 1 ); buffer[read_length - 1] = '\0';
}
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 (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 ) static void script_switcher_free(Mode *sw) {
{ if (sw == NULL) {
if ( sw == NULL ) { return;
return; }
} g_free(sw->name);
g_free ( sw->name ); g_free(sw->ed);
g_free ( sw->ed ); g_free(sw);
g_free ( sw );
} }
static int script_mode_init ( Mode *sw ) static int script_mode_init(Mode *sw) {
{ if (sw->private_data == NULL) {
if ( sw->private_data == NULL ) { ScriptModePrivateData *pd = g_malloc0(sizeof(*pd));
ScriptModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) ); pd->delim = '\n';
pd->delim = '\n'; sw->private_data = (void *)pd;
sw->private_data = (void *) pd; pd->cmd_list = execute_executor(sw, NULL, &(pd->cmd_list_length), 0, NULL);
pd->cmd_list = execute_executor ( sw, NULL, &( pd->cmd_list_length ), 0, NULL ); }
} return TRUE;
return TRUE;
} }
static unsigned int script_mode_get_num_entries ( const Mode *sw ) static unsigned int script_mode_get_num_entries(const Mode *sw) {
{ const ScriptModePrivateData *rmpd =
const ScriptModePrivateData *rmpd = (const ScriptModePrivateData *) sw->private_data; (const ScriptModePrivateData *)sw->private_data;
return rmpd->cmd_list_length; return rmpd->cmd_list_length;
} }
static void script_mode_reset_highlight ( Mode *sw ) static void script_mode_reset_highlight(Mode *sw) {
{ ScriptModePrivateData *rmpd = (ScriptModePrivateData *)sw->private_data;
ScriptModePrivateData *rmpd = (ScriptModePrivateData *) sw->private_data;
rmpd->num_urgent_list = 0; rmpd->num_urgent_list = 0;
g_free ( rmpd->urgent_list ); g_free(rmpd->urgent_list);
rmpd->urgent_list = NULL; rmpd->urgent_list = NULL;
rmpd->num_active_list = 0; rmpd->num_active_list = 0;
g_free ( rmpd->active_list ); g_free(rmpd->active_list);
rmpd->active_list = NULL; rmpd->active_list = NULL;
} }
static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line ) static ModeMode script_mode_result(Mode *sw, int mretv, char **input,
{ unsigned int selected_line) {
ScriptModePrivateData *rmpd = (ScriptModePrivateData *) sw->private_data; ScriptModePrivateData *rmpd = (ScriptModePrivateData *)sw->private_data;
ModeMode retv = MODE_EXIT; ModeMode retv = MODE_EXIT;
DmenuScriptEntry *new_list = NULL; DmenuScriptEntry *new_list = NULL;
unsigned int new_length = 0; unsigned int new_length = 0;
if ( ( mretv & MENU_CUSTOM_COMMAND ) ) { if ((mretv & MENU_CUSTOM_COMMAND)) {
if ( rmpd->use_hot_keys ) { if (rmpd->use_hot_keys) {
script_mode_reset_highlight ( sw ); script_mode_reset_highlight(sw);
if ( selected_line != UINT32_MAX ) { 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] ) ); new_list = execute_executor(sw, rmpd->cmd_list[selected_line].entry,
} &new_length, 10 + (mretv & MENU_LOWER_MASK),
else { &(rmpd->cmd_list[selected_line]));
if ( rmpd->no_custom == FALSE ) { } else {
new_list = execute_executor ( sw, *input, &new_length, 10 + ( mretv & MENU_LOWER_MASK ), NULL ); if (rmpd->no_custom == FALSE) {
} new_list = execute_executor(sw, *input, &new_length,
else { 10 + (mretv & MENU_LOWER_MASK), NULL);
return RELOAD_DIALOG; } else {
} return RELOAD_DIALOG;
}
}
else {
retv = ( mretv & MENU_LOWER_MASK );
return retv;
} }
}
} else {
retv = (mretv & MENU_LOWER_MASK);
return retv;
} }
else if ( ( mretv & MENU_OK ) && rmpd->cmd_list[selected_line].entry != NULL ) { } else if ((mretv & MENU_OK) && rmpd->cmd_list[selected_line].entry != NULL) {
if ( rmpd->cmd_list[selected_line].nonselectable ) { if (rmpd->cmd_list[selected_line].nonselectable) {
return RELOAD_DIALOG; 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' ) { script_mode_reset_highlight(sw);
if ( rmpd->no_custom == FALSE ) { new_list =
script_mode_reset_highlight ( sw ); execute_executor(sw, rmpd->cmd_list[selected_line].entry, &new_length,
new_list = execute_executor ( sw, *input, &new_length, 2, NULL ); 1, &(rmpd->cmd_list[selected_line]));
} } else if ((mretv & MENU_CUSTOM_INPUT) && *input != NULL &&
else { *input[0] != '\0') {
return RELOAD_DIALOG; 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 a new list was generated, use that an loop around.
if ( new_list != NULL ) { if (new_list != NULL) {
for ( unsigned int i = 0; i < rmpd->cmd_list_length; i++ ) { for (unsigned int i = 0; i < rmpd->cmd_list_length; i++) {
g_free ( rmpd->cmd_list[i].entry ); g_free(rmpd->cmd_list[i].entry);
g_free ( rmpd->cmd_list[i].icon_name ); g_free(rmpd->cmd_list[i].icon_name);
g_free ( rmpd->cmd_list[i].meta ); 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;
} }
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 ) static void script_mode_destroy(Mode *sw) {
{ ScriptModePrivateData *rmpd = (ScriptModePrivateData *)sw->private_data;
ScriptModePrivateData *rmpd = (ScriptModePrivateData *) sw->private_data; if (rmpd != NULL) {
if ( rmpd != NULL ) { for (unsigned int i = 0; i < rmpd->cmd_list_length; i++) {
for ( unsigned int i = 0; i < rmpd->cmd_list_length; i++ ) { g_free(rmpd->cmd_list[i].entry);
g_free ( rmpd->cmd_list[i].entry ); g_free(rmpd->cmd_list[i].icon_name);
g_free ( rmpd->cmd_list[i].icon_name ); g_free(rmpd->cmd_list[i].meta);
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;
} }
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 ) static inline unsigned int get_index(unsigned int length, int index) {
{ if (index >= 0) {
if ( index >= 0 ) { return index;
return index; }
} if (((unsigned int)-index) <= length) {
if ( ( (unsigned int) -index ) <= length ) { return length + index;
return length + index; }
} // Out of range.
// Out of range. return UINT_MAX;
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 ) static char *_get_display_value(const Mode *sw, unsigned int selected_line,
{ G_GNUC_UNUSED int *state,
ScriptModePrivateData *pd = sw->private_data; G_GNUC_UNUSED GList **list, int get_entry) {
for ( unsigned int i = 0; i < pd->num_active_list; i++ ) { ScriptModePrivateData *pd = sw->private_data;
unsigned int start = get_index ( pd->cmd_list_length, pd->active_list[i].start ); for (unsigned int i = 0; i < pd->num_active_list; i++) {
unsigned int stop = get_index ( pd->cmd_list_length, pd->active_list[i].stop ); unsigned int start =
if ( selected_line >= start && selected_line <= stop ) { get_index(pd->cmd_list_length, pd->active_list[i].start);
*state |= ACTIVE; 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 ); for (unsigned int i = 0; i < pd->num_urgent_list; i++) {
unsigned int stop = get_index ( pd->cmd_list_length, pd->urgent_list[i].stop ); unsigned int start =
if ( selected_line >= start && selected_line <= stop ) { get_index(pd->cmd_list_length, pd->urgent_list[i].start);
*state |= URGENT; 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; if (pd->do_markup) {
} *state |= MARKUP;
return get_entry ? g_strdup ( pd->cmd_list[selected_line].entry ) : NULL; }
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 ) static int script_token_match(const Mode *sw, rofi_int_matcher **tokens,
{ unsigned int index) {
ScriptModePrivateData *rmpd = sw->private_data; ScriptModePrivateData *rmpd = sw->private_data;
int match = 1; int match = 1;
if ( tokens ) { if (tokens) {
for ( int j = 0; match && tokens != NULL && tokens[j] != NULL; j++ ) { for (int j = 0; match && tokens != NULL && tokens[j] != NULL; j++) {
rofi_int_matcher *ftokens[2] = { tokens[j], NULL }; rofi_int_matcher *ftokens[2] = {tokens[j], NULL};
int test = 0; int test = 0;
test = helper_token_match ( ftokens, rmpd->cmd_list[index].entry ); test = helper_token_match(ftokens, rmpd->cmd_list[index].entry);
if ( test == tokens[j]->invert && rmpd->cmd_list[index].meta ) { if (test == tokens[j]->invert && rmpd->cmd_list[index].meta) {
test = helper_token_match ( ftokens, rmpd->cmd_list[index].meta ); test = helper_token_match(ftokens, rmpd->cmd_list[index].meta);
} }
if ( test == 0 ) { if (test == 0) {
match = 0; match = 0;
} }
}
} }
return match; }
return match;
} }
static char *script_get_message ( const Mode *sw ) static char *script_get_message(const Mode *sw) {
{ ScriptModePrivateData *pd = sw->private_data;
ScriptModePrivateData *pd = sw->private_data; return g_strdup(pd->message);
return g_strdup ( pd->message );
} }
static cairo_surface_t *script_get_icon ( const Mode *sw, unsigned int selected_line, int height ) static cairo_surface_t *
{ script_get_icon(const Mode *sw, unsigned int selected_line, int height) {
ScriptModePrivateData *pd = (ScriptModePrivateData *) mode_get_private_data ( sw ); ScriptModePrivateData *pd =
g_return_val_if_fail ( pd->cmd_list != NULL, NULL ); (ScriptModePrivateData *)mode_get_private_data(sw);
DmenuScriptEntry *dr = &( pd->cmd_list[selected_line] ); g_return_val_if_fail(pd->cmd_list != NULL, NULL);
if ( dr->icon_name == NULL ) { DmenuScriptEntry *dr = &(pd->cmd_list[selected_line]);
return NULL; if (dr->icon_name == NULL) {
} return NULL;
if ( dr->icon_fetch_uid > 0 ) { }
return rofi_icon_fetcher_get ( dr->icon_fetch_uid ); 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 ); 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" #include "mode-private.h"
Mode *script_switcher_parse_setup ( const char *str ) Mode *script_switcher_parse_setup(const char *str) {
{ Mode *sw = g_malloc0(sizeof(*sw));
Mode *sw = g_malloc0 ( sizeof ( *sw ) ); char *endp = NULL;
char *endp = NULL; char *parse = g_strdup(str);
char *parse = g_strdup ( str ); unsigned int index = 0;
unsigned int index = 0; const char *const sep = ":";
const char *const sep = ":"; for (char *token = strtok_r(parse, sep, &endp); token != NULL;
for ( char *token = strtok_r ( parse, sep, &endp ); token != NULL; token = strtok_r ( NULL, sep, &endp ) ) { token = strtok_r(NULL, sep, &endp)) {
if ( index == 0 ) { if (index == 0) {
sw->name = g_strdup ( token ); sw->name = g_strdup(token);
} } else if (index == 1) {
else if ( index == 1 ) { sw->ed = (void *)rofi_expand_path(token);
sw->ed = (void *) rofi_expand_path ( token );
}
index++;
} }
g_free ( parse ); index++;
if ( index == 2 ) { }
sw->free = script_switcher_free; g_free(parse);
sw->_init = script_mode_init; if (index == 2) {
sw->_get_num_entries = script_mode_get_num_entries; sw->free = script_switcher_free;
sw->_result = script_mode_result; sw->_init = script_mode_init;
sw->_destroy = script_mode_destroy; sw->_get_num_entries = script_mode_get_num_entries;
sw->_token_match = script_token_match; sw->_result = script_mode_result;
sw->_get_message = script_get_message; sw->_destroy = script_mode_destroy;
sw->_get_icon = script_get_icon; sw->_token_match = script_token_match;
sw->_get_completion = NULL, sw->_get_message = script_get_message;
sw->_preprocess_input = NULL, sw->_get_icon = script_get_icon;
sw->_get_display_value = _get_display_value; sw->_get_completion = NULL, sw->_preprocess_input = NULL,
sw->_get_display_value = _get_display_value;
return sw; return sw;
} }
fprintf ( stderr, "The script command '%s' has %u options, but needs 2: <name>:<script>.", str, index ); fprintf(
script_switcher_free ( sw ); stderr,
return NULL; "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 ) gboolean script_switcher_is_valid(const char *token) {
{ return strchr(token, ':') != NULL;
return strchr ( token, ':' ) != 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

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

View File

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

View File

@ -28,7 +28,7 @@
/** The log domain of this Helper. */ /** The log domain of this Helper. */
#define G_LOG_DOMAIN "Helpers.IconFetcher" #define G_LOG_DOMAIN "Helpers.IconFetcher"
#include <config.h> #include "config.h"
#include <stdlib.h> #include <stdlib.h>
#include <xcb/xproto.h> #include <xcb/xproto.h>

View File

@ -29,7 +29,7 @@
/** Log domain */ /** Log domain */
#define G_LOG_DOMAIN "Rofi" #define G_LOG_DOMAIN "Rofi"
#include <config.h> #include "config.h"
#include <errno.h> #include <errno.h>
#include <gmodule.h> #include <gmodule.h>
#include <locale.h> #include <locale.h>

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -28,7 +28,7 @@
/** The Rofi View log domain */ /** The Rofi View log domain */
#define G_LOG_DOMAIN "View" #define G_LOG_DOMAIN "View"
#include <config.h> #include "config.h"
#include <errno.h> #include <errno.h>
#include <locale.h> #include <locale.h>
#include <signal.h> #include <signal.h>

View File

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

View File

@ -26,113 +26,100 @@
*/ */
/** The log domain of this widget. */ /** 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 "widgets/container.h"
#include "theme.h" #include "theme.h"
#include "widgets/widget-internal.h"
#include "widgets/widget.h"
#include <stdio.h>
struct _container struct _container {
{ widget widget;
widget widget; widget *child;
widget *child;
}; };
static void container_update ( widget *wid ); static void container_update(widget *wid);
static int container_get_desired_height ( widget *widget ) static int container_get_desired_height(widget *widget) {
{ container *b = (container *)widget;
container *b = (container *) widget; int height = 0;
int height = 0; if (b->child) {
if ( b->child ) { height += widget_get_desired_height(b->child);
height += widget_get_desired_height ( b->child ); }
} height += widget_padding_get_padding_height(widget);
height += widget_padding_get_padding_height ( widget ); return height;
return height;
} }
static void container_draw ( widget *wid, cairo_t *draw ) static void container_draw(widget *wid, cairo_t *draw) {
{ container *b = (container *)wid;
container *b = (container *) wid;
widget_draw ( b->child, draw ); widget_draw(b->child, draw);
} }
static void container_free ( widget *wid ) static void container_free(widget *wid) {
{ container *b = (container *)wid;
container *b = (container *) wid;
widget_free ( b->child ); widget_free(b->child);
g_free ( b ); g_free(b);
} }
void container_add ( container *container, widget *child ) void container_add(container *container, widget *child) {
{ if (container == NULL) {
if ( container == NULL ) { return;
return; }
} container->child = child;
container->child = child; g_assert(child->parent == WIDGET(container));
g_assert ( child->parent == WIDGET ( container ) ); widget_update(WIDGET(container));
widget_update ( WIDGET ( container ) );
} }
static void container_resize ( widget *widget, short w, short h ) static void container_resize(widget *widget, short w, short h) {
{ container *b = (container *)widget;
container *b = (container *) widget; if (b->widget.w != w || b->widget.h != h) {
if ( b->widget.w != w || b->widget.h != h ) { b->widget.w = w;
b->widget.w = w; b->widget.h = h;
b->widget.h = h; widget_update(widget);
widget_update ( widget ); }
}
} }
static widget *container_find_mouse_target ( widget *wid, WidgetType type, gint x, gint y ) static widget *container_find_mouse_target(widget *wid, WidgetType type, gint x,
{ gint y) {
container *b = (container *) wid; container *b = (container *)wid;
if ( !widget_intersect ( b->child, x, y ) ) { if (!widget_intersect(b->child, x, y)) {
return NULL; return NULL;
} }
x -= b->child->x; x -= b->child->x;
y -= b->child->y; y -= b->child->y;
return widget_find_mouse_target ( b->child, type, x, y ); return widget_find_mouse_target(b->child, type, x, y);
} }
static void container_set_state ( widget *wid, const char *state ) static void container_set_state(widget *wid, const char *state) {
{ container *b = (container *)wid;
container *b = (container *) wid; widget_set_state(b->child, state);
widget_set_state ( b->child, state );
} }
container * container_create ( widget *parent, const char *name ) container *container_create(widget *parent, const char *name) {
{ container *b = g_malloc0(sizeof(container));
container *b = g_malloc0 ( sizeof ( container ) ); // Initialize widget.
// Initialize widget. widget_init(WIDGET(b), parent, WIDGET_TYPE_UNKNOWN, name);
widget_init ( WIDGET ( b ), parent, WIDGET_TYPE_UNKNOWN, name ); b->widget.draw = container_draw;
b->widget.draw = container_draw; b->widget.free = container_free;
b->widget.free = container_free; b->widget.resize = container_resize;
b->widget.resize = container_resize; b->widget.update = container_update;
b->widget.update = container_update; b->widget.find_mouse_target = container_find_mouse_target;
b->widget.find_mouse_target = container_find_mouse_target; b->widget.get_desired_height = container_get_desired_height;
b->widget.get_desired_height = container_get_desired_height; b->widget.set_state = container_set_state;
b->widget.set_state = container_set_state; return b;
return b;
} }
static void container_update ( widget *wid ) static void container_update(widget *wid) {
{ container *b = (container *)wid;
container *b = (container *) wid; if (b->child && b->child->enabled) {
if ( b->child && b->child->enabled ) { widget_resize(WIDGET(b->child),
widget_resize ( WIDGET ( b->child ), widget_padding_get_remaining_width(WIDGET(b)),
widget_padding_get_remaining_width ( WIDGET ( b ) ), widget_padding_get_remaining_height(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)));
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. */ /** 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 "widgets/icon.h"
#include "theme.h" #include "theme.h"
#include "widgets/widget-internal.h"
#include "widgets/widget.h"
#include <stdio.h>
#include "rofi-icon-fetcher.h" #include "rofi-icon-fetcher.h"
struct _icon struct _icon {
{ widget widget;
widget widget;
// Size of the icon. // Size of the icon.
int size; int size;
int squared; int squared;
uint32_t icon_fetch_id; uint32_t icon_fetch_id;
double yalign, xalign; double yalign, xalign;
// Source surface. // Source surface.
cairo_surface_t *icon; cairo_surface_t *icon;
}; };
static int icon_get_desired_height ( widget *widget ) static int icon_get_desired_height(widget *widget) {
{ icon *b = (icon *)widget;
icon *b = (icon *) widget; int height = b->size;
int height = b->size; if (b->squared == FALSE) {
if ( b->squared == FALSE ) { if (b->icon) {
if ( b->icon ) { int iconh = cairo_image_surface_get_height(b->icon);
int iconh = cairo_image_surface_get_height ( b->icon ); int iconw = cairo_image_surface_get_width(b->icon);
int iconw = cairo_image_surface_get_width ( b->icon ); int icons = MAX(iconh, iconw);
int icons = MAX ( iconh, iconw ); double scale = (double)b->size / icons;
double scale = (double) b->size / icons; height = iconh * scale;
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 ) static int icon_get_desired_width(widget *widget) {
{ icon *b = (icon *)widget;
icon *b = (icon *) widget; int width = b->size;
int width = b->size; if (b->squared == FALSE) {
if ( b->squared == FALSE ) { if (b->icon) {
if ( b->icon ) { int iconh = cairo_image_surface_get_height(b->icon);
int iconh = cairo_image_surface_get_height ( b->icon ); int iconw = cairo_image_surface_get_width(b->icon);
int iconw = cairo_image_surface_get_width ( b->icon ); int icons = MAX(iconh, iconw);
int icons = MAX ( iconh, iconw ); double scale = (double)b->size / icons;
double scale = (double) b->size / icons; width = iconw * scale;
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 ) static void icon_draw(widget *wid, cairo_t *draw) {
{ icon *b = (icon *)wid;
icon *b = (icon *) wid; // If no icon is loaded. quit.
// If no icon is loaded. quit. if (b->icon == NULL && b->icon_fetch_id > 0) {
if ( b->icon == NULL && b->icon_fetch_id > 0 ) { b->icon = rofi_icon_fetcher_get(b->icon_fetch_id);
b->icon = rofi_icon_fetcher_get ( b->icon_fetch_id ); if (b->icon) {
if ( b->icon ) { cairo_surface_reference(b->icon);
cairo_surface_reference ( b->icon );
}
} }
if ( b->icon == NULL ) { }
return; if (b->icon == NULL) {
} return;
int iconh = cairo_image_surface_get_height ( b->icon ); }
int iconw = cairo_image_surface_get_width ( b->icon ); int iconh = cairo_image_surface_get_height(b->icon);
int icons = MAX ( iconh, iconw ); int iconw = cairo_image_surface_get_width(b->icon);
double scale = (double) b->size / icons; int icons = MAX(iconh, iconw);
double scale = (double)b->size / icons;
int lpad = widget_padding_get_left ( WIDGET ( b ) ); int lpad = widget_padding_get_left(WIDGET(b));
int rpad = widget_padding_get_right ( WIDGET ( b ) ); int rpad = widget_padding_get_right(WIDGET(b));
int tpad = widget_padding_get_top ( WIDGET ( b ) ); int tpad = widget_padding_get_top(WIDGET(b));
int bpad = widget_padding_get_bottom ( WIDGET ( b ) ); int bpad = widget_padding_get_bottom(WIDGET(b));
cairo_save ( draw ); cairo_save(draw);
cairo_translate ( draw, cairo_translate(
lpad + ( b->widget.w - iconw * scale - lpad - rpad ) * b->xalign, draw, lpad + (b->widget.w - iconw * scale - lpad - rpad) * b->xalign,
tpad + ( b->widget.h - iconh * scale - tpad - bpad ) * b->yalign ); tpad + (b->widget.h - iconh * scale - tpad - bpad) * b->yalign);
cairo_scale ( draw, scale, scale ); cairo_scale(draw, scale, scale);
cairo_set_source_surface ( draw, b->icon, 0, 0 ); cairo_set_source_surface(draw, b->icon, 0, 0);
cairo_paint ( draw ); cairo_paint(draw);
cairo_restore ( draw ); cairo_restore(draw);
} }
static void icon_free ( widget *wid ) static void icon_free(widget *wid) {
{ icon *b = (icon *)wid;
icon *b = (icon *) wid;
if ( b->icon ) { if (b->icon) {
cairo_surface_destroy ( b->icon ); cairo_surface_destroy(b->icon);
} }
g_free ( b ); g_free(b);
} }
static void icon_resize ( widget *widget, short w, short h ) static void icon_resize(widget *widget, short w, short h) {
{ icon *b = (icon *)widget;
icon *b = (icon *) widget; if (b->widget.w != w || b->widget.h != h) {
if ( b->widget.w != w || b->widget.h != h ) { b->widget.w = w;
b->widget.w = w; b->widget.h = h;
b->widget.h = h; widget_update(widget);
widget_update ( widget ); }
}
} }
void icon_set_surface ( icon *icon, cairo_surface_t *surf ) void icon_set_surface(icon *icon, cairo_surface_t *surf) {
{ icon->icon_fetch_id = 0;
icon->icon_fetch_id = 0; if (icon->icon) {
if ( icon->icon ) { cairo_surface_destroy(icon->icon);
cairo_surface_destroy ( icon->icon ); icon->icon = NULL;
icon->icon = NULL; }
} if (surf) {
if ( surf ) { cairo_surface_reference(surf);
cairo_surface_reference ( surf ); icon->icon = surf;
icon->icon = surf; }
} widget_queue_redraw(WIDGET(icon));
widget_queue_redraw ( WIDGET ( icon ) );
} }
icon * icon_create ( widget *parent, const char *name ) icon *icon_create(widget *parent, const char *name) {
{ icon *b = g_malloc0(sizeof(icon));
icon *b = g_malloc0 ( sizeof ( icon ) );
b->size = 16; b->size = 16;
// Initialize widget. // Initialize widget.
widget_init ( WIDGET ( b ), parent, WIDGET_TYPE_UNKNOWN, name ); widget_init(WIDGET(b), parent, WIDGET_TYPE_UNKNOWN, name);
b->widget.draw = icon_draw; b->widget.draw = icon_draw;
b->widget.free = icon_free; b->widget.free = icon_free;
b->widget.resize = icon_resize; b->widget.resize = icon_resize;
b->widget.get_desired_height = icon_get_desired_height; b->widget.get_desired_height = icon_get_desired_height;
b->widget.get_desired_width = icon_get_desired_width; b->widget.get_desired_width = icon_get_desired_width;
RofiDistance d = rofi_theme_get_distance ( WIDGET ( b ), "size", b->size ); RofiDistance d = rofi_theme_get_distance(WIDGET(b), "size", b->size);
b->size = distance_get_pixel ( d, ROFI_ORIENTATION_VERTICAL ); 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 ); const char *filename = rofi_theme_get_string(WIDGET(b), "filename", NULL);
if ( filename ) { if (filename) {
b->icon_fetch_id = rofi_icon_fetcher_query ( filename, b->size ); 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 = rofi_theme_get_double(WIDGET(b), "vertical-align", 0.5);
b->yalign = MAX ( 0, MIN ( 1.0, b->yalign ) ); b->yalign = MAX(0, MIN(1.0, b->yalign));
b->xalign = rofi_theme_get_double ( WIDGET ( b ), "horizontal-align", 0.5 ); b->xalign = rofi_theme_get_double(WIDGET(b), "horizontal-align", 0.5);
b->xalign = MAX ( 0, MIN ( 1.0, b->xalign ) ); 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 "widgets/scrollbar.h"
#include <xkbcommon/xkbcommon.h>
#include <glib.h>
#include "widgets/textbox.h"
#include "widgets/icon.h" #include "widgets/icon.h"
#include "widgets/listview.h" #include "widgets/listview.h"
#include "widgets/scrollbar.h" #include "widgets/textbox.h"
#include <glib.h>
#include <xkbcommon/xkbcommon.h>
#include "theme.h" #include "theme.h"
/** The default width of the scrollbar */ /** 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_draw(widget *, cairo_t *);
static void scrollbar_free ( widget * ); static void scrollbar_free(widget *);
static int scrollbar_get_desired_height ( widget *wid ) static int scrollbar_get_desired_height(widget *wid) {
{ // Want height we are.
// Want height we are. return wid->h;
return wid->h;
} }
// TODO // TODO
// This should behave more like a real scrollbar. // This should behave more like a real scrollbar.
guint scrollbar_scroll_get_line ( const scrollbar *sb, int y ) guint scrollbar_scroll_get_line(const scrollbar *sb, int y) {
{ y -= sb->widget.border.top.base.distance;
y -= sb->widget.border.top.base.distance; if (y < 0) {
if ( y < 0 ) { return 0;
return 0; }
}
if ( y > sb->widget.h ) { if (y > sb->widget.h) {
return sb->length - 1; return sb->length - 1;
} }
short r = ( sb->length * sb->widget.h ) / ( (double) ( sb->length + sb->pos_length ) ); short r =
short handle = sb->widget.h - r; (sb->length * sb->widget.h) / ((double)(sb->length + sb->pos_length));
double sec = ( ( r ) / (double) ( sb->length - 1 ) ); short handle = sb->widget.h - r;
short half_handle = handle / 2; double sec = ((r) / (double)(sb->length - 1));
y -= half_handle; short half_handle = handle / 2;
y = MIN ( MAX ( 0, y ), sb->widget.h - 2 * half_handle ); y -= half_handle;
y = MIN(MAX(0, y), sb->widget.h - 2 * half_handle);
unsigned int sel = ( ( y ) / sec ); unsigned int sel = ((y) / sec);
return MIN ( sel, sb->length - 1 ); return MIN(sel, sb->length - 1);
} }
static void scrollbar_scroll ( scrollbar *sb, int y ) static void scrollbar_scroll(scrollbar *sb, int y) {
{ listview_set_selected((listview *)sb->widget.parent,
listview_set_selected ( (listview *) sb->widget.parent, scrollbar_scroll_get_line ( sb, y ) ); 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 ) static WidgetTriggerActionResult
{ scrollbar_trigger_action(widget *wid, MouseBindingMouseDefaultAction action,
scrollbar *sb = (scrollbar *) wid; G_GNUC_UNUSED gint x, gint y,
switch ( action ) G_GNUC_UNUSED void *user_data) {
{ scrollbar *sb = (scrollbar *)wid;
case MOUSE_CLICK_DOWN: switch (action) {
return WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_BEGIN; case MOUSE_CLICK_DOWN:
case MOUSE_CLICK_UP: return WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_BEGIN;
scrollbar_scroll ( sb, y ); case MOUSE_CLICK_UP:
return WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_END; scrollbar_scroll(sb, y);
case MOUSE_DCLICK_DOWN: return WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_END;
case MOUSE_DCLICK_UP: case MOUSE_DCLICK_DOWN:
break; case MOUSE_DCLICK_UP:
} break;
return FALSE; }
return FALSE;
} }
static gboolean scrollbar_motion_notify ( widget *wid, G_GNUC_UNUSED gint x, gint y ) static gboolean scrollbar_motion_notify(widget *wid, G_GNUC_UNUSED gint x,
{ gint y) {
scrollbar *sb = (scrollbar *) wid; scrollbar *sb = (scrollbar *)wid;
scrollbar_scroll ( sb, y ); scrollbar_scroll(sb, y);
return TRUE; return TRUE;
} }
scrollbar *scrollbar_create ( widget *parent, const char *name ) scrollbar *scrollbar_create(widget *parent, const char *name) {
{ scrollbar *sb = g_malloc0(sizeof(scrollbar));
scrollbar *sb = g_malloc0 ( sizeof ( scrollbar ) ); widget_init(WIDGET(sb), parent, WIDGET_TYPE_SCROLLBAR, name);
widget_init ( WIDGET ( sb ), parent, WIDGET_TYPE_SCROLLBAR, name ); sb->widget.x = 0;
sb->widget.x = 0; sb->widget.y = 0;
sb->widget.y = 0; sb->width = rofi_theme_get_distance(WIDGET(sb), "handle-width",
sb->width = rofi_theme_get_distance ( WIDGET ( sb ), "handle-width", DEFAULT_SCROLLBAR_WIDTH ); DEFAULT_SCROLLBAR_WIDTH);
int width = distance_get_pixel ( sb->width, ROFI_ORIENTATION_HORIZONTAL ); int width = distance_get_pixel(sb->width, ROFI_ORIENTATION_HORIZONTAL);
sb->widget.w = widget_padding_get_padding_width ( WIDGET ( sb ) ) + width; sb->widget.w = widget_padding_get_padding_width(WIDGET(sb)) + width;
sb->widget.h = widget_padding_get_padding_height ( WIDGET ( sb ) ); sb->widget.h = widget_padding_get_padding_height(WIDGET(sb));
sb->widget.draw = scrollbar_draw; sb->widget.draw = scrollbar_draw;
sb->widget.free = scrollbar_free; sb->widget.free = scrollbar_free;
sb->widget.trigger_action = scrollbar_trigger_action; sb->widget.trigger_action = scrollbar_trigger_action;
sb->widget.motion_notify = scrollbar_motion_notify; sb->widget.motion_notify = scrollbar_motion_notify;
sb->widget.get_desired_height = scrollbar_get_desired_height; sb->widget.get_desired_height = scrollbar_get_desired_height;
sb->length = 10; sb->length = 10;
sb->pos = 0; sb->pos = 0;
sb->pos_length = 4; sb->pos_length = 4;
return sb; return sb;
} }
static void scrollbar_free ( widget *wid ) static void scrollbar_free(widget *wid) {
{ scrollbar *sb = (scrollbar *)wid;
scrollbar *sb = (scrollbar *) wid; g_free(sb);
g_free ( sb );
} }
void scrollbar_set_max_value ( scrollbar *sb, unsigned int max ) void scrollbar_set_max_value(scrollbar *sb, unsigned int max) {
{ if (sb != NULL) {
if ( sb != NULL ) { sb->length = MAX(1u, max);
sb->length = MAX ( 1u, max ); }
}
} }
void scrollbar_set_handle ( scrollbar *sb, unsigned int pos ) void scrollbar_set_handle(scrollbar *sb, unsigned int pos) {
{ if (sb != NULL) {
if ( sb != NULL ) { sb->pos = MIN(sb->length, pos);
sb->pos = MIN ( sb->length, pos ); }
}
} }
void scrollbar_set_handle_length ( scrollbar *sb, unsigned int pos_length ) void scrollbar_set_handle_length(scrollbar *sb, unsigned int pos_length) {
{ if (sb != NULL) {
if ( sb != NULL ) { sb->pos_length = MIN(sb->length, MAX(1u, pos_length));
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+hl ) = num*h
* r = (num*h)/(num+hl) * r = (num*h)/(num+hl)
*/ */
static void scrollbar_draw ( widget *wid, cairo_t *draw ) static void scrollbar_draw(widget *wid, cairo_t *draw) {
{ scrollbar *sb = (scrollbar *)wid;
scrollbar *sb = (scrollbar *) wid; unsigned int wh = widget_padding_get_remaining_height(wid);
unsigned int wh = widget_padding_get_remaining_height ( wid ); // Calculate position and size.
// Calculate position and size. unsigned int r = (sb->length * wh) / ((double)(sb->length + sb->pos_length));
unsigned int r = ( sb->length * wh ) / ( (double) ( sb->length + sb->pos_length ) ); unsigned int handle = wid->h - r;
unsigned int handle = wid->h - r; double sec = ((r) / (double)(sb->length - 1));
double sec = ( ( r ) / (double) ( sb->length - 1 ) ); unsigned int height = handle;
unsigned int height = handle; unsigned int y = sb->pos * sec;
unsigned int y = sb->pos * sec; // Set max pos.
// Set max pos. y = MIN(y, wh - handle);
y = MIN ( y, wh - handle ); // Never go out of bar.
// Never go out of bar. height = MAX(2, height);
height = MAX ( 2, height ); // Cap length;
// Cap length; rofi_theme_get_color(WIDGET(sb), "handle-color", draw);
rofi_theme_get_color ( WIDGET ( sb ), "handle-color", draw );
cairo_rectangle ( draw, cairo_rectangle(draw, widget_padding_get_left(wid),
widget_padding_get_left ( wid ), widget_padding_get_top(wid) + y,
widget_padding_get_top ( wid ) + y, widget_padding_get_remaining_width(wid), height);
widget_padding_get_remaining_width ( wid ), cairo_fill(draw);
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