[Cleanup] Using clang-tidy

This commit is contained in:
Dave Davenport 2021-08-18 01:16:45 +02:00
parent 3a1b768bf4
commit 954fc728b2
41 changed files with 13115 additions and 12950 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

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

File diff suppressed because it is too large Load Diff

View File

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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -25,7 +25,7 @@
*
*/
#include <config.h>
#include "config.h"
#include <string.h>
#include "rofi.h"
#include "nkutils-bindings.h"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff