[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
{
typedef struct CSSColor {
/** CSS name of the color. */
char *name;
/** BGRA 8 bit color components. */
uint8_t b, g, r, a;
}CSSColor;
} CSSColor;
/**
* Array with all the named colors. Of type #CSSColor, there are #num_CSSColors items in this array.
* Array with all the named colors. Of type #CSSColor, there are #num_CSSColors
* items in this array.
*/
extern const CSSColor CSSColors[];
/**

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,17 +281,17 @@ 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
{
typedef struct {
/** The name of the application */
const gchar *name;
/** The binary name of the application */
@@ -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,8 +7,7 @@ G_BEGIN_DECLS
/**
* Type of property
*/
typedef enum
{
typedef enum {
/** Integer */
P_INTEGER,
/** Double */
@@ -48,11 +46,10 @@ typedef enum
* 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
{
typedef enum {
/** no highlight */
ROFI_HL_NONE = 0,
/** bold */
@@ -70,8 +67,7 @@ typedef enum
} RofiHighlightStyle;
/** Style of line */
typedef enum
{
typedef enum {
/** Solid line */
ROFI_HL_SOLID,
/** Dashed line */
@@ -81,8 +77,7 @@ typedef enum
/**
* Distance unit type.
*/
typedef enum
{
typedef enum {
/** PixelWidth in pixels. */
ROFI_PU_PX,
/** PixelWidth in millimeters. */
@@ -98,8 +93,7 @@ typedef enum
/**
* Structure representing a distance.
*/
typedef enum
{
typedef enum {
ROFI_DISTANCE_MODIFIER_NONE,
ROFI_DISTANCE_MODIFIER_ADD,
ROFI_DISTANCE_MODIFIER_SUBTRACT,
@@ -111,8 +105,7 @@ typedef enum
ROFI_DISTANCE_MODIFIER_MAX,
} RofiDistanceModifier;
typedef struct RofiDistanceUnit
{
typedef struct RofiDistanceUnit {
/** Distance */
double distance;
/** Unit type of the distance */
@@ -128,8 +121,7 @@ typedef struct RofiDistanceUnit
struct RofiDistanceUnit *right;
} RofiDistanceUnit;
typedef struct
{
typedef struct {
/** Base */
RofiDistanceUnit base;
/** Style of the line (optional)*/
@@ -139,8 +131,7 @@ typedef struct
/**
* Type of orientation.
*/
typedef enum
{
typedef enum {
ROFI_ORIENTATION_VERTICAL,
ROFI_ORIENTATION_HORIZONTAL
} RofiOrientation;
@@ -148,8 +139,7 @@ typedef enum
/**
* Cursor type.
*/
typedef enum
{
typedef enum {
ROFI_CURSOR_DEFAULT,
ROFI_CURSOR_POINTER,
ROFI_CURSOR_TEXT
@@ -158,8 +148,7 @@ typedef enum
/**
* Represent the color in theme.
*/
typedef struct
{
typedef struct {
/** red channel */
double red;
/** green channel */
@@ -173,14 +162,9 @@ typedef struct
/**
* Theme Image
*/
typedef enum
{
ROFI_IMAGE_URL,
ROFI_IMAGE_LINEAR_GRADIENT
} RofiImageType;
typedef enum { ROFI_IMAGE_URL, ROFI_IMAGE_LINEAR_GRADIENT } RofiImageType;
typedef enum
{
typedef enum {
ROFI_DIRECTION_LEFT,
ROFI_DIRECTION_RIGHT,
ROFI_DIRECTION_TOP,
@@ -188,16 +172,14 @@ typedef enum
ROFI_DIRECTION_ANGLE,
} RofiDirection;
typedef enum
{
typedef enum {
ROFI_SCALE_NONE,
ROFI_SCALE_BOTH,
ROFI_SCALE_HEIGHT,
ROFI_SCALE_WIDTH,
} RofiScaleType;
typedef struct
{
typedef struct {
RofiImageType type;
char *url;
RofiScaleType scaling;
@@ -217,8 +199,7 @@ typedef struct
/**
* RofiPadding
*/
typedef struct
{
typedef struct {
RofiDistance top;
RofiDistance right;
RofiDistance bottom;
@@ -228,8 +209,7 @@ typedef struct
/**
* Theme highlight.
*/
typedef struct
{
typedef struct {
/** style to display */
RofiHighlightStyle style;
/** Color */
@@ -245,8 +225,7 @@ typedef struct
*
* @ingroup CONFIGURATION
*/
typedef enum
{
typedef enum {
/** Center */
WL_CENTER = 0,
/** Top middle */
@@ -267,8 +246,7 @@ typedef enum
WL_SOUTH_WEST = WL_SOUTH | WL_WEST,
} WindowLocation;
typedef union _PropertyValue
{
typedef union _PropertyValue {
/** integer */
int i;
/** Double */
@@ -284,8 +262,7 @@ typedef union _PropertyValue
/** RofiPadding */
RofiPadding padding;
/** Reference */
struct
{
struct {
/** Name */
char *name;
/** Cached looked up ref */
@@ -304,8 +281,7 @@ typedef union _PropertyValue
/**
* Property structure.
*/
typedef struct Property
{
typedef struct Property {
/** Name of property */
char *name;
/** Type of property. */
@@ -317,8 +293,7 @@ typedef struct Property
/**
* Structure to hold a range.
*/
typedef struct rofi_range_pair
{
typedef struct rofi_range_pair {
int start;
int stop;
} rofi_range_pair;
@@ -326,8 +301,7 @@ typedef struct rofi_range_pair
/**
* Internal structure for matching.
*/
typedef struct rofi_int_matcher_t
{
typedef struct rofi_int_matcher_t {
GRegex *regex;
gboolean invert;
} rofi_int_matcher;
@@ -336,9 +310,8 @@ typedef struct rofi_int_matcher_t
* 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 }
};
{.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

@@ -28,29 +28,26 @@
/** The log domain of this dialog. */
#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
{
typedef struct {
Mode *mode;
gboolean disable;
} CombiMode;
typedef struct
{
typedef struct {
// List of (combined) entries.
unsigned int cmd_list_length;
// List to validate where each switcher starts.
@@ -61,46 +58,45 @@ typedef struct
CombiMode *switchers;
} CombiModePrivateData;
static void combi_mode_parse_switchers ( Mode *sw )
{
CombiModePrivateData *pd = mode_get_private_data ( sw );
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 = ",#";
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 ) ) {
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 ) );
pd->switchers = (CombiMode *)g_realloc(
pd->switchers, sizeof(CombiMode) * (pd->num_switchers + 1));
Mode *mode = rofi_collect_modi_search ( token );
if ( mode != 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;
}
// If not build in, use custom switchers.
mode = script_switcher_parse_setup ( token );
if ( mode != NULL ) {
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 );
g_warning("Invalid script switcher: %s", token);
token = NULL;
}
// Free string that was modified by strtok_r
g_free ( switcher_str );
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 );
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 );
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;
@@ -108,130 +104,137 @@ static unsigned int combi_mode_get_num_entries ( const Mode *sw )
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 ) ) {
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 );
if (pd->cmd_list_length == 0) {
pd->cmd_list_length = combi_mode_get_num_entries(sw);
}
}
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 );
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 );
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 );
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 );
static ModeMode combi_mode_result(Mode *sw, int mretv, char **input,
unsigned int selected_line) {
CombiModePrivateData *pd = mode_get_private_data(sw);
if ( input[0][0] == '!' ) {
if (input[0][0] == '!') {
int switcher = -1;
// Implement strchrnul behaviour.
char *eob = g_utf8_strchr ( input[0], -1, ' ' );
if ( eob == NULL ) {
eob = &( input[0][strlen ( input[0] )] );
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 ) {
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] == ' ' ) {
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_result(pd->switchers[switcher].mode, mretv, &n,
selected_line - pd->starts[switcher]);
}
return MODE_EXIT;
}
} else if ( ( mretv& MENU_COMPLETE) ) {
} 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 );
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 ) {
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] );
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 );
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;
}
}
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 );
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 );
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 );
pa->end_index = strlen(dname);
*attr_list = g_list_append(*attr_list, pa);
}
}
}
@@ -241,69 +244,69 @@ static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *stat
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 );
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 ();
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 );
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;
}
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++ ) {
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] == '!' ) {
if (input != NULL && input[0] == '!') {
// Implement strchrnul behaviour.
const char *eob = g_utf8_strchr ( input, -1, ' ' );
if ( eob == NULL ) {
const char *eob = g_utf8_strchr(input, -1, ' ');
if (eob == NULL) {
// Set it to end.
eob = &( input[strlen ( input )] );
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 ) ) {
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' ) {
if (eob[0] == '\0' || eob[1] == '\0') {
return NULL;
}
return g_strdup ( eob + 1 );
return g_strdup(eob + 1);
}
}
return g_strdup ( input );
return g_strdup(input);
}
Mode combi_mode =
{
.name = "combi",
Mode combi_mode = {.name = "combi",
.cfg_name_key = "display-combi",
._init = combi_mode_init,
._get_num_entries = combi_mode_get_num_entries,
@@ -315,5 +318,4 @@ Mode combi_mode =
._get_icon = combi_get_icon,
._preprocess_input = combi_preprocess_input,
.private_data = NULL,
.free = NULL
};
.free = NULL};

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -23,25 +23,25 @@
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <gmodule.h>
#include <gio/gio.h>
#include <gmodule.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "mode.h"
#include "theme.h"
#include "helper.h"
#include "mode-private.h"
#include "dialogs/filebrowser.h"
#include "rofi.h"
#include "helper.h"
#include "history.h"
#include "mode-private.h"
#include "mode.h"
#include "rofi.h"
#include "theme.h"
#include <stdint.h>
@@ -52,8 +52,7 @@
/**
* The internal data structure holding the private data of the TEST Mode.
*/
enum FBFileType
{
enum FBFileType {
UP,
DIRECTORY,
RFILE,
@@ -63,8 +62,7 @@ enum FBFileType
/**
* Possible sorting methods
*/
enum FBSortingMethod
{
enum FBSortingMethod {
FB_SORT_NAME,
FB_SORT_TIME,
};
@@ -72,22 +70,15 @@ enum FBSortingMethod
/**
* Type of time to sort by
*/
enum FBSortingTime
{
enum FBSortingTime {
FB_MTIME,
FB_ATIME,
FB_CTIME,
};
/** Icons to use for the file type */
const char *icon_name[NUM_FILE_TYPES] =
{
"go-up",
"folder",
"gtk-file"
};
typedef struct
{
const char *icon_name[NUM_FILE_TYPES] = {"go-up", "folder", "gtk-file"};
typedef struct {
char *name;
char *path;
enum FBFileType type;
@@ -96,15 +87,13 @@ typedef struct
time_t time;
} FBFile;
typedef struct
{
typedef struct {
GFile *current_dir;
FBFile *array;
unsigned int array_length;
} FileBrowserModePrivateData;
struct
{
struct {
enum FBSortingMethod sorting_method;
enum FBSortingTime sorting_time;
gboolean directories_first;
@@ -114,58 +103,55 @@ struct
.directories_first = TRUE,
};
static void free_list ( FileBrowserModePrivateData *pd )
{
for ( unsigned int i = 0; i < pd->array_length; i++ ) {
FBFile *fb = &( pd->array[i] );
g_free ( fb->name );
g_free ( fb->path );
static void free_list(FileBrowserModePrivateData *pd) {
for (unsigned int i = 0; i < pd->array_length; i++) {
FBFile *fb = &(pd->array[i]);
g_free(fb->name);
g_free(fb->path);
}
g_free ( pd->array );
g_free(pd->array);
pd->array = NULL;
pd->array_length = 0;
}
#include <sys/types.h>
#include <dirent.h>
#include <sys/types.h>
static gint compare_name ( gconstpointer a, gconstpointer b, G_GNUC_UNUSED gpointer data )
{
FBFile *fa = (FBFile *) a;
FBFile *fb = (FBFile *) b;
static gint compare_name(gconstpointer a, gconstpointer b,
G_GNUC_UNUSED gpointer data) {
FBFile *fa = (FBFile *)a;
FBFile *fb = (FBFile *)b;
if ( file_browser_config.directories_first && fa->type != fb->type ) {
if (file_browser_config.directories_first && fa->type != fb->type) {
return fa->type - fb->type;
}
return g_strcmp0 ( fa->name, fb->name );
return g_strcmp0(fa->name, fb->name);
}
static gint compare_time ( gconstpointer a, gconstpointer b, G_GNUC_UNUSED gpointer data )
{
FBFile *fa = (FBFile *) a;
FBFile *fb = (FBFile *) b;
static gint compare_time(gconstpointer a, gconstpointer b,
G_GNUC_UNUSED gpointer data) {
FBFile *fa = (FBFile *)a;
FBFile *fb = (FBFile *)b;
if ( file_browser_config.directories_first && fa->type != fb->type ) {
if (file_browser_config.directories_first && fa->type != fb->type) {
return fa->type - fb->type;
}
if ( fa->time < 0 ) {
if (fa->time < 0) {
return -1;
}
if ( fb->time < 0 ) {
if (fb->time < 0) {
return 1;
}
return fb->time - fa->time;
}
static gint compare ( gconstpointer a, gconstpointer b, gpointer data )
{
static gint compare(gconstpointer a, gconstpointer b, gpointer data) {
GCompareDataFunc comparator = NULL;
switch ( file_browser_config.sorting_method )
{
switch (file_browser_config.sorting_method) {
case FB_SORT_NAME:
comparator = compare_name;
break;
@@ -177,13 +163,11 @@ static gint compare ( gconstpointer a, gconstpointer b, gpointer data )
break;
}
return comparator ( a, b, data );
return comparator(a, b, data);
}
static time_t get_time ( const struct stat *statbuf )
{
switch ( file_browser_config.sorting_time )
{
static time_t get_time(const struct stat *statbuf) {
switch (file_browser_config.sorting_time) {
case FB_MTIME:
return statbuf->st_mtim.tv_sec;
case FB_ATIME:
@@ -195,38 +179,37 @@ static time_t get_time ( const struct stat *statbuf )
}
}
static void set_time ( FBFile *file )
{
gchar* path = g_filename_from_utf8 ( file->path, -1, NULL, NULL, NULL );
static void set_time(FBFile *file) {
gchar *path = g_filename_from_utf8(file->path, -1, NULL, NULL, NULL);
struct stat statbuf;
if ( stat ( path, &statbuf ) == 0 ) {
file->time = get_time ( &statbuf );
}
else {
g_warning ( "Failed to stat file: %s, %s", path, strerror ( errno ) );
if (stat(path, &statbuf) == 0) {
file->time = get_time(&statbuf);
} else {
g_warning("Failed to stat file: %s, %s", path, strerror(errno));
}
g_free ( path );
g_free(path);
}
static void get_file_browser ( Mode *sw )
{
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
static void get_file_browser(Mode *sw) {
FileBrowserModePrivateData *pd =
(FileBrowserModePrivateData *)mode_get_private_data(sw);
/**
* Get the entries to display.
* this gets called on plugin initialization.
*/
char *cdir = g_file_get_path ( pd->current_dir );
DIR *dir = opendir ( cdir );
if ( dir ) {
char *cdir = g_file_get_path(pd->current_dir);
DIR *dir = opendir(cdir);
if (dir) {
struct dirent *rd = NULL;
while ( ( rd = readdir ( dir ) ) != NULL ) {
if ( g_strcmp0 ( rd->d_name, ".." ) == 0 ) {
pd->array = g_realloc ( pd->array, ( pd->array_length + 1 ) * sizeof ( FBFile ) );
while ((rd = readdir(dir)) != NULL) {
if (g_strcmp0(rd->d_name, "..") == 0) {
pd->array =
g_realloc(pd->array, (pd->array_length + 1) * sizeof(FBFile));
// Rofi expects utf-8, so lets convert the filename.
pd->array[pd->array_length].name = g_strdup ( ".." );
pd->array[pd->array_length].name = g_strdup("..");
pd->array[pd->array_length].path = NULL;
pd->array[pd->array_length].type = UP;
pd->array[pd->array_length].icon_fetch_uid = 0;
@@ -235,12 +218,11 @@ static void get_file_browser ( Mode *sw )
pd->array_length++;
continue;
}
else if ( rd->d_name[0] == '.' ) {
if (rd->d_name[0] == '.') {
continue;
}
switch ( rd->d_type )
{
switch (rd->d_type) {
case DT_BLK:
case DT_CHR:
case DT_FIFO:
@@ -250,272 +232,267 @@ static void get_file_browser ( Mode *sw )
break;
case DT_REG:
case DT_DIR:
pd->array = g_realloc ( pd->array, ( pd->array_length + 1 ) * sizeof ( FBFile ) );
pd->array =
g_realloc(pd->array, (pd->array_length + 1) * sizeof(FBFile));
// Rofi expects utf-8, so lets convert the filename.
pd->array[pd->array_length].name = g_filename_to_utf8 ( rd->d_name, -1, NULL, NULL, NULL );
pd->array[pd->array_length].path = g_build_filename ( cdir, rd->d_name, NULL );
pd->array[pd->array_length].type = ( rd->d_type == DT_DIR ) ? DIRECTORY : RFILE;
pd->array[pd->array_length].name =
g_filename_to_utf8(rd->d_name, -1, NULL, NULL, NULL);
pd->array[pd->array_length].path =
g_build_filename(cdir, rd->d_name, NULL);
pd->array[pd->array_length].type =
(rd->d_type == DT_DIR) ? DIRECTORY : RFILE;
pd->array[pd->array_length].icon_fetch_uid = 0;
pd->array[pd->array_length].link = FALSE;
if ( file_browser_config.sorting_method == FB_SORT_TIME ) {
set_time ( &pd->array[pd->array_length] );
if (file_browser_config.sorting_method == FB_SORT_TIME) {
set_time(&pd->array[pd->array_length]);
}
pd->array_length++;
break;
case DT_LNK:
pd->array = g_realloc ( pd->array, ( pd->array_length + 1 ) * sizeof ( FBFile ) );
pd->array =
g_realloc(pd->array, (pd->array_length + 1) * sizeof(FBFile));
// Rofi expects utf-8, so lets convert the filename.
pd->array[pd->array_length].name = g_filename_to_utf8 ( rd->d_name, -1, NULL, NULL, NULL );
pd->array[pd->array_length].path = g_build_filename ( cdir, rd->d_name, NULL );
pd->array[pd->array_length].name =
g_filename_to_utf8(rd->d_name, -1, NULL, NULL, NULL);
pd->array[pd->array_length].path =
g_build_filename(cdir, rd->d_name, NULL);
pd->array[pd->array_length].icon_fetch_uid = 0;
pd->array[pd->array_length].link = TRUE;
// Default to file.
pd->array[pd->array_length].type = RFILE;
{
// If we have link, use a stat to fine out what it is, if we fail, we mark it as file.
// If we have link, use a stat to fine out what it is, if we fail, we
// mark it as file.
// TODO have a 'broken link' mode?
// Convert full path to right encoding.
char *file = g_filename_from_utf8 ( pd->array[pd->array_length].path, -1, NULL, NULL, NULL );
if ( file ) {
char *file = g_filename_from_utf8(pd->array[pd->array_length].path,
-1, NULL, NULL, NULL);
if (file) {
struct stat statbuf;
if ( stat ( file, &statbuf ) == 0 ) {
if ( S_ISDIR ( statbuf.st_mode ) ) {
if (stat(file, &statbuf) == 0) {
if (S_ISDIR(statbuf.st_mode)) {
pd->array[pd->array_length].type = DIRECTORY;
}
else if ( S_ISREG ( statbuf.st_mode ) ) {
} else if (S_ISREG(statbuf.st_mode)) {
pd->array[pd->array_length].type = RFILE;
}
if ( file_browser_config.sorting_method == FB_SORT_TIME ) {
pd->array[pd->array_length].time = get_time ( &statbuf );
if (file_browser_config.sorting_method == FB_SORT_TIME) {
pd->array[pd->array_length].time = get_time(&statbuf);
}
}
else {
g_warning ( "Failed to stat file: %s, %s", file, strerror ( errno ) );
} else {
g_warning("Failed to stat file: %s, %s", file, strerror(errno));
}
g_free ( file );
g_free(file);
}
}
pd->array_length++;
break;
}
}
closedir ( dir );
closedir(dir);
}
g_qsort_with_data ( pd->array, pd->array_length, sizeof ( FBFile ), compare, NULL );
g_qsort_with_data(pd->array, pd->array_length, sizeof(FBFile), compare, NULL);
}
static void file_browser_mode_init_config ( Mode *sw )
{
static void file_browser_mode_init_config(Mode *sw) {
char *msg = NULL;
gboolean found_error = FALSE;
ThemeWidget *wid = rofi_config_find_widget ( sw->name, NULL, TRUE );
ThemeWidget *wid = rofi_config_find_widget(sw->name, NULL, TRUE);
Property *p = rofi_theme_find_property ( wid, P_STRING, "sorting-method", TRUE );
if ( p != NULL && p->type == P_STRING ) {
if ( g_strcmp0 ( p->value.s, "name" ) == 0 ) {
Property *p = rofi_theme_find_property(wid, P_STRING, "sorting-method", TRUE);
if (p != NULL && p->type == P_STRING) {
if (g_strcmp0(p->value.s, "name") == 0) {
file_browser_config.sorting_method = FB_SORT_NAME;
}
else if ( g_strcmp0 ( p->value.s, "mtime" ) == 0 ) {
} else if (g_strcmp0(p->value.s, "mtime") == 0) {
file_browser_config.sorting_method = FB_SORT_TIME;
file_browser_config.sorting_time = FB_MTIME;
}
else if ( g_strcmp0 ( p->value.s, "atime" ) == 0 ) {
} else if (g_strcmp0(p->value.s, "atime") == 0) {
file_browser_config.sorting_method = FB_SORT_TIME;
file_browser_config.sorting_time = FB_ATIME;
}
else if ( g_strcmp0 ( p->value.s, "ctime" ) == 0 ) {
} else if (g_strcmp0(p->value.s, "ctime") == 0) {
file_browser_config.sorting_method = FB_SORT_TIME;
file_browser_config.sorting_time = FB_CTIME;
}
else {
} else {
found_error = TRUE;
msg = g_strdup_printf ( "\"%s\" is not a valid filebrowser sorting method", p->value.s );
msg = g_strdup_printf("\"%s\" is not a valid filebrowser sorting method",
p->value.s);
}
}
p = rofi_theme_find_property ( wid, P_BOOLEAN, "directories-first", TRUE );
if ( p != NULL && p->type == P_BOOLEAN ) {
p = rofi_theme_find_property(wid, P_BOOLEAN, "directories-first", TRUE);
if (p != NULL && p->type == P_BOOLEAN) {
file_browser_config.directories_first = p->value.b;
}
if ( found_error ) {
rofi_view_error_dialog ( msg, FALSE );
if (found_error) {
rofi_view_error_dialog(msg, FALSE);
g_free ( msg );
g_free(msg);
}
}
static void file_browser_mode_init_current_dir ( Mode *sw ) {
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
static void file_browser_mode_init_current_dir(Mode *sw) {
FileBrowserModePrivateData *pd =
(FileBrowserModePrivateData *)mode_get_private_data(sw);
ThemeWidget *wid = rofi_config_find_widget ( sw->name, NULL, TRUE );
ThemeWidget *wid = rofi_config_find_widget(sw->name, NULL, TRUE);
Property *p = rofi_theme_find_property ( wid, P_STRING, "directory", TRUE );
Property *p = rofi_theme_find_property(wid, P_STRING, "directory", TRUE);
gboolean config_has_valid_dir = p != NULL && p->type == P_STRING
&& g_file_test ( p->value.s, G_FILE_TEST_IS_DIR );
gboolean config_has_valid_dir = p != NULL && p->type == P_STRING &&
g_file_test(p->value.s, G_FILE_TEST_IS_DIR);
if ( config_has_valid_dir ) {
pd->current_dir = g_file_new_for_path ( p->value.s );
if (config_has_valid_dir) {
pd->current_dir = g_file_new_for_path(p->value.s);
} else {
char *current_dir = NULL;
char *cache_file = g_build_filename ( cache_dir, FILEBROWSER_CACHE_FILE, NULL );
char *cache_file =
g_build_filename(cache_dir, FILEBROWSER_CACHE_FILE, NULL);
if ( g_file_get_contents ( cache_file, &current_dir, NULL, NULL ) ) {
if ( g_file_test ( current_dir, G_FILE_TEST_IS_DIR ) ) {
pd->current_dir = g_file_new_for_path ( current_dir );
if (g_file_get_contents(cache_file, &current_dir, NULL, NULL)) {
if (g_file_test(current_dir, G_FILE_TEST_IS_DIR)) {
pd->current_dir = g_file_new_for_path(current_dir);
}
g_free ( current_dir );
g_free(current_dir);
}
// Store it based on the unique identifiers (desktop_id).
g_free ( cache_file );
g_free(cache_file);
}
if ( pd->current_dir == NULL ) {
pd->current_dir = g_file_new_for_path ( g_get_home_dir () );
if (pd->current_dir == NULL) {
pd->current_dir = g_file_new_for_path(g_get_home_dir());
}
}
static int file_browser_mode_init ( Mode *sw )
{
static int file_browser_mode_init(Mode *sw) {
/**
* Called on startup when enabled (in modi list)
*/
if ( mode_get_private_data ( sw ) == NULL ) {
FileBrowserModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
mode_set_private_data ( sw, (void *) pd );
if (mode_get_private_data(sw) == NULL) {
FileBrowserModePrivateData *pd = g_malloc0(sizeof(*pd));
mode_set_private_data(sw, (void *)pd);
file_browser_mode_init_config ( sw );
file_browser_mode_init_current_dir ( sw );
file_browser_mode_init_config(sw);
file_browser_mode_init_current_dir(sw);
// Load content.
get_file_browser ( sw );
get_file_browser(sw);
}
return TRUE;
}
static unsigned int file_browser_mode_get_num_entries ( const Mode *sw )
{
const FileBrowserModePrivateData *pd = (const FileBrowserModePrivateData *) mode_get_private_data ( sw );
static unsigned int file_browser_mode_get_num_entries(const Mode *sw) {
const FileBrowserModePrivateData *pd =
(const FileBrowserModePrivateData *)mode_get_private_data(sw);
return pd->array_length;
}
static ModeMode file_browser_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line )
{
static ModeMode file_browser_mode_result(Mode *sw, int mretv, char **input,
unsigned int selected_line) {
ModeMode retv = MODE_EXIT;
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
if ( mretv & MENU_NEXT ) {
FileBrowserModePrivateData *pd =
(FileBrowserModePrivateData *)mode_get_private_data(sw);
if (mretv & MENU_NEXT) {
retv = NEXT_DIALOG;
}
else if ( mretv & MENU_PREVIOUS ) {
} else if (mretv & MENU_PREVIOUS) {
retv = PREVIOUS_DIALOG;
}
else if ( mretv & MENU_QUICK_SWITCH ) {
retv = ( mretv & MENU_LOWER_MASK );
}
else if ( mretv & MENU_CUSTOM_COMMAND ) {
retv = ( mretv & MENU_LOWER_MASK );
}
else if ( ( mretv & MENU_OK ) ) {
if ( selected_line < pd->array_length ) {
if ( pd->array[selected_line].type == UP ) {
GFile *new = g_file_get_parent ( pd->current_dir );
if ( new ) {
g_object_unref ( pd->current_dir );
} else if (mretv & MENU_QUICK_SWITCH) {
retv = (mretv & MENU_LOWER_MASK);
} else if (mretv & MENU_CUSTOM_COMMAND) {
retv = (mretv & MENU_LOWER_MASK);
} else if ((mretv & MENU_OK)) {
if (selected_line < pd->array_length) {
if (pd->array[selected_line].type == UP) {
GFile *new = g_file_get_parent(pd->current_dir);
if (new) {
g_object_unref(pd->current_dir);
pd->current_dir = new;
free_list ( pd );
get_file_browser ( sw );
free_list(pd);
get_file_browser(sw);
return RESET_DIALOG;
}
}
else if ( pd->array[selected_line].type == DIRECTORY ) {
char *path = g_build_filename ( cache_dir, FILEBROWSER_CACHE_FILE, NULL );
g_file_set_contents ( path, pd->array[selected_line].path, -1, NULL );
g_free ( path );
GFile *new = g_file_new_for_path ( pd->array[selected_line].path );
g_object_unref ( pd->current_dir );
} else if (pd->array[selected_line].type == DIRECTORY) {
char *path = g_build_filename(cache_dir, FILEBROWSER_CACHE_FILE, NULL);
g_file_set_contents(path, pd->array[selected_line].path, -1, NULL);
g_free(path);
GFile *new = g_file_new_for_path(pd->array[selected_line].path);
g_object_unref(pd->current_dir);
pd->current_dir = new;
free_list ( pd );
get_file_browser ( sw );
free_list(pd);
get_file_browser(sw);
return RESET_DIALOG;
}
else if ( pd->array[selected_line].type == RFILE ) {
char *d = g_filename_from_utf8 ( pd->array[selected_line].path, -1, NULL, NULL, NULL );
char *d_esc = g_shell_quote ( d );
char *cmd = g_strdup_printf ( "xdg-open %s", d_esc );
g_free ( d_esc );
g_free ( d );
char *cdir = g_file_get_path ( pd->current_dir );
helper_execute_command ( cdir, cmd, FALSE, NULL );
g_free ( cdir );
g_free ( cmd );
} else if (pd->array[selected_line].type == RFILE) {
char *d = g_filename_from_utf8(pd->array[selected_line].path, -1, NULL,
NULL, NULL);
char *d_esc = g_shell_quote(d);
char *cmd = g_strdup_printf("xdg-open %s", d_esc);
g_free(d_esc);
g_free(d);
char *cdir = g_file_get_path(pd->current_dir);
helper_execute_command(cdir, cmd, FALSE, NULL);
g_free(cdir);
g_free(cmd);
return MODE_EXIT;
}
}
retv = RELOAD_DIALOG;
}
else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input ) {
char *p = rofi_expand_path ( *input );
char *dir = g_filename_from_utf8 ( p, -1, NULL, NULL, NULL );
g_free ( p );
if ( g_file_test ( dir, G_FILE_TEST_EXISTS ) ) {
if ( g_file_test ( dir, G_FILE_TEST_IS_DIR ) ) {
g_object_unref ( pd->current_dir );
pd->current_dir = g_file_new_for_path ( dir );
g_free ( dir );
free_list ( pd );
get_file_browser ( sw );
} else if ((mretv & MENU_CUSTOM_INPUT) && *input) {
char *p = rofi_expand_path(*input);
char *dir = g_filename_from_utf8(p, -1, NULL, NULL, NULL);
g_free(p);
if (g_file_test(dir, G_FILE_TEST_EXISTS)) {
if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
g_object_unref(pd->current_dir);
pd->current_dir = g_file_new_for_path(dir);
g_free(dir);
free_list(pd);
get_file_browser(sw);
return RESET_DIALOG;
}
}
g_free ( dir );
g_free(dir);
retv = RELOAD_DIALOG;
}
else if ( ( mretv & MENU_ENTRY_DELETE ) == MENU_ENTRY_DELETE ) {
} else if ((mretv & MENU_ENTRY_DELETE) == MENU_ENTRY_DELETE) {
retv = RELOAD_DIALOG;
}
return retv;
}
static void file_browser_mode_destroy ( Mode *sw )
{
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
if ( pd != NULL ) {
g_object_unref ( pd->current_dir );
free_list ( pd );
g_free ( pd );
mode_set_private_data ( sw, NULL );
static void file_browser_mode_destroy(Mode *sw) {
FileBrowserModePrivateData *pd =
(FileBrowserModePrivateData *)mode_get_private_data(sw);
if (pd != NULL) {
g_object_unref(pd->current_dir);
free_list(pd);
g_free(pd);
mode_set_private_data(sw, NULL);
}
}
static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, G_GNUC_UNUSED GList **attr_list, int get_entry )
{
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
static char *_get_display_value(const Mode *sw, unsigned int selected_line,
G_GNUC_UNUSED int *state,
G_GNUC_UNUSED GList **attr_list,
int get_entry) {
FileBrowserModePrivateData *pd =
(FileBrowserModePrivateData *)mode_get_private_data(sw);
// Only return the string if requested, otherwise only set state.
if ( !get_entry ) {
if (!get_entry) {
return NULL;
}
if ( pd->array[selected_line].type == UP ) {
return g_strdup ( " .." );
if (pd->array[selected_line].type == UP) {
return g_strdup(" ..");
}
else {
if ( pd->array[selected_line].link ) {
return g_strconcat ( "@", pd->array[selected_line].name, NULL );
if (pd->array[selected_line].link) {
return g_strconcat("@", pd->array[selected_line].name, NULL);
}
else {
return g_strdup ( pd->array[selected_line].name );
}
}
return g_strdup ( "n/a" );
return g_strdup(pd->array[selected_line].name);
}
/**
@@ -527,54 +504,55 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_
*
* @returns try when a match.
*/
static int file_browser_token_match ( const Mode *sw, rofi_int_matcher **tokens, unsigned int index )
{
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
static int file_browser_token_match(const Mode *sw, rofi_int_matcher **tokens,
unsigned int index) {
FileBrowserModePrivateData *pd =
(FileBrowserModePrivateData *)mode_get_private_data(sw);
// Call default matching function.
return helper_token_match ( tokens, pd->array[index].name );
return helper_token_match(tokens, pd->array[index].name);
}
static cairo_surface_t *_get_icon ( const Mode *sw, unsigned int selected_line, int height )
{
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
g_return_val_if_fail ( pd->array != NULL, NULL );
FBFile *dr = &( pd->array[selected_line] );
if ( dr->icon_fetch_uid > 0 ) {
return rofi_icon_fetcher_get ( dr->icon_fetch_uid );
static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line,
int height) {
FileBrowserModePrivateData *pd =
(FileBrowserModePrivateData *)mode_get_private_data(sw);
g_return_val_if_fail(pd->array != NULL, NULL);
FBFile *dr = &(pd->array[selected_line]);
if (dr->icon_fetch_uid > 0) {
return rofi_icon_fetcher_get(dr->icon_fetch_uid);
}
if ( rofi_icon_fetcher_file_is_image ( dr->path ) ) {
dr->icon_fetch_uid = rofi_icon_fetcher_query ( dr->path, height );
if (rofi_icon_fetcher_file_is_image(dr->path)) {
dr->icon_fetch_uid = rofi_icon_fetcher_query(dr->path, height);
} else {
dr->icon_fetch_uid = rofi_icon_fetcher_query(icon_name[dr->type], height);
}
else {
dr->icon_fetch_uid = rofi_icon_fetcher_query ( icon_name[dr->type], height );
}
return rofi_icon_fetcher_get ( dr->icon_fetch_uid );
return rofi_icon_fetcher_get(dr->icon_fetch_uid);
}
static char * _get_message ( const Mode *sw )
{
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
if ( pd->current_dir ) {
char *dirname = g_file_get_parse_name ( pd->current_dir );
char *str = g_markup_printf_escaped ( "<b>Current directory:</b> %s", dirname );
g_free ( dirname );
static char *_get_message(const Mode *sw) {
FileBrowserModePrivateData *pd =
(FileBrowserModePrivateData *)mode_get_private_data(sw);
if (pd->current_dir) {
char *dirname = g_file_get_parse_name(pd->current_dir);
char *str =
g_markup_printf_escaped("<b>Current directory:</b> %s", dirname);
g_free(dirname);
return str;
}
return "n/a";
}
static char *_get_completion ( const Mode *sw, unsigned int index )
{
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
static char *_get_completion(const Mode *sw, unsigned int index) {
FileBrowserModePrivateData *pd =
(FileBrowserModePrivateData *)mode_get_private_data(sw);
char *d = g_strescape ( pd->array[index].path, NULL );
char *d = g_strescape(pd->array[index].path, NULL);
return d;
}
Mode *create_new_file_browser ( void )
{
Mode *sw = g_malloc0 ( sizeof ( Mode ) );
Mode *create_new_file_browser(void) {
Mode *sw = g_malloc0(sizeof(Mode));
*sw = file_browser_mode;
@@ -583,72 +561,65 @@ Mode *create_new_file_browser ( void )
}
#if 1
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) {
ModeMode retv = MODE_EXIT;
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
if ( mretv & MENU_NEXT ) {
FileBrowserModePrivateData *pd =
(FileBrowserModePrivateData *)mode_get_private_data(sw);
if (mretv & MENU_NEXT) {
retv = NEXT_DIALOG;
}
else if ( mretv & MENU_PREVIOUS ) {
} else if (mretv & MENU_PREVIOUS) {
retv = PREVIOUS_DIALOG;
}
else if ( mretv & MENU_QUICK_SWITCH ) {
retv = ( mretv & MENU_LOWER_MASK );
}
else if ( ( mretv & MENU_OK ) ) {
if ( selected_line < pd->array_length ) {
if ( pd->array[selected_line].type == UP ) {
GFile *new = g_file_get_parent ( pd->current_dir );
if ( new ) {
g_object_unref ( pd->current_dir );
} else if (mretv & MENU_QUICK_SWITCH) {
retv = (mretv & MENU_LOWER_MASK);
} else if ((mretv & MENU_OK)) {
if (selected_line < pd->array_length) {
if (pd->array[selected_line].type == UP) {
GFile *new = g_file_get_parent(pd->current_dir);
if (new) {
g_object_unref(pd->current_dir);
pd->current_dir = new;
free_list ( pd );
get_file_browser ( sw );
free_list(pd);
get_file_browser(sw);
return RESET_DIALOG;
}
}
else if ( pd->array[selected_line].type == DIRECTORY ) {
GFile *new = g_file_new_for_path ( pd->array[selected_line].path );
g_object_unref ( pd->current_dir );
} else if (pd->array[selected_line].type == DIRECTORY) {
GFile *new = g_file_new_for_path(pd->array[selected_line].path);
g_object_unref(pd->current_dir);
pd->current_dir = new;
free_list ( pd );
get_file_browser ( sw );
free_list(pd);
get_file_browser(sw);
return RESET_DIALOG;
}
else if ( pd->array[selected_line].type == RFILE ) {
*path = g_strescape ( pd->array[selected_line].path, NULL );
} else if (pd->array[selected_line].type == RFILE) {
*path = g_strescape(pd->array[selected_line].path, NULL);
return MODE_EXIT;
}
}
retv = RELOAD_DIALOG;
}
else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input ) {
char *p = rofi_expand_path ( *input );
char *dir = g_filename_from_utf8 ( p, -1, NULL, NULL, NULL );
g_free ( p );
if ( g_file_test ( dir, G_FILE_TEST_EXISTS ) ) {
if ( g_file_test ( dir, G_FILE_TEST_IS_DIR ) ) {
g_object_unref ( pd->current_dir );
pd->current_dir = g_file_new_for_path ( dir );
g_free ( dir );
free_list ( pd );
get_file_browser ( sw );
} else if ((mretv & MENU_CUSTOM_INPUT) && *input) {
char *p = rofi_expand_path(*input);
char *dir = g_filename_from_utf8(p, -1, NULL, NULL, NULL);
g_free(p);
if (g_file_test(dir, G_FILE_TEST_EXISTS)) {
if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
g_object_unref(pd->current_dir);
pd->current_dir = g_file_new_for_path(dir);
g_free(dir);
free_list(pd);
get_file_browser(sw);
return RESET_DIALOG;
}
}
g_free ( dir );
g_free(dir);
retv = RELOAD_DIALOG;
}
else if ( ( mretv & MENU_ENTRY_DELETE ) == MENU_ENTRY_DELETE ) {
} else if ((mretv & MENU_ENTRY_DELETE) == MENU_ENTRY_DELETE) {
retv = RELOAD_DIALOG;
}
return retv;
}
#endif
Mode file_browser_mode =
{
Mode file_browser_mode = {
.display_name = NULL,
.abi_version = ABI_VERSION,
.name = "filebrowser",

View File

@@ -26,95 +26,89 @@
*/
#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
{
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 );
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,
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 );
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 );
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 ) {
if (!get_entry) {
return NULL;
}
return g_strdup ( pd->messages[selected_line] );
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 );
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",
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,
@@ -124,5 +118,4 @@ Mode help_keys_mode =
._get_completion = NULL,
._get_display_value = _get_display_value,
.private_data = NULL,
.free = NULL
};
.free = NULL};

View File

@@ -34,36 +34,35 @@
#define G_LOG_DOMAIN "Dialogs.Run"
#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 "rofi.h"
#include "settings.h"
#include "dialogs/filebrowser.h"
#include "dialogs/run.h"
#include "helper.h"
#include "history.h"
#include "dialogs/run.h"
#include "dialogs/filebrowser.h"
#include "rofi.h"
#include "settings.h"
#include "mode-private.h"
#include "timings.h"
#include "rofi-icon-fetcher.h"
#include "timings.h"
/**
* Name of the history file where previously chosen commands are stored.
*/
#define RUN_CACHE_FILE "rofi-3.runcache"
typedef struct
{
typedef struct {
char *entry;
uint32_t icon_fetch_uid;
/* Surface holding the icon. */
@@ -73,8 +72,7 @@ typedef struct
/**
* The internal data structure holding the private data of the Run Mode.
*/
typedef struct
{
typedef struct {
/** list of available commands. */
RunEntry *cmd_list;
/** Length of the #cmd_list. */
@@ -98,40 +96,39 @@ typedef struct
*
* Execute command and add to history.
*/
static gboolean exec_cmd ( const char *cmd, int run_in_term )
{
static gboolean exec_cmd(const char *cmd, int run_in_term) {
GError *error = NULL;
if ( !cmd || !cmd[0] ) {
if (!cmd || !cmd[0]) {
return FALSE;
}
gsize lf_cmd_size = 0;
gchar *lf_cmd = g_locale_from_utf8 ( cmd, -1, NULL, &lf_cmd_size, &error );
if ( error != NULL ) {
g_warning ( "Failed to convert command to locale encoding: %s", error->message );
g_error_free ( error );
gchar *lf_cmd = g_locale_from_utf8(cmd, -1, NULL, &lf_cmd_size, &error);
if (error != NULL) {
g_warning("Failed to convert command to locale encoding: %s",
error->message);
g_error_free(error);
return FALSE;
}
char *path = g_build_filename ( cache_dir, RUN_CACHE_FILE, NULL );
RofiHelperExecuteContext context = { .name = NULL };
char *path = g_build_filename(cache_dir, RUN_CACHE_FILE, NULL);
RofiHelperExecuteContext context = {.name = NULL};
// FIXME: assume startup notification support for terminals
if ( helper_execute_command ( NULL, lf_cmd, run_in_term, run_in_term ? &context : NULL ) ) {
if (helper_execute_command(NULL, lf_cmd, run_in_term,
run_in_term ? &context : NULL)) {
/**
* This happens in non-critical time (After launching app)
* It is allowed to be a bit slower.
*/
history_set ( path, cmd );
g_free ( path );
g_free ( lf_cmd );
history_set(path, cmd);
g_free(path);
g_free(lf_cmd);
return TRUE;
}
else {
history_remove ( path, cmd );
g_free ( path );
g_free ( lf_cmd );
history_remove(path, cmd);
g_free(path);
g_free(lf_cmd);
return FALSE;
}
}
/**
@@ -139,13 +136,12 @@ static gboolean exec_cmd ( const char *cmd, int run_in_term )
*
* Remove command from history.
*/
static void delete_entry ( const RunEntry *cmd )
{
char *path = g_build_filename ( cache_dir, RUN_CACHE_FILE, NULL );
static void delete_entry(const RunEntry *cmd) {
char *path = g_build_filename(cache_dir, RUN_CACHE_FILE, NULL);
history_remove ( path, cmd->entry );
history_remove(path, cmd->entry);
g_free ( path );
g_free(path);
}
/**
@@ -155,341 +151,338 @@ static void delete_entry ( const RunEntry *cmd )
*
* Function used for sorting.
*
* @returns returns less then, equal to and greater than zero is a is less than, is a match or greater than b.
* @returns returns less then, equal to and greater than zero is a is less than,
* is a match or greater than b.
*/
static int sort_func ( const void *a, const void *b, G_GNUC_UNUSED void *data )
{
const RunEntry *astr = ( const RunEntry * ) a;
const RunEntry *bstr = ( const RunEntry * ) b;
static int sort_func(const void *a, const void *b, G_GNUC_UNUSED void *data) {
const RunEntry *astr = (const RunEntry *)a;
const RunEntry *bstr = (const RunEntry *)b;
if ( astr->entry == NULL && bstr->entry == NULL ) {
if (astr->entry == NULL && bstr->entry == NULL) {
return 0;
}
else if ( astr->entry == NULL ) {
if (astr->entry == NULL) {
return 1;
}
else if ( bstr->entry == NULL ) {
if (bstr->entry == NULL) {
return -1;
}
return g_strcmp0 ( astr->entry , bstr->entry );
return g_strcmp0(astr->entry, bstr->entry);
}
/**
* External spider to get list of executables.
*/
static RunEntry * get_apps_external ( RunEntry *retv, unsigned int *length, unsigned int num_favorites )
{
int fd = execute_generator ( config.run_list_command );
if ( fd >= 0 ) {
FILE *inp = fdopen ( fd, "r" );
if ( inp ) {
static RunEntry *get_apps_external(RunEntry *retv, unsigned int *length,
unsigned int num_favorites) {
int fd = execute_generator(config.run_list_command);
if (fd >= 0) {
FILE *inp = fdopen(fd, "r");
if (inp) {
char *buffer = NULL;
size_t buffer_length = 0;
while ( getline ( &buffer, &buffer_length, inp ) > 0 ) {
while (getline(&buffer, &buffer_length, inp) > 0) {
int found = 0;
// Filter out line-end.
if ( buffer[strlen ( buffer ) - 1] == '\n' ) {
buffer[strlen ( buffer ) - 1] = '\0';
if (buffer[strlen(buffer) - 1] == '\n') {
buffer[strlen(buffer) - 1] = '\0';
}
// This is a nice little penalty, but doable? time will tell.
// given num_favorites is max 25.
for ( unsigned int j = 0; found == 0 && j < num_favorites; j++ ) {
if ( strcasecmp ( buffer, retv[j].entry ) == 0 ) {
for (unsigned int j = 0; found == 0 && j < num_favorites; j++) {
if (strcasecmp(buffer, retv[j].entry) == 0) {
found = 1;
}
}
if ( found == 1 ) {
if (found == 1) {
continue;
}
// No duplicate, add it.
retv = g_realloc ( retv, ( ( *length ) + 2 ) * sizeof ( RunEntry ) );
retv[( *length )].entry = g_strdup ( buffer );
retv[( *length )].icon = NULL;
retv[( *length )].icon_fetch_uid = 0;
retv = g_realloc(retv, ((*length) + 2) * sizeof(RunEntry));
retv[(*length)].entry = g_strdup(buffer);
retv[(*length)].icon = NULL;
retv[(*length)].icon_fetch_uid = 0;
( *length )++;
(*length)++;
}
if ( buffer != NULL ) {
free ( buffer );
if (buffer != NULL) {
free(buffer);
}
if ( fclose ( inp ) != 0 ) {
g_warning ( "Failed to close stdout off executor script: '%s'",
g_strerror ( errno ) );
if (fclose(inp) != 0) {
g_warning("Failed to close stdout off executor script: '%s'",
g_strerror(errno));
}
}
}
retv[( *length ) ].entry = NULL;
retv[( *length ) ].icon = NULL;
retv[( *length ) ].icon_fetch_uid = 0;
retv[(*length)].entry = NULL;
retv[(*length)].icon = NULL;
retv[(*length)].icon_fetch_uid = 0;
return retv;
}
/**
* Internal spider used to get list of executables.
*/
static RunEntry * get_apps ( unsigned int *length )
{
static RunEntry *get_apps(unsigned int *length) {
GError *error = NULL;
RunEntry *retv = NULL;
unsigned int num_favorites = 0;
char *path;
if ( g_getenv ( "PATH" ) == NULL ) {
if (g_getenv("PATH") == NULL) {
return NULL;
}
TICK_N ( "start" );
path = g_build_filename ( cache_dir, RUN_CACHE_FILE, NULL );
char **hretv = history_get_list ( path, length );
retv = (RunEntry*)g_malloc0((*length+1)*sizeof(RunEntry));
for ( unsigned int i = 0; i < *length; i++ ) {
TICK_N("start");
path = g_build_filename(cache_dir, RUN_CACHE_FILE, NULL);
char **hretv = history_get_list(path, length);
retv = (RunEntry *)g_malloc0((*length + 1) * sizeof(RunEntry));
for (unsigned int i = 0; i < *length; i++) {
retv[i].entry = hretv[i];
}
g_free(hretv);
g_free ( path );
g_free(path);
// Keep track of how many where loaded as favorite.
num_favorites = ( *length );
num_favorites = (*length);
path = g_strdup ( g_getenv ( "PATH" ) );
path = g_strdup(g_getenv("PATH"));
gsize l = 0;
gchar *homedir = g_locale_to_utf8 ( g_get_home_dir (), -1, NULL, &l, &error );
if ( error != NULL ) {
g_debug ( "Failed to convert homedir to UTF-8: %s", error->message );
for ( unsigned int i = 0; retv[i].entry != NULL ; i++ ) {
g_free ( retv[i].entry );
gchar *homedir = g_locale_to_utf8(g_get_home_dir(), -1, NULL, &l, &error);
if (error != NULL) {
g_debug("Failed to convert homedir to UTF-8: %s", error->message);
for (unsigned int i = 0; retv[i].entry != NULL; i++) {
g_free(retv[i].entry);
}
g_free(retv);
g_clear_error ( &error );
g_free ( homedir );
g_clear_error(&error);
g_free(homedir);
return NULL;
}
const char *const sep = ":";
char *strtok_savepointer = NULL;
for ( const char *dirname = strtok_r ( path, sep, &strtok_savepointer ); dirname != NULL; dirname = strtok_r ( NULL, sep, &strtok_savepointer ) ) {
char *fpath = rofi_expand_path ( dirname );
DIR *dir = opendir ( fpath );
g_debug ( "Checking path %s for executable.", fpath );
g_free ( fpath );
for (const char *dirname = strtok_r(path, sep, &strtok_savepointer);
dirname != NULL; dirname = strtok_r(NULL, sep, &strtok_savepointer)) {
char *fpath = rofi_expand_path(dirname);
DIR *dir = opendir(fpath);
g_debug("Checking path %s for executable.", fpath);
g_free(fpath);
if ( dir != NULL ) {
if (dir != NULL) {
struct dirent *dent;
gsize dirn_len = 0;
gchar *dirn = g_locale_to_utf8 ( dirname, -1, NULL, &dirn_len, &error );
if ( error != NULL ) {
g_debug ( "Failed to convert directory name to UTF-8: %s", error->message );
g_clear_error ( &error );
closedir ( dir );
gchar *dirn = g_locale_to_utf8(dirname, -1, NULL, &dirn_len, &error);
if (error != NULL) {
g_debug("Failed to convert directory name to UTF-8: %s",
error->message);
g_clear_error(&error);
closedir(dir);
continue;
}
gboolean is_homedir = g_str_has_prefix ( dirn, homedir );
g_free ( dirn );
gboolean is_homedir = g_str_has_prefix(dirn, homedir);
g_free(dirn);
while ( ( dent = readdir ( dir ) ) != NULL ) {
if ( dent->d_type != DT_REG && dent->d_type != DT_LNK && dent->d_type != DT_UNKNOWN ) {
while ((dent = readdir(dir)) != NULL) {
if (dent->d_type != DT_REG && dent->d_type != DT_LNK &&
dent->d_type != DT_UNKNOWN) {
continue;
}
// Skip dot files.
if ( dent->d_name[0] == '.' ) {
if (dent->d_name[0] == '.') {
continue;
}
if ( is_homedir ) {
gchar *fpath = g_build_filename ( dirname, dent->d_name, NULL );
gboolean b = g_file_test ( fpath, G_FILE_TEST_IS_EXECUTABLE );
g_free ( fpath );
if ( !b ) {
if (is_homedir) {
gchar *fpath = g_build_filename(dirname, dent->d_name, NULL);
gboolean b = g_file_test(fpath, G_FILE_TEST_IS_EXECUTABLE);
g_free(fpath);
if (!b) {
continue;
}
}
gsize name_len;
gchar *name = g_filename_to_utf8 ( dent->d_name, -1, NULL, &name_len, &error );
if ( error != NULL ) {
g_debug ( "Failed to convert filename to UTF-8: %s", error->message );
g_clear_error ( &error );
g_free ( name );
gchar *name =
g_filename_to_utf8(dent->d_name, -1, NULL, &name_len, &error);
if (error != NULL) {
g_debug("Failed to convert filename to UTF-8: %s", error->message);
g_clear_error(&error);
g_free(name);
continue;
}
// This is a nice little penalty, but doable? time will tell.
// given num_favorites is max 25.
int found = 0;
for ( unsigned int j = 0; found == 0 && j < num_favorites; j++ ) {
if ( g_strcmp0 ( name, retv[j].entry ) == 0 ) {
for (unsigned int j = 0; found == 0 && j < num_favorites; j++) {
if (g_strcmp0(name, retv[j].entry) == 0) {
found = 1;
}
}
if ( found == 1 ) {
g_free ( name );
if (found == 1) {
g_free(name);
continue;
}
retv = g_realloc ( retv, ( ( *length ) + 2 ) * sizeof ( RunEntry ) );
retv[( *length )].entry = name;
retv[( *length )].icon = NULL;
retv[( *length )].icon_fetch_uid = 0;
retv[( *length ) + 1].entry = NULL;
retv[( *length ) + 1].icon = NULL;
retv[( *length ) + 1].icon_fetch_uid = 0;
( *length )++;
retv = g_realloc(retv, ((*length) + 2) * sizeof(RunEntry));
retv[(*length)].entry = name;
retv[(*length)].icon = NULL;
retv[(*length)].icon_fetch_uid = 0;
retv[(*length) + 1].entry = NULL;
retv[(*length) + 1].icon = NULL;
retv[(*length) + 1].icon_fetch_uid = 0;
(*length)++;
}
closedir ( dir );
closedir(dir);
}
}
g_free ( homedir );
g_free(homedir);
// Get external apps.
if ( config.run_list_command != NULL && config.run_list_command[0] != '\0' ) {
retv = get_apps_external ( retv, length, num_favorites );
if (config.run_list_command != NULL && config.run_list_command[0] != '\0') {
retv = get_apps_external(retv, length, num_favorites);
}
// No sorting needed.
if ( ( *length ) == 0 ) {
if ((*length) == 0) {
return retv;
}
// TODO: check this is still fast enough. (takes 1ms on laptop.)
if ( ( *length ) > num_favorites ) {
g_qsort_with_data ( &(retv[num_favorites]), ( *length ) - num_favorites, sizeof ( RunEntry ), sort_func, NULL );
if ((*length) > num_favorites) {
g_qsort_with_data(&(retv[num_favorites]), (*length) - num_favorites,
sizeof(RunEntry), sort_func, NULL);
}
g_free ( path );
g_free(path);
unsigned int removed = 0;
for ( unsigned int index = num_favorites; index < ( ( *length ) - 1 ); index++ ) {
if ( g_strcmp0 ( retv[index].entry , retv[index + 1].entry ) == 0 ) {
g_free ( retv[index].entry );
for (unsigned int index = num_favorites; index < ((*length) - 1); index++) {
if (g_strcmp0(retv[index].entry, retv[index + 1].entry) == 0) {
g_free(retv[index].entry);
retv[index].entry = NULL;
removed++;
}
}
if ( ( *length ) > num_favorites ) {
g_qsort_with_data ( &(retv[num_favorites]), ( *length ) - num_favorites, sizeof ( RunEntry ),
sort_func,
NULL );
if ((*length) > num_favorites) {
g_qsort_with_data(&(retv[num_favorites]), (*length) - num_favorites,
sizeof(RunEntry), sort_func, NULL);
}
// Reduce array length;
( *length ) -= removed;
(*length) -= removed;
TICK_N ( "stop" );
TICK_N("stop");
return retv;
}
static int run_mode_init ( Mode *sw )
{
if ( sw->private_data == NULL ) {
RunModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
sw->private_data = (void *) pd;
pd->cmd_list = get_apps ( &( pd->cmd_list_length ) );
pd->completer = create_new_file_browser ();
mode_init ( pd->completer );
static int run_mode_init(Mode *sw) {
if (sw->private_data == NULL) {
RunModePrivateData *pd = g_malloc0(sizeof(*pd));
sw->private_data = (void *)pd;
pd->cmd_list = get_apps(&(pd->cmd_list_length));
pd->completer = create_new_file_browser();
mode_init(pd->completer);
}
return TRUE;
}
static void run_mode_destroy ( Mode *sw )
{
RunModePrivateData *rmpd = (RunModePrivateData *) sw->private_data;
if ( rmpd != NULL ) {
for ( unsigned int i = 0; i < rmpd->cmd_list_length; i++ ) {
g_free ( rmpd->cmd_list[i].entry );
if ( rmpd->cmd_list[i].icon != NULL ) {
cairo_surface_destroy ( rmpd->cmd_list[i].icon );
static void run_mode_destroy(Mode *sw) {
RunModePrivateData *rmpd = (RunModePrivateData *)sw->private_data;
if (rmpd != NULL) {
for (unsigned int i = 0; i < rmpd->cmd_list_length; i++) {
g_free(rmpd->cmd_list[i].entry);
if (rmpd->cmd_list[i].icon != NULL) {
cairo_surface_destroy(rmpd->cmd_list[i].icon);
}
}
g_free ( rmpd->cmd_list );
g_free ( rmpd->old_input );
g_free ( rmpd->old_completer_input );
mode_destroy ( rmpd->completer );
g_free ( rmpd );
g_free(rmpd->cmd_list);
g_free(rmpd->old_input);
g_free(rmpd->old_completer_input);
mode_destroy(rmpd->completer);
g_free(rmpd);
sw->private_data = NULL;
}
}
static unsigned int run_mode_get_num_entries ( const Mode *sw )
{
const RunModePrivateData *rmpd = (const RunModePrivateData *) sw->private_data;
if ( rmpd->file_complete ) {
return rmpd->completer->_get_num_entries( rmpd->completer );
static unsigned int run_mode_get_num_entries(const Mode *sw) {
const RunModePrivateData *rmpd = (const RunModePrivateData *)sw->private_data;
if (rmpd->file_complete) {
return rmpd->completer->_get_num_entries(rmpd->completer);
}
return rmpd->cmd_list_length;
}
static ModeMode run_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line )
{
RunModePrivateData *rmpd = (RunModePrivateData *) sw->private_data;
static ModeMode run_mode_result(Mode *sw, int mretv, char **input,
unsigned int selected_line) {
RunModePrivateData *rmpd = (RunModePrivateData *)sw->private_data;
ModeMode retv = MODE_EXIT;
gboolean run_in_term = ( ( mretv & MENU_CUSTOM_ACTION ) == MENU_CUSTOM_ACTION );
if ( rmpd->file_complete == TRUE ) {
gboolean run_in_term = ((mretv & MENU_CUSTOM_ACTION) == MENU_CUSTOM_ACTION);
if (rmpd->file_complete == TRUE) {
retv = RELOAD_DIALOG;
if ( ( mretv& (MENU_COMPLETE)) ) {
g_free ( rmpd->old_completer_input );
if ((mretv & (MENU_COMPLETE))) {
g_free(rmpd->old_completer_input);
rmpd->old_completer_input = *input;
*input = NULL;
if ( rmpd->selected_line < rmpd->cmd_list_length ) {
(*input) = g_strdup ( rmpd->old_input );
if (rmpd->selected_line < rmpd->cmd_list_length) {
(*input) = g_strdup(rmpd->old_input);
}
rmpd->file_complete = FALSE;
}
else if ( (mretv&MENU_CANCEL) ) {
} else if ((mretv & MENU_CANCEL)) {
retv = MODE_EXIT;
}
else {
} else {
char *path = NULL;
retv = file_browser_mode_completer ( rmpd->completer, mretv, input, selected_line, &path );
if ( retv == MODE_EXIT ) {
if ( path == NULL ) {
exec_cmd ( rmpd->cmd_list[rmpd->selected_line].entry, run_in_term );
}
else {
char *arg= g_strdup_printf ( "%s '%s'", rmpd->cmd_list[rmpd->selected_line].entry, path);
exec_cmd ( arg, run_in_term );
retv = file_browser_mode_completer(rmpd->completer, mretv, input,
selected_line, &path);
if (retv == MODE_EXIT) {
if (path == NULL) {
exec_cmd(rmpd->cmd_list[rmpd->selected_line].entry, run_in_term);
} else {
char *arg = g_strdup_printf(
"%s '%s'", rmpd->cmd_list[rmpd->selected_line].entry, path);
exec_cmd(arg, run_in_term);
g_free(arg);
}
}
g_free (path);
g_free(path);
}
return retv;
}
if ( ( mretv & MENU_OK ) && rmpd->cmd_list[selected_line].entry != NULL ) {
if ( !exec_cmd ( rmpd->cmd_list[selected_line].entry, run_in_term ) ) {
if ((mretv & MENU_OK) && rmpd->cmd_list[selected_line].entry != NULL) {
if (!exec_cmd(rmpd->cmd_list[selected_line].entry, run_in_term)) {
retv = RELOAD_DIALOG;
}
}
else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] != '\0' ) {
if ( !exec_cmd ( *input, run_in_term ) ) {
} else if ((mretv & MENU_CUSTOM_INPUT) && *input != NULL &&
*input[0] != '\0') {
if (!exec_cmd(*input, run_in_term)) {
retv = RELOAD_DIALOG;
}
}
else if ( ( mretv & MENU_ENTRY_DELETE ) && rmpd->cmd_list[selected_line].entry ) {
delete_entry ( &(rmpd->cmd_list[selected_line]) );
} else if ((mretv & MENU_ENTRY_DELETE) &&
rmpd->cmd_list[selected_line].entry) {
delete_entry(&(rmpd->cmd_list[selected_line]));
// Clear the list.
retv = RELOAD_DIALOG;
run_mode_destroy ( sw );
run_mode_init ( sw );
}
else if ( mretv & MENU_CUSTOM_COMMAND ) {
retv = ( mretv & MENU_LOWER_MASK );
}
else if ( ( mretv& MENU_COMPLETE) ) {
run_mode_destroy(sw);
run_mode_init(sw);
} else if (mretv & MENU_CUSTOM_COMMAND) {
retv = (mretv & MENU_LOWER_MASK);
} else if ((mretv & MENU_COMPLETE)) {
retv = RELOAD_DIALOG;
if ( selected_line < rmpd->cmd_list_length ) {
if (selected_line < rmpd->cmd_list_length) {
rmpd->selected_line = selected_line;
g_free ( rmpd->old_input );
rmpd->old_input = g_strdup ( *input );
g_free(rmpd->old_input);
rmpd->old_input = g_strdup(*input);
if ( *input ) g_free (*input);
*input = g_strdup ( rmpd->old_completer_input );
if (*input)
g_free(*input);
*input = g_strdup(rmpd->old_completer_input);
rmpd->file_complete = TRUE;
}
@@ -497,84 +490,85 @@ static ModeMode run_mode_result ( Mode *sw, int mretv, char **input, unsigned in
return retv;
}
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 )
{
const RunModePrivateData *rmpd = (const RunModePrivateData *) sw->private_data;
if ( rmpd->file_complete ) {
return rmpd->completer->_get_display_value (rmpd->completer, selected_line, state, list, get_entry );
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) {
const RunModePrivateData *rmpd = (const RunModePrivateData *)sw->private_data;
if (rmpd->file_complete) {
return rmpd->completer->_get_display_value(rmpd->completer, selected_line,
state, list, get_entry);
}
return get_entry ? g_strdup ( rmpd->cmd_list[selected_line].entry ) : NULL;
return get_entry ? g_strdup(rmpd->cmd_list[selected_line].entry) : NULL;
}
static int run_token_match ( const Mode *sw, rofi_int_matcher **tokens, unsigned int index )
{
const RunModePrivateData *rmpd = (const RunModePrivateData *) sw->private_data;
if ( rmpd->file_complete ) {
return rmpd->completer->_token_match (rmpd->completer, tokens, index );
static int run_token_match(const Mode *sw, rofi_int_matcher **tokens,
unsigned int index) {
const RunModePrivateData *rmpd = (const RunModePrivateData *)sw->private_data;
if (rmpd->file_complete) {
return rmpd->completer->_token_match(rmpd->completer, tokens, index);
}
return helper_token_match ( tokens, rmpd->cmd_list[index].entry );
return helper_token_match(tokens, rmpd->cmd_list[index].entry);
}
static char *run_get_message ( const Mode *sw )
{
static char *run_get_message(const Mode *sw) {
RunModePrivateData *pd = sw->private_data;
if ( pd->file_complete ) {
if ( pd->selected_line < pd->cmd_list_length ) {
char *msg = mode_get_message ( pd->completer);
if ( msg ) {
char *retv = g_strdup_printf("File complete for: %s\n%s", pd->cmd_list[pd->selected_line].entry, msg);
g_free (msg);
if (pd->file_complete) {
if (pd->selected_line < pd->cmd_list_length) {
char *msg = mode_get_message(pd->completer);
if (msg) {
char *retv =
g_strdup_printf("File complete for: %s\n%s",
pd->cmd_list[pd->selected_line].entry, msg);
g_free(msg);
return retv;
}
return g_strdup_printf("File complete for: %s", pd->cmd_list[pd->selected_line].entry);
return g_strdup_printf("File complete for: %s",
pd->cmd_list[pd->selected_line].entry);
}
}
return NULL;
}
static cairo_surface_t *fallback_icon ( RunModePrivateData *pd, int height )
{
if ( config.application_fallback_icon ) {
static cairo_surface_t *fallback_icon(RunModePrivateData *pd, int height) {
if (config.application_fallback_icon) {
// FALLBACK
if ( pd->fallback_icon_fetch_uid > 0 ) {
return rofi_icon_fetcher_get ( pd->fallback_icon_fetch_uid );
if (pd->fallback_icon_fetch_uid > 0) {
return rofi_icon_fetcher_get(pd->fallback_icon_fetch_uid);
}
pd->fallback_icon_fetch_uid = rofi_icon_fetcher_query ( config.application_fallback_icon, height );
pd->fallback_icon_fetch_uid =
rofi_icon_fetcher_query(config.application_fallback_icon, height);
}
return NULL;
}
static cairo_surface_t *_get_icon ( const Mode *sw, unsigned int selected_line, int height )
{
RunModePrivateData *pd = (RunModePrivateData *) mode_get_private_data ( sw );
if ( pd->file_complete ) {
return pd->completer->_get_icon ( pd->completer, selected_line, height );
static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line,
int height) {
RunModePrivateData *pd = (RunModePrivateData *)mode_get_private_data(sw);
if (pd->file_complete) {
return pd->completer->_get_icon(pd->completer, selected_line, height);
}
g_return_val_if_fail ( pd->cmd_list != NULL, NULL );
RunEntry *dr = &( pd->cmd_list[selected_line] );
g_return_val_if_fail(pd->cmd_list != NULL, NULL);
RunEntry *dr = &(pd->cmd_list[selected_line]);
if ( dr->icon_fetch_uid > 0 ) {
cairo_surface_t *icon = rofi_icon_fetcher_get ( dr->icon_fetch_uid );
if ( icon ) {
if (dr->icon_fetch_uid > 0) {
cairo_surface_t *icon = rofi_icon_fetcher_get(dr->icon_fetch_uid);
if (icon) {
return icon;
}
return fallback_icon ( pd, height );
return fallback_icon(pd, height);
}
/** lookup icon */
char ** str = g_strsplit(dr->entry, " ", 2);
if ( str ) {
dr->icon_fetch_uid = rofi_icon_fetcher_query ( str[0], height );
g_strfreev ( str );
cairo_surface_t *icon = rofi_icon_fetcher_get ( dr->icon_fetch_uid );
if ( icon ) {
char **str = g_strsplit(dr->entry, " ", 2);
if (str) {
dr->icon_fetch_uid = rofi_icon_fetcher_query(str[0], height);
g_strfreev(str);
cairo_surface_t *icon = rofi_icon_fetcher_get(dr->icon_fetch_uid);
if (icon) {
return icon;
}
}
return fallback_icon ( pd, height );
return fallback_icon(pd, height);
}
#include "mode-private.h"
Mode run_mode =
{
.name = "run",
Mode run_mode = {.name = "run",
.cfg_name_key = "display-run",
._init = run_mode_init,
._get_num_entries = run_mode_get_num_entries,
@@ -587,6 +581,5 @@ Mode run_mode =
._get_completion = NULL,
._preprocess_input = NULL,
.private_data = NULL,
.free = NULL
};
.free = NULL};
/** @}*/

View File

@@ -28,18 +28,17 @@
/** The log domain of this dialog. */
#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,8 +48,7 @@
#include "dialogs/dmenuscriptshared.h"
typedef struct
{
typedef struct {
/** ID of the current script. */
unsigned int id;
/** List of visible items. */
@@ -59,10 +57,10 @@ typedef struct
unsigned int cmd_list_length;
/** Urgent list */
struct rofi_range_pair * urgent_list;
struct rofi_range_pair *urgent_list;
unsigned int num_urgent_list;
/** Active list */
struct rofi_range_pair * active_list;
struct rofi_range_pair *active_list;
unsigned int num_active_list;
/** Configuration settings. */
char *message;
@@ -78,82 +76,72 @@ typedef struct
/**
* 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 );
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 ) {
for (extra = extras; *extra != NULL && *(extra + 1) != NULL; extra += 2) {
gchar *key = *extra;
gchar *value = *( extra + 1 );
if ( strcasecmp ( key, "icon" ) == 0 ) {
gchar *value = *(extra + 1);
if (strcasecmp(key, "icon") == 0) {
entry->icon_name = value;
}
else if ( strcasecmp ( key, "meta" ) == 0 ) {
} else if (strcasecmp(key, "meta") == 0) {
entry->meta = value;
}
else if ( strcasecmp ( key, "info" ) == 0 ) {
} 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);
}
else if ( strcasecmp ( key, "nonselectable" ) == 0 ) {
entry->nonselectable = strcasecmp ( value, "true" ) == 0;
g_free ( value );
g_free(key);
}
else {
g_free ( value );
}
g_free ( key );
}
g_free ( extras );
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' ) {
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 ) {
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 );
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 );
} 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;
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;
@@ -162,172 +150,173 @@ static DmenuScriptEntry *execute_executor ( Mode *sw, char *arg, unsigned int *l
*length = 0;
// Environment
char ** env = g_get_environ ();
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 );
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_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 );
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 );
g_error_free(error);
fd = -1;
}
if ( fd >= 0 ) {
FILE *inp = fdopen ( fd, "r" );
if ( inp ) {
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 ) {
while ((read_length = getdelim(&buffer, &buffer_length, pd->delim, inp)) >
0) {
// Filter out line-end.
if ( buffer[read_length - 1] == pd->delim ) {
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 ) ) {
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 ) );
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 );
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 )++;
retv[(*length) + 1].entry = NULL;
(*length)++;
}
}
if ( buffer ) {
free ( buffer );
if (buffer) {
free(buffer);
}
if ( fclose ( inp ) != 0 ) {
g_warning ( "Failed to close stdout off executor script: '%s'",
g_strerror ( errno ) );
if (fclose(inp) != 0) {
g_warning("Failed to close stdout off executor script: '%s'",
g_strerror(errno));
}
}
}
g_strfreev ( argv );
g_strfreev(argv);
return retv;
}
static void script_switcher_free ( Mode *sw )
{
if ( sw == NULL ) {
static void script_switcher_free(Mode *sw) {
if (sw == NULL) {
return;
}
g_free ( sw->name );
g_free ( sw->ed );
g_free ( sw );
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 ) );
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 );
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;
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 );
g_free(rmpd->urgent_list);
rmpd->urgent_list = NULL;
rmpd->num_active_list = 0;
g_free ( rmpd->active_list );
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;
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 {
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 );
} 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 ) {
} 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_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 {
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 );
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 );
g_free(rmpd->cmd_list);
rmpd->cmd_list = new_list;
rmpd->cmd_list_length = new_length;
@@ -336,117 +325,117 @@ static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned
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 );
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 );
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 ) {
static inline unsigned int get_index(unsigned int length, int index) {
if (index >= 0) {
return index;
}
if ( ( (unsigned int) -index ) <= length ) {
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 )
{
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 ) {
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 ) {
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 ) {
if (pd->do_markup) {
*state |= MARKUP;
}
return get_entry ? g_strdup ( pd->cmd_list[selected_line].entry ) : NULL;
return get_entry ? g_strdup(pd->cmd_list[selected_line].entry) : NULL;
}
static int script_token_match ( const Mode *sw, rofi_int_matcher **tokens, unsigned int index )
{
static int script_token_match(const Mode *sw, rofi_int_matcher **tokens,
unsigned int index) {
ScriptModePrivateData *rmpd = sw->private_data;
int match = 1;
if ( tokens ) {
for ( int j = 0; match && tokens != NULL && tokens[j] != NULL; j++ ) {
rofi_int_matcher *ftokens[2] = { tokens[j], NULL };
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 );
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 ) {
if (test == 0) {
match = 0;
}
}
}
return match;
}
static char *script_get_message ( const Mode *sw )
{
static char *script_get_message(const Mode *sw) {
ScriptModePrivateData *pd = sw->private_data;
return g_strdup ( pd->message );
return g_strdup(pd->message);
}
static cairo_surface_t *script_get_icon ( const Mode *sw, unsigned int selected_line, int height )
{
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 ) {
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 );
if (dr->icon_fetch_uid > 0) {
return rofi_icon_fetcher_get(dr->icon_fetch_uid);
}
dr->icon_fetch_uid = rofi_icon_fetcher_query ( dr->icon_name, height );
return rofi_icon_fetcher_get ( dr->icon_fetch_uid );
dr->icon_fetch_uid = rofi_icon_fetcher_query(dr->icon_name, height);
return rofi_icon_fetcher_get(dr->icon_fetch_uid);
}
#include "mode-private.h"
Mode *script_switcher_parse_setup ( const char *str )
{
Mode *sw = g_malloc0 ( sizeof ( *sw ) );
Mode *script_switcher_parse_setup(const char *str) {
Mode *sw = g_malloc0(sizeof(*sw));
char *endp = NULL;
char *parse = g_strdup ( str );
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 );
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++;
}
g_free ( parse );
if ( index == 2 ) {
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;
@@ -455,18 +444,19 @@ Mode *script_switcher_parse_setup ( const char *str )
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_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 );
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;
}

View File

@@ -37,30 +37,29 @@
#include <config.h>
#include <glib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <dirent.h>
#include <strings.h>
#include <string.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <helper.h>
#include <glob.h>
#include <helper.h>
#include <signal.h>
#include <string.h>
#include <strings.h>
#include <sys/types.h>
#include <unistd.h>
#include "dialogs/ssh.h"
#include "history.h"
#include "rofi.h"
#include "settings.h"
#include "history.h"
#include "dialogs/ssh.h"
/**
* Holding an ssh entry.
*/
typedef struct _SshEntry
{
typedef struct _SshEntry {
/** SSH hostname */
char *hostname;
/** SSH port number */
@@ -69,8 +68,7 @@ typedef struct _SshEntry
/**
* The internal data structure holding the private data of the SSH Mode.
*/
typedef struct
{
typedef struct {
GList *user_known_hosts;
/** List if available ssh hosts.*/
SshEntry *hosts_list;
@@ -96,31 +94,28 @@ typedef struct
*
* @returns FALSE On failure, TRUE on success
*/
static int execshssh ( const SshEntry *entry )
{
static int execshssh(const SshEntry *entry) {
char **args = NULL;
int argsv = 0;
gchar *portstr = NULL;
if ( entry->port > 0 ) {
portstr = g_strdup_printf ( "%d", entry->port );
if (entry->port > 0) {
portstr = g_strdup_printf("%d", entry->port);
}
helper_parse_setup ( config.ssh_command, &args, &argsv,
"{host}", entry->hostname,
"{port}", portstr,
(char *) 0 );
g_free ( portstr );
helper_parse_setup(config.ssh_command, &args, &argsv, "{host}",
entry->hostname, "{port}", portstr, (char *)0);
g_free(portstr);
gsize l = strlen ( "Connecting to '' via rofi" ) + strlen ( entry->hostname ) + 1;
gchar *desc = g_newa ( gchar, l );
gsize l = strlen("Connecting to '' via rofi") + strlen(entry->hostname) + 1;
gchar *desc = g_newa(gchar, l);
g_snprintf ( desc, l, "Connecting to '%s' via rofi", entry->hostname );
g_snprintf(desc, l, "Connecting to '%s' via rofi", entry->hostname);
RofiHelperExecuteContext context = {
.name = "ssh",
.description = desc,
.command = "ssh",
};
return helper_execute ( NULL, args, "ssh ", entry->hostname, &context );
return helper_execute(NULL, args, "ssh ", entry->hostname, &context);
}
/**
@@ -128,29 +123,27 @@ static int execshssh ( const SshEntry *entry )
*
* SSH into the selected host, if successful update history.
*/
static void exec_ssh ( const SshEntry *entry )
{
if ( !( entry->hostname ) || !( entry->hostname[0] ) ) {
static void exec_ssh(const SshEntry *entry) {
if (!(entry->hostname) || !(entry->hostname[0])) {
return;
}
if ( !execshssh ( entry ) ) {
if (!execshssh(entry)) {
return;
}
// This happens in non-critical time (After launching app)
// It is allowed to be a bit slower.
char *path = g_build_filename ( cache_dir, SSH_CACHE_FILE, NULL );
char *path = g_build_filename(cache_dir, SSH_CACHE_FILE, NULL);
// TODO update.
if ( entry->port > 0 ) {
char *store = g_strdup_printf ( "%s\x1F%d", entry->hostname, entry->port );
history_set ( path, store );
g_free ( store );
if (entry->port > 0) {
char *store = g_strdup_printf("%s\x1F%d", entry->hostname, entry->port);
history_set(path, store);
g_free(store);
} else {
history_set(path, entry->hostname);
}
else {
history_set ( path, entry->hostname );
}
g_free ( path );
g_free(path);
}
/**
@@ -158,14 +151,13 @@ static void exec_ssh ( const SshEntry *entry )
*
* Remove host from history.
*/
static void delete_ssh ( const char *host )
{
if ( !host || !host[0] ) {
static void delete_ssh(const char *host) {
if (!host || !host[0]) {
return;
}
char *path = g_build_filename ( cache_dir, SSH_CACHE_FILE, NULL );
history_remove ( path, host );
g_free ( path );
char *path = g_build_filename(cache_dir, SSH_CACHE_FILE, NULL);
history_remove(path, host);
g_free(path);
}
/**
@@ -177,54 +169,53 @@ static void delete_ssh ( const char *host )
*
* @returns updated list of hosts.
*/
static SshEntry *read_known_hosts_file ( const char *path, SshEntry * retv, unsigned int *length )
{
FILE *fd = fopen ( path, "r" );
if ( fd != NULL ) {
static SshEntry *read_known_hosts_file(const char *path, SshEntry *retv,
unsigned int *length) {
FILE *fd = fopen(path, "r");
if (fd != NULL) {
char *buffer = NULL;
size_t buffer_length = 0;
// Reading one line per time.
while ( getline ( &buffer, &buffer_length, fd ) > 0 ) {
while (getline(&buffer, &buffer_length, fd) > 0) {
// Strip whitespace.
char *start = g_strstrip ( &( buffer[0] ) );
char *start = g_strstrip(&(buffer[0]));
// Find start.
if ( *start == '#' || *start == '@' ) {
if (*start == '#' || *start == '@') {
// skip comments or cert-authority or revoked items.
continue;
}
if ( *start == '|' ) {
if (*start == '|') {
// Skip hashed hostnames.
continue;
}
// Find end of hostname set.
char *end = strstr ( start, " " );
if ( end == NULL ) {
char *end = strstr(start, " ");
if (end == NULL) {
// Something is wrong.
continue;
}
*end = '\0';
char *sep = start;
start = strsep ( &sep, ", " );
while ( start ) {
start = strsep(&sep, ", ");
while (start) {
int port = 0;
if ( start[0] == '[' ) {
if (start[0] == '[') {
start++;
char *end = strchr ( start, ']' );
if ( end[1] == ':' ) {
char *end = strchr(start, ']');
if (end[1] == ':') {
*end = '\0';
errno = 0;
gchar *endptr = NULL;
gint64 number = g_ascii_strtoll ( &( end[2] ), &endptr, 10 );
if ( errno != 0 ) {
g_warning ( "Failed to parse port number: %s.", &( end[2] ) );
}
else if ( endptr == &( end[2] ) ) {
g_warning ( "Failed to parse port number: %s, invalid number.", &( end[2] ) );
}
else if ( number < 0 || number > 65535 ) {
g_warning ( "Failed to parse port number: %s, out of range.", &( end[2] ) );
}
else {
gint64 number = g_ascii_strtoll(&(end[2]), &endptr, 10);
if (errno != 0) {
g_warning("Failed to parse port number: %s.", &(end[2]));
} else if (endptr == &(end[2])) {
g_warning("Failed to parse port number: %s, invalid number.",
&(end[2]));
} else if (number < 0 || number > 65535) {
g_warning("Failed to parse port number: %s, out of range.",
&(end[2]));
} else {
port = number;
}
}
@@ -232,34 +223,33 @@ static SshEntry *read_known_hosts_file ( const char *path, SshEntry * retv, unsi
// Is this host name already in the list?
// We often get duplicates in hosts file, so lets check this.
int found = 0;
for ( unsigned int j = 0; j < ( *length ); j++ ) {
if ( !g_ascii_strcasecmp ( start, retv[j].hostname ) ) {
for (unsigned int j = 0; j < (*length); j++) {
if (!g_ascii_strcasecmp(start, retv[j].hostname)) {
found = 1;
break;
}
}
if ( !found ) {
if (!found) {
// Add this host name to the list.
retv = g_realloc ( retv, ( ( *length ) + 2 ) * sizeof ( SshEntry ) );
retv[( *length )].hostname = g_strdup ( start );
retv[( *length )].port = port;
retv[( *length ) + 1].hostname = NULL;
retv[( *length ) + 1].port = 0;
( *length )++;
retv = g_realloc(retv, ((*length) + 2) * sizeof(SshEntry));
retv[(*length)].hostname = g_strdup(start);
retv[(*length)].port = port;
retv[(*length) + 1].hostname = NULL;
retv[(*length) + 1].port = 0;
(*length)++;
}
start = strsep ( &sep, ", " );
start = strsep(&sep, ", ");
}
}
if ( buffer != NULL ) {
free ( buffer );
if (buffer != NULL) {
free(buffer);
}
if ( fclose ( fd ) != 0 ) {
g_warning ( "Failed to close hosts file: '%s'", g_strerror ( errno ) );
if (fclose(fd) != 0) {
g_warning("Failed to close hosts file: '%s'", g_strerror(errno));
}
}
else {
g_debug ( "Failed to open KnownHostFile: '%s'", path );
} else {
g_debug("Failed to open KnownHostFile: '%s'", path);
}
return retv;
@@ -273,15 +263,14 @@ static SshEntry *read_known_hosts_file ( const char *path, SshEntry * retv, unsi
*
* @returns an updated list with the added hosts.
*/
static SshEntry *read_hosts_file ( SshEntry * retv, unsigned int *length )
{
static SshEntry *read_hosts_file(SshEntry *retv, unsigned int *length) {
// Read the hosts file.
FILE *fd = fopen ( "/etc/hosts", "r" );
if ( fd != NULL ) {
FILE *fd = fopen("/etc/hosts", "r");
if (fd != NULL) {
char *buffer = NULL;
size_t buffer_length = 0;
// Reading one line per time.
while ( getline ( &buffer, &buffer_length, fd ) > 0 ) {
while (getline(&buffer, &buffer_length, fd) > 0) {
// Evaluate one line.
unsigned int index = 0, ti = 0;
char *token = buffer;
@@ -290,136 +279,133 @@ static SshEntry *read_hosts_file ( SshEntry * retv, unsigned int *length )
do {
char c = buffer[index];
// Break on space, tab, newline and \0.
if ( c == ' ' || c == '\t' || c == '\n' || c == '\0' || c == '#' ) {
if (c == ' ' || c == '\t' || c == '\n' || c == '\0' || c == '#') {
buffer[index] = '\0';
// Ignore empty tokens
if ( token[0] != '\0' ) {
if (token[0] != '\0') {
ti++;
// and first token.
if ( ti > 1 ) {
if (ti > 1) {
// Is this host name already in the list?
// We often get duplicates in hosts file, so lets check this.
int found = 0;
for ( unsigned int j = 0; j < ( *length ); j++ ) {
if ( !g_ascii_strcasecmp ( token, retv[j].hostname ) ) {
for (unsigned int j = 0; j < (*length); j++) {
if (!g_ascii_strcasecmp(token, retv[j].hostname)) {
found = 1;
break;
}
}
if ( !found ) {
if (!found) {
// Add this host name to the list.
retv = g_realloc ( retv,
( ( *length ) + 2 ) * sizeof ( SshEntry ) );
retv[( *length )].hostname = g_strdup ( token );
retv[( *length )].port = 0;
retv[( *length ) + 1].hostname = NULL;
( *length )++;
retv = g_realloc(retv, ((*length) + 2) * sizeof(SshEntry));
retv[(*length)].hostname = g_strdup(token);
retv[(*length)].port = 0;
retv[(*length) + 1].hostname = NULL;
(*length)++;
}
}
}
// Set start to next element.
token = &buffer[index + 1];
// Everything after comment ignore.
if ( c == '#' ) {
if (c == '#') {
break;
}
}
// Skip to the next entry.
index++;
} while ( buffer[index] != '\0' && buffer[index] != '#' );
} while (buffer[index] != '\0' && buffer[index] != '#');
}
if ( buffer != NULL ) {
free ( buffer );
if (buffer != NULL) {
free(buffer);
}
if ( fclose ( fd ) != 0 ) {
g_warning ( "Failed to close hosts file: '%s'", g_strerror ( errno ) );
if (fclose(fd) != 0) {
g_warning("Failed to close hosts file: '%s'", g_strerror(errno));
}
}
return retv;
}
static void add_known_hosts_file ( SSHModePrivateData *pd, const char *token )
{
GList *item = g_list_find_custom ( pd->user_known_hosts, token, (GCompareFunc) g_strcmp0 );
if ( item == NULL ) {
g_debug ( "Add '%s' to UserKnownHost list", token );
pd->user_known_hosts = g_list_append ( pd->user_known_hosts, g_strdup ( token ) );
}
else {
g_debug ( "File '%s' already in UserKnownHostsFile list", token );
static void add_known_hosts_file(SSHModePrivateData *pd, const char *token) {
GList *item =
g_list_find_custom(pd->user_known_hosts, token, (GCompareFunc)g_strcmp0);
if (item == NULL) {
g_debug("Add '%s' to UserKnownHost list", token);
pd->user_known_hosts = g_list_append(pd->user_known_hosts, g_strdup(token));
} else {
g_debug("File '%s' already in UserKnownHostsFile list", token);
}
}
static void parse_ssh_config_file ( SSHModePrivateData *pd, const char *filename, SshEntry **retv, unsigned int *length, unsigned int num_favorites )
{
FILE *fd = fopen ( filename, "r" );
static void parse_ssh_config_file(SSHModePrivateData *pd, const char *filename,
SshEntry **retv, unsigned int *length,
unsigned int num_favorites) {
FILE *fd = fopen(filename, "r");
g_debug ( "Parsing ssh config file: %s", filename );
if ( fd != NULL ) {
g_debug("Parsing ssh config file: %s", filename);
if (fd != NULL) {
char *buffer = NULL;
size_t buffer_length = 0;
char *strtok_pointer = NULL;
while ( getline ( &buffer, &buffer_length, fd ) > 0 ) {
while (getline(&buffer, &buffer_length, fd) > 0) {
// Each line is either empty, a comment line starting with a '#'
// character or of the form "keyword [=] arguments", where there may
// be multiple (possibly quoted) arguments separated by whitespace.
// The keyword is separated from its arguments by whitespace OR by
// optional whitespace and a '=' character.
char *token = strtok_r ( buffer, SSH_TOKEN_DELIM, &strtok_pointer );
char *token = strtok_r(buffer, SSH_TOKEN_DELIM, &strtok_pointer);
// Skip empty lines and comment lines. Also skip lines where the
// keyword is not "Host".
if ( !token || *token == '#' ) {
if (!token || *token == '#') {
continue;
}
char *low_token = g_ascii_strdown ( token, -1 );
if ( g_strcmp0 ( low_token, "include" ) == 0 ) {
token = strtok_r ( NULL, SSH_TOKEN_DELIM, &strtok_pointer );
g_debug ( "Found Include: %s", token );
gchar *path = rofi_expand_path ( token );
char *low_token = g_ascii_strdown(token, -1);
if (g_strcmp0(low_token, "include") == 0) {
token = strtok_r(NULL, SSH_TOKEN_DELIM, &strtok_pointer);
g_debug("Found Include: %s", token);
gchar *path = rofi_expand_path(token);
gchar *full_path = NULL;
if ( !g_path_is_absolute ( path ) ) {
char *dirname = g_path_get_dirname ( filename );
full_path = g_build_filename ( dirname, path, NULL );
g_free ( dirname );
if (!g_path_is_absolute(path)) {
char *dirname = g_path_get_dirname(filename);
full_path = g_build_filename(dirname, path, NULL);
g_free(dirname);
} else {
full_path = g_strdup(path);
}
else {
full_path = g_strdup ( path );
}
glob_t globbuf = { .gl_pathc = 0, .gl_pathv = NULL, .gl_offs = 0 };
glob_t globbuf = {.gl_pathc = 0, .gl_pathv = NULL, .gl_offs = 0};
if ( glob ( full_path, 0, NULL, &globbuf ) == 0 ) {
for ( size_t iter = 0; iter < globbuf.gl_pathc; iter++ ) {
parse_ssh_config_file ( pd, globbuf.gl_pathv[iter], retv, length, num_favorites );
if (glob(full_path, 0, NULL, &globbuf) == 0) {
for (size_t iter = 0; iter < globbuf.gl_pathc; iter++) {
parse_ssh_config_file(pd, globbuf.gl_pathv[iter], retv, length,
num_favorites);
}
}
globfree ( &globbuf );
globfree(&globbuf);
g_free ( full_path );
g_free ( path );
g_free(full_path);
g_free(path);
} else if (g_strcmp0(low_token, "userknownhostsfile") == 0) {
while ((token = strtok_r(NULL, SSH_TOKEN_DELIM, &strtok_pointer))) {
g_debug("Found extra UserKnownHostsFile: %s", token);
add_known_hosts_file(pd, token);
}
else if ( g_strcmp0 ( low_token, "userknownhostsfile" ) == 0 ) {
while ( ( token = strtok_r ( NULL, SSH_TOKEN_DELIM, &strtok_pointer ) ) ) {
g_debug ( "Found extra UserKnownHostsFile: %s", token );
add_known_hosts_file ( pd, token );
}
}
else if ( g_strcmp0 ( low_token, "host" ) == 0 ) {
} else if (g_strcmp0(low_token, "host") == 0) {
// Now we know that this is a "Host" line.
// The "Host" keyword is followed by one more host names separated
// by whitespace; while host names may be quoted with double quotes
// to represent host names containing spaces, we don't support this
// (how many host names contain spaces?).
while ( ( token = strtok_r ( NULL, SSH_TOKEN_DELIM, &strtok_pointer ) ) ) {
while ((token = strtok_r(NULL, SSH_TOKEN_DELIM, &strtok_pointer))) {
// We do not want to show wildcard entries, as you cannot ssh to them.
const char *const sep = "*?";
if ( *token == '!' || strpbrk ( token, sep ) ) {
if (*token == '!' || strpbrk(token, sep)) {
continue;
}
// If comment, skip from now on.
if ( *token == '#' ) {
if (*token == '#') {
break;
}
@@ -427,33 +413,34 @@ static void parse_ssh_config_file ( SSHModePrivateData *pd, const char *filename
// This is a nice little penalty, but doable? time will tell.
// given num_favorites is max 25.
int found = 0;
for ( unsigned int j = 0; j < num_favorites; j++ ) {
if ( !g_ascii_strcasecmp ( token, ( *retv )[j].hostname ) ) {
for (unsigned int j = 0; j < num_favorites; j++) {
if (!g_ascii_strcasecmp(token, (*retv)[j].hostname)) {
found = 1;
break;
}
}
if ( found ) {
if (found) {
continue;
}
// Add this host name to the list.
( *retv ) = g_realloc ( ( *retv ), ( ( *length ) + 2 ) * sizeof ( SshEntry ) );
( *retv )[( *length )].hostname = g_strdup ( token );
( *retv )[( *length )].port = 0;
( *retv )[( *length ) + 1].hostname = NULL;
( *length )++;
(*retv) = g_realloc((*retv), ((*length) + 2) * sizeof(SshEntry));
(*retv)[(*length)].hostname = g_strdup(token);
(*retv)[(*length)].port = 0;
(*retv)[(*length) + 1].hostname = NULL;
(*length)++;
}
}
g_free ( low_token );
g_free(low_token);
}
if ( buffer != NULL ) {
free ( buffer );
if (buffer != NULL) {
free(buffer);
}
if ( fclose ( fd ) != 0 ) {
g_warning ( "Failed to close ssh configuration file: '%s'", g_strerror ( errno ) );
if (fclose(fd) != 0) {
g_warning("Failed to close ssh configuration file: '%s'",
g_strerror(errno));
}
}
}
@@ -466,68 +453,68 @@ static void parse_ssh_config_file ( SSHModePrivateData *pd, const char *filename
*
* @returns an array of strings containing all the hosts.
*/
static SshEntry * get_ssh ( SSHModePrivateData *pd, unsigned int *length )
{
static SshEntry *get_ssh(SSHModePrivateData *pd, unsigned int *length) {
SshEntry *retv = NULL;
unsigned int num_favorites = 0;
char *path;
if ( g_get_home_dir () == NULL ) {
if (g_get_home_dir() == NULL) {
return NULL;
}
path = g_build_filename ( cache_dir, SSH_CACHE_FILE, NULL );
char **h = history_get_list ( path, length );
path = g_build_filename(cache_dir, SSH_CACHE_FILE, NULL);
char **h = history_get_list(path, length);
retv = malloc ( ( *length ) * sizeof ( SshEntry ) );
for ( unsigned int i = 0; i < ( *length ); i++ ) {
retv = malloc((*length) * sizeof(SshEntry));
for (unsigned int i = 0; i < (*length); i++) {
int port = 0;
char *portstr = strchr ( h[i], '\x1F' );
if ( portstr != NULL ) {
char *portstr = strchr(h[i], '\x1F');
if (portstr != NULL) {
*portstr = '\0';
errno = 0;
gchar *endptr = NULL;
gint64 number = g_ascii_strtoll ( &( portstr[1] ), &endptr, 10 );
if ( errno != 0 ) {
g_warning ( "Failed to parse port number: %s.", &( portstr[1] ) );
}
else if ( endptr == &( portstr[1] ) ) {
g_warning ( "Failed to parse port number: %s, invalid number.", &( portstr[1] ) );
}
else if ( number < 0 || number > 65535 ) {
g_warning ( "Failed to parse port number: %s, out of range.", &( portstr[1] ) );
}
else {
gint64 number = g_ascii_strtoll(&(portstr[1]), &endptr, 10);
if (errno != 0) {
g_warning("Failed to parse port number: %s.", &(portstr[1]));
} else if (endptr == &(portstr[1])) {
g_warning("Failed to parse port number: %s, invalid number.",
&(portstr[1]));
} else if (number < 0 || number > 65535) {
g_warning("Failed to parse port number: %s, out of range.",
&(portstr[1]));
} else {
port = number;
}
}
retv[i].hostname = h[i];
retv[i].port = port;
}
g_free ( h );
g_free(h);
g_free ( path );
num_favorites = ( *length );
g_free(path);
num_favorites = (*length);
const char *hd = g_get_home_dir ();
path = g_build_filename ( hd, ".ssh", "config", NULL );
parse_ssh_config_file ( pd, path, &retv, length, num_favorites );
const char *hd = g_get_home_dir();
path = g_build_filename(hd, ".ssh", "config", NULL);
parse_ssh_config_file(pd, path, &retv, length, num_favorites);
if ( config.parse_known_hosts == TRUE ) {
char *path = g_build_filename ( g_get_home_dir (), ".ssh", "known_hosts", NULL );
retv = read_known_hosts_file ( path, retv, length );
g_free ( path );
for ( GList *iter = g_list_first ( pd->user_known_hosts ); iter; iter = g_list_next ( iter ) ) {
char *path = rofi_expand_path ( (const char *) iter->data );
retv = read_known_hosts_file ( (const char *) path, retv, length );
g_free ( path );
if (config.parse_known_hosts == TRUE) {
char *path =
g_build_filename(g_get_home_dir(), ".ssh", "known_hosts", NULL);
retv = read_known_hosts_file(path, retv, length);
g_free(path);
for (GList *iter = g_list_first(pd->user_known_hosts); iter;
iter = g_list_next(iter)) {
char *path = rofi_expand_path((const char *)iter->data);
retv = read_known_hosts_file((const char *)path, retv, length);
g_free(path);
}
}
if ( config.parse_hosts == TRUE ) {
retv = read_hosts_file ( retv, length );
if (config.parse_hosts == TRUE) {
retv = read_hosts_file(retv, length);
}
g_free ( path );
g_free(path);
return retv;
}
@@ -538,12 +525,11 @@ static SshEntry * get_ssh ( SSHModePrivateData *pd, unsigned int *length )
* Initializes the SSH Mode private data object and
* loads the relevant ssh information.
*/
static int ssh_mode_init ( Mode *sw )
{
if ( mode_get_private_data ( sw ) == NULL ) {
SSHModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
mode_set_private_data ( sw, (void *) pd );
pd->hosts_list = get_ssh ( pd, &( pd->hosts_list_length ) );
static int ssh_mode_init(Mode *sw) {
if (mode_get_private_data(sw) == NULL) {
SSHModePrivateData *pd = g_malloc0(sizeof(*pd));
mode_set_private_data(sw, (void *)pd);
pd->hosts_list = get_ssh(pd, &(pd->hosts_list_length));
}
return TRUE;
}
@@ -555,27 +541,27 @@ static int ssh_mode_init ( Mode *sw )
*
* @returns the number of ssh entries.
*/
static unsigned int ssh_mode_get_num_entries ( const Mode *sw )
{
const SSHModePrivateData *rmpd = (const SSHModePrivateData *) mode_get_private_data ( sw );
static unsigned int ssh_mode_get_num_entries(const Mode *sw) {
const SSHModePrivateData *rmpd =
(const SSHModePrivateData *)mode_get_private_data(sw);
return rmpd->hosts_list_length;
}
/**
* @param sw Object handle to the SSH Mode object
*
* Cleanup the SSH Mode. Free all allocated memory and NULL the private data pointer.
* Cleanup the SSH Mode. Free all allocated memory and NULL the private data
* pointer.
*/
static void ssh_mode_destroy ( Mode *sw )
{
SSHModePrivateData *rmpd = (SSHModePrivateData *) mode_get_private_data ( sw );
if ( rmpd != NULL ) {
for ( unsigned int i = 0; i < rmpd->hosts_list_length; i++ ) {
g_free ( rmpd->hosts_list[i].hostname );
static void ssh_mode_destroy(Mode *sw) {
SSHModePrivateData *rmpd = (SSHModePrivateData *)mode_get_private_data(sw);
if (rmpd != NULL) {
for (unsigned int i = 0; i < rmpd->hosts_list_length; i++) {
g_free(rmpd->hosts_list[i].hostname);
}
g_list_free_full ( rmpd->user_known_hosts, g_free );
g_free ( rmpd->hosts_list );
g_free ( rmpd );
mode_set_private_data ( sw, NULL );
g_list_free_full(rmpd->user_known_hosts, g_free);
g_free(rmpd->hosts_list);
g_free(rmpd);
mode_set_private_data(sw, NULL);
}
}
@@ -589,26 +575,25 @@ static void ssh_mode_destroy ( Mode *sw )
*
* @returns the next #ModeMode.
*/
static ModeMode ssh_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line )
{
static ModeMode ssh_mode_result(Mode *sw, int mretv, char **input,
unsigned int selected_line) {
ModeMode retv = MODE_EXIT;
SSHModePrivateData *rmpd = (SSHModePrivateData *) mode_get_private_data ( sw );
if ( ( mretv & MENU_OK ) && rmpd->hosts_list[selected_line].hostname != NULL ) {
exec_ssh ( &( rmpd->hosts_list[selected_line] ) );
}
else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] != '\0' ) {
SshEntry entry = { .hostname = *input, .port = 0 };
exec_ssh ( &entry );
}
else if ( ( mretv & MENU_ENTRY_DELETE ) && rmpd->hosts_list[selected_line].hostname ) {
delete_ssh ( rmpd->hosts_list[selected_line].hostname );
SSHModePrivateData *rmpd = (SSHModePrivateData *)mode_get_private_data(sw);
if ((mretv & MENU_OK) && rmpd->hosts_list[selected_line].hostname != NULL) {
exec_ssh(&(rmpd->hosts_list[selected_line]));
} else if ((mretv & MENU_CUSTOM_INPUT) && *input != NULL &&
*input[0] != '\0') {
SshEntry entry = {.hostname = *input, .port = 0};
exec_ssh(&entry);
} else if ((mretv & MENU_ENTRY_DELETE) &&
rmpd->hosts_list[selected_line].hostname) {
delete_ssh(rmpd->hosts_list[selected_line].hostname);
// Stay
retv = RELOAD_DIALOG;
ssh_mode_destroy ( sw );
ssh_mode_init ( sw );
}
else if ( mretv & MENU_CUSTOM_COMMAND ) {
retv = ( mretv & MENU_LOWER_MASK );
ssh_mode_destroy(sw);
ssh_mode_init(sw);
} else if (mretv & MENU_CUSTOM_COMMAND) {
retv = (mretv & MENU_LOWER_MASK);
}
return retv;
}
@@ -625,10 +610,12 @@ static ModeMode ssh_mode_result ( Mode *sw, int mretv, char **input, unsigned in
*
* @return the string as it should be displayed and the display state.
*/
static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, G_GNUC_UNUSED GList **attr_list, int get_entry )
{
SSHModePrivateData *rmpd = (SSHModePrivateData *) mode_get_private_data ( sw );
return get_entry ? g_strdup ( rmpd->hosts_list[selected_line].hostname ) : NULL;
static char *_get_display_value(const Mode *sw, unsigned int selected_line,
G_GNUC_UNUSED int *state,
G_GNUC_UNUSED GList **attr_list,
int get_entry) {
SSHModePrivateData *rmpd = (SSHModePrivateData *)mode_get_private_data(sw);
return get_entry ? g_strdup(rmpd->hosts_list[selected_line].hostname) : NULL;
}
/**
@@ -640,15 +627,13 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_
*
* @returns TRUE if matches
*/
static int ssh_token_match ( const Mode *sw, rofi_int_matcher **tokens, unsigned int index )
{
SSHModePrivateData *rmpd = (SSHModePrivateData *) mode_get_private_data ( sw );
return helper_token_match ( tokens, rmpd->hosts_list[index].hostname );
static int ssh_token_match(const Mode *sw, rofi_int_matcher **tokens,
unsigned int index) {
SSHModePrivateData *rmpd = (SSHModePrivateData *)mode_get_private_data(sw);
return helper_token_match(tokens, rmpd->hosts_list[index].hostname);
}
#include "mode-private.h"
Mode ssh_mode =
{
.name = "ssh",
Mode ssh_mode = {.name = "ssh",
.cfg_name_key = "display-ssh",
._init = ssh_mode_init,
._get_num_entries = ssh_mode_get_num_entries,
@@ -659,6 +644,5 @@ Mode ssh_mode =
._get_completion = NULL,
._preprocess_input = NULL,
.private_data = NULL,
.free = NULL
};
.free = NULL};
/**@}*/

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -25,171 +25,173 @@
*
*/
#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
{
typedef struct __element {
/** Index in history */
long int index;
/** Entry */
char *name;
}_element;
} _element;
static int __element_sort_func ( const void *ea, const void *eb, void *data __attribute__( ( unused ) ) )
{
_element *a = *(_element * *) ea;
_element *b = *(_element * *) eb;
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 ) {
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 );
g_qsort_with_data(list, length, sizeof(_element *), __element_sort_func,
NULL);
// 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;
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 );
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 )
{
static char **__history_get_element_list_fields(FILE *fd,
unsigned int *length) {
unsigned int real_length = 0;
char **retv = NULL;;
if ( length == NULL ) {
char **retv = NULL;
;
if (length == NULL) {
return NULL;
}
*length = 0;
if ( fd == 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 ) {
while ((l = getline(&buffer, &buffer_length, fd)) > 0) {
// Jump to the first space.
const char *start = strchr ( buffer, ' ' );
const char *start = strchr(buffer, ' ');
// not found, skip.
if ( start == NULL ) {
if (start == NULL) {
continue;
}
start++;
// remove trailing \n
buffer[l - 1] = '\0';
if ( real_length < ( *length + 2 ) ) {
if (real_length < (*length + 2)) {
real_length += 15;
// Resize and check.
retv = g_realloc ( retv, ( real_length ) * sizeof ( char* ) );
retv = g_realloc(retv, (real_length) * sizeof(char *));
}
// Parse the number of times.
retv[( *length )] = g_strndup ( start, l - 1 - ( start - buffer ) );
retv[(*length)] = g_strndup(start, l - 1 - (start - buffer));
// Force trailing '\0'
retv[( *length ) + 1] = NULL;
retv[(*length) + 1] = NULL;
( *length )++;
(*length)++;
}
if ( buffer_length > 0 ) {
g_free ( buffer );
if (buffer_length > 0) {
g_free(buffer);
}
return retv;
}
static _element ** __history_get_element_list ( FILE *fd, unsigned int *length )
{
static _element **__history_get_element_list(FILE *fd, unsigned int *length) {
unsigned int real_length = 0;
_element **retv = NULL;
if ( length == NULL ) {
if (length == NULL) {
return NULL;
}
*length = 0;
if ( fd == 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 ) {
char * start = NULL;
while ((l = getline(&buffer, &buffer_length, fd)) > 0) {
char *start = NULL;
// Skip empty lines.
if ( l <= 1 ) {
if (l <= 1) {
continue;
}
long int index = strtol ( buffer, &start, 10 );
if ( start == buffer || *start == '\0' ) {
long int index = strtol(buffer, &start, 10);
if (start == buffer || *start == '\0') {
continue;
}
start++;
if ( ( l - ( start - buffer ) ) < 2 ) {
if ((l - (start - buffer)) < 2) {
continue;
}
if ( real_length < ( *length + 2 ) ) {
if (real_length < (*length + 2)) {
real_length += 15;
// Resize and check.
retv = g_realloc ( retv, ( real_length ) * sizeof ( _element* ) );
retv = g_realloc(retv, (real_length) * sizeof(_element *));
}
retv[( *length )] = g_malloc ( 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 ) );
retv[(*length)]->index = index;
retv[(*length)]->name = g_strndup(start, l - 1 - (start - buffer));
// Force trailing '\0'
retv[( *length ) + 1] = NULL;
retv[(*length) + 1] = NULL;
( *length )++;
(*length)++;
}
if ( buffer != NULL ) {
free ( buffer );
if (buffer != NULL) {
free(buffer);
buffer = NULL;
}
return retv;
}
void history_set ( const char *filename, const char *entry )
{
if ( config.disable_history ) {
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 (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.
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 ) ) {
if (g_str_has_prefix(entry, checked_prefix)) {
return;
}
}
@@ -199,35 +201,34 @@ void history_set ( const char *filename, const char *entry )
unsigned int length = 0;
_element **list = NULL;
// Open file for reading and writing.
FILE *fd = g_fopen ( filename, "r" );
if ( fd != NULL ) {
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));
}
}
// Look if the entry exists.
for ( unsigned int iter = 0; !found && iter < length; iter++ ) {
if ( strcmp ( list[iter]->name, entry ) == 0 ) {
for (unsigned int iter = 0; !found && iter < length; iter++) {
if (strcmp(list[iter]->name, entry) == 0) {
curr = iter;
found = 1;
}
}
if ( found ) {
if (found) {
// If exists, increment list index number
list[curr]->index++;
}
else{
} else {
// If not exists, add it.
// Increase list by one
list = g_realloc ( list, ( length + 2 ) * sizeof ( _element* ) );
list[length] = g_malloc ( sizeof ( _element ) );
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 );
if (list[length] != NULL) {
list[length]->name = g_strdup(entry);
// set # hits
list[length]->index = 1;
@@ -236,116 +237,112 @@ void history_set ( const char *filename, const char *entry )
}
}
fd = fopen ( filename, "w" );
if ( fd == NULL ) {
g_warning ( "Failed to open file: %s", g_strerror ( errno ) );
}
else {
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 );
__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 ) );
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] );
for (unsigned int iter = 0; iter < length; iter++) {
g_free(list[iter]->name);
g_free(list[iter]);
}
g_free ( list );
g_free(list);
}
void history_remove ( const char *filename, const char *entry )
{
if ( config.disable_history ) {
void history_remove(const char *filename, const char *entry) {
if (config.disable_history) {
return;
}
_element ** list = NULL;
_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 ) );
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 );
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 ) {
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 ) {
if (found) {
// Remove the entry.
g_free ( list[curr]->name );
g_free ( list[curr] );
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" );
fd = g_fopen(filename, "w");
// Clear list.
if ( fd != NULL ) {
if (fd != NULL) {
// Write list.
__history_write_element_list ( fd, list, length );
__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 ) );
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 ) );
} else {
g_warning("Failed to open 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] );
for (unsigned int iter = 0; iter < length; iter++) {
g_free(list[iter]->name);
g_free(list[iter]);
}
if ( list != NULL ) {
g_free ( list );
if (list != NULL) {
g_free(list);
}
}
char ** history_get_list ( const char *filename, unsigned int *length )
{
char **history_get_list(const char *filename, unsigned int *length) {
*length = 0;
if ( config.disable_history ) {
if (config.disable_history) {
return NULL;
}
char **retv = NULL;
// Open file.
FILE *fd = g_fopen ( filename, "r" );
if ( fd == NULL ) {
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 ) );
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 );
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 (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,152 +39,140 @@
* @{
*/
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 );
if (mode->_get_icon != NULL) {
return mode->_get_icon(mode, selected_line, height);
}
else {
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 );
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 );
}
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 ) {
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 ) {
if (menu_retv & MENU_PREVIOUS) {
return PREVIOUS_DIALOG;
}
else if ( menu_retv & MENU_QUICK_SWITCH ) {
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 );
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 );
void mode_free(Mode **mode) {
g_assert(mode != NULL);
g_assert((*mode) != NULL);
if ((*mode)->free != NULL) {
(*mode)->free(*mode);
}
( *mode ) = NULL;
(*mode) = NULL;
}
void *mode_get_private_data ( const Mode *mode )
{
g_assert ( mode != NULL );
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 );
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;
}
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 );
char *mode_preprocess_input(Mode *mode, const char *input) {
if (mode->_preprocess_input) {
return mode->_preprocess_input(mode, input);
}
return g_strdup ( input );
return g_strdup(input);
}
char *mode_get_message ( const Mode *mode )
{
if ( mode->_get_message ) {
return mode->_get_message ( mode );
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

@@ -28,10 +28,10 @@
/** Log domain used by 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 );
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

@@ -28,18 +28,16 @@
/** The log domain of this widget. */
#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
struct _box
{
struct _box {
widget widget;
RofiOrientation type;
int max_size;
@@ -49,282 +47,286 @@ struct _box
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 );
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 ) {
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 ) {
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 ) {
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 );
if (child->expand == TRUE) {
width += widget_get_desired_width(child);
continue;
}
width += widget_get_desired_width ( child );
width += widget_get_desired_width(child);
}
if ( active_widgets > 0 ) {
width += ( active_widgets - 1 ) * spacing;
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 ) {
} 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 = MAX(widget_get_desired_width(child), width);
}
}
width += widget_padding_get_padding_width ( wid );
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 );
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 ) {
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 ) {
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 );
height += widget_get_desired_height(child);
}
if ( active_widgets > 0 ) {
height += ( active_widgets - 1 ) * spacing;
if (active_widgets > 0) {
height += (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 ) {
} 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 = MAX(widget_get_desired_height(child), height);
}
}
height += widget_padding_get_padding_height ( wid );
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 );
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 ) );
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 ) {
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 ) {
if (child->expand == TRUE) {
expanding_widgets++;
continue;
}
if ( child->h > 0 ) {
if (child->h > 0) {
b->max_size += child->h;
}
}
if ( active_widgets > 0 ) {
b->max_size += ( active_widgets - 1 ) * spacing;
if (active_widgets > 0) {
b->max_size += (active_widgets - 1) * spacing;
}
if ( b->max_size > rem_height ) {
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 );
g_debug("Widgets to large (height) for box: %d %d", b->max_size,
b->widget.h);
return;
}
if ( active_widgets > 0 ) {
int top = widget_padding_get_top ( WIDGET ( b ) );
if (active_widgets > 0) {
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 ) {
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 ) {
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 );
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 );
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 );
} 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 );
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 );
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 ) {
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 ) {
if (child->expand == TRUE) {
expanding_widgets++;
continue;
}
// Size used by fixed width widgets.
if ( child->h > 0 ) {
if (child->h > 0) {
b->max_size += child->w;
}
}
b->max_size += MAX ( 0, ( ( active_widgets - 1 ) * spacing ) );
if ( b->max_size > ( rem_width ) ) {
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;
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 ) );
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 ) {
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 ) {
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 ) {
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 ) ) );
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 );
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 );
} else {
widget_move(child, left, widget_padding_get_top(WIDGET(b)));
left += widget_get_width(child);
left += spacing;
}
}
}
b->max_size += widget_padding_get_padding_width ( WIDGET ( b ) );
b->max_size += 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 );
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 );
g_list_free(b->children);
g_free(b);
}
void box_add ( box *box, widget *child, gboolean expand )
{
if ( box == NULL ) {
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 ) {
if (box->type == ROFI_ORIENTATION_VERTICAL) {
int width = box->widget.w;
width = MAX ( width, child->w + widget_padding_get_padding_width ( WIDGET ( box ) ) );
width =
MAX(width, child->w + widget_padding_get_padding_width(WIDGET(box)));
box->widget.w = width;
}
else {
} else {
int height = box->widget.h;
height = MAX ( height, child->h + widget_padding_get_padding_height ( WIDGET ( box ) ) );
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 ) );
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 ) {
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 );
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 ) {
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 ) ) {
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 ) {
widget *target = widget_find_mouse_target(child, type, rx, ry);
if (target != NULL) {
return target;
}
}
@@ -332,19 +334,18 @@ static widget *box_find_mouse_target ( widget *wid, WidgetType type, gint x, gin
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 ) );
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 );
widget_init(WIDGET(b), parent, WIDGET_TYPE_UNKNOWN, name);
b->type = type;
b->widget.draw = box_draw;
b->widget.free = box_free;
@@ -355,25 +356,23 @@ box * box_create ( widget *parent, const char *name, RofiOrientation type )
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 );
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 )
{
static void box_update(widget *wid) {
box *b = (box *)wid;
switch (b->type) {
case ROFI_ORIENTATION_VERTICAL:
vert_calculate_size ( b );
vert_calculate_size(b);
break;
case ROFI_ORIENTATION_HORIZONTAL:
default:
hori_calculate_size ( b );
hori_calculate_size(b);
}
if ( wid->parent ) {
widget_update ( wid->parent );
if (wid->parent) {
widget_update(wid->parent);
}
}

View File

@@ -28,90 +28,81 @@
/** The log domain of this widget. */
#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
{
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;
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 );
if (b->child) {
height += widget_get_desired_height(b->child);
}
height += widget_padding_get_padding_height ( widget );
height += widget_padding_get_padding_height(widget);
return height;
}
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 ) {
void container_add(container *container, widget *child) {
if (container == NULL) {
return;
}
container->child = child;
g_assert ( child->parent == WIDGET ( container ) );
widget_update ( WIDGET ( container ) );
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 ) {
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 );
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 ) ) {
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 );
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 ) );
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 );
widget_init(WIDGET(b), parent, WIDGET_TYPE_UNKNOWN, name);
b->widget.draw = container_draw;
b->widget.free = container_free;
b->widget.resize = container_resize;
@@ -122,17 +113,13 @@ container * container_create ( widget *parent, const char *name )
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

@@ -28,17 +28,15 @@
/** The log domain of this widget. */
#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
{
struct _icon {
widget widget;
// Size of the icon.
@@ -54,134 +52,127 @@ struct _icon
cairo_surface_t *icon;
};
static int icon_get_desired_height ( widget *widget )
{
icon *b = (icon *) widget;
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;
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 );
height += widget_padding_get_padding_height(widget);
return height;
}
static int icon_get_desired_width ( widget *widget )
{
icon *b = (icon *) widget;
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;
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 );
width += widget_padding_get_padding_width(widget);
return width;
}
static void icon_draw ( widget *wid, cairo_t *draw )
{
icon *b = (icon *) wid;
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 && 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 ) {
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 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 ) {
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 );
widget_update(widget);
}
}
void icon_set_surface ( icon *icon, cairo_surface_t *surf )
{
void icon_set_surface(icon *icon, cairo_surface_t *surf) {
icon->icon_fetch_id = 0;
if ( icon->icon ) {
cairo_surface_destroy ( icon->icon );
if (icon->icon) {
cairo_surface_destroy(icon->icon);
icon->icon = NULL;
}
if ( surf ) {
cairo_surface_reference ( surf );
if (surf) {
cairo_surface_reference(surf);
icon->icon = surf;
}
widget_queue_redraw ( WIDGET ( icon ) );
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 );
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 );
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 ) );
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;
}

File diff suppressed because it is too large Load Diff

View File

@@ -25,66 +25,65 @@
*
*/
#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
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 )
{
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 )
{
guint scrollbar_scroll_get_line(const scrollbar *sb, int y) {
y -= sb->widget.border.top.base.distance;
if ( y < 0 ) {
if (y < 0) {
return 0;
}
if ( y > sb->widget.h ) {
if (y > sb->widget.h) {
return sb->length - 1;
}
short r = ( sb->length * sb->widget.h ) / ( (double) ( sb->length + sb->pos_length ) );
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 ) );
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 );
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 )
{
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 );
scrollbar_scroll(sb, y);
return WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_END;
case MOUSE_DCLICK_DOWN:
case MOUSE_DCLICK_UP:
@@ -93,23 +92,23 @@ static WidgetTriggerActionResult scrollbar_trigger_action ( widget *wid, MouseBi
return FALSE;
}
static gboolean scrollbar_motion_notify ( widget *wid, G_GNUC_UNUSED gint x, gint y )
{
scrollbar *sb = (scrollbar *) wid;
scrollbar_scroll ( sb, y );
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 );
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->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;
@@ -124,30 +123,26 @@ scrollbar *scrollbar_create ( widget *parent, const char *name )
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 );
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 r = (sb->length * wh) / ((double)(sb->length + sb->pos_length));
unsigned int handle = wid->h - r;
double sec = ( ( r ) / (double) ( sb->length - 1 ) );
double sec = ((r) / (double)(sb->length - 1));
unsigned int height = handle;
unsigned int y = sb->pos * sec;
// Set max pos.
y = MIN ( y, wh - handle );
y = MIN(y, wh - handle);
// Never go out of bar.
height = MAX ( 2, height );
height = MAX(2, height);
// Cap length;
rofi_theme_get_color ( WIDGET ( sb ), "handle-color", draw );
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

View File

@@ -25,242 +25,263 @@
*
*/
#include "widgets/widget.h"
#include "theme.h"
#include "widgets/widget-internal.h"
#include <glib.h>
#include <math.h>
#include "widgets/widget.h"
#include "widgets/widget-internal.h"
#include "theme.h"
/** Default padding. */
#define WIDGET_DEFAULT_PADDING 0
/** macro for initializing the padding struction. */
#define WIDGET_PADDING_INIT { { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }
#define WIDGET_PADDING_INIT \
{ \
{WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, \
NULL}, \
ROFI_HL_SOLID \
}
void widget_init ( widget *wid, widget *parent, WidgetType type, const char *name )
{
void widget_init(widget *wid, widget *parent, WidgetType type,
const char *name) {
wid->type = type;
wid->parent = parent;
wid->name = g_strdup ( name );
wid->def_padding = (RofiPadding) { WIDGET_PADDING_INIT, WIDGET_PADDING_INIT, WIDGET_PADDING_INIT, WIDGET_PADDING_INIT };
wid->def_border = (RofiPadding) { WIDGET_PADDING_INIT, WIDGET_PADDING_INIT, WIDGET_PADDING_INIT, WIDGET_PADDING_INIT };
wid->def_border_radius = (RofiPadding) { WIDGET_PADDING_INIT, WIDGET_PADDING_INIT, WIDGET_PADDING_INIT, WIDGET_PADDING_INIT };
wid->def_margin = (RofiPadding) { WIDGET_PADDING_INIT, WIDGET_PADDING_INIT, WIDGET_PADDING_INIT, WIDGET_PADDING_INIT };
wid->name = g_strdup(name);
wid->def_padding = (RofiPadding){WIDGET_PADDING_INIT, WIDGET_PADDING_INIT,
WIDGET_PADDING_INIT, WIDGET_PADDING_INIT};
wid->def_border = (RofiPadding){WIDGET_PADDING_INIT, WIDGET_PADDING_INIT,
WIDGET_PADDING_INIT, WIDGET_PADDING_INIT};
wid->def_border_radius =
(RofiPadding){WIDGET_PADDING_INIT, WIDGET_PADDING_INIT,
WIDGET_PADDING_INIT, WIDGET_PADDING_INIT};
wid->def_margin = (RofiPadding){WIDGET_PADDING_INIT, WIDGET_PADDING_INIT,
WIDGET_PADDING_INIT, WIDGET_PADDING_INIT};
wid->padding = rofi_theme_get_padding ( wid, "padding", wid->def_padding );
wid->border = rofi_theme_get_padding ( wid, "border", wid->def_border );
wid->border_radius = rofi_theme_get_padding ( wid, "border-radius", wid->def_border_radius );
wid->margin = rofi_theme_get_padding ( wid, "margin", wid->def_margin );
wid->padding = rofi_theme_get_padding(wid, "padding", wid->def_padding);
wid->border = rofi_theme_get_padding(wid, "border", wid->def_border);
wid->border_radius =
rofi_theme_get_padding(wid, "border-radius", wid->def_border_radius);
wid->margin = rofi_theme_get_padding(wid, "margin", wid->def_margin);
wid->cursor_type = rofi_theme_get_cursor_type ( wid, "cursor", ROFI_CURSOR_DEFAULT );
wid->cursor_type =
rofi_theme_get_cursor_type(wid, "cursor", ROFI_CURSOR_DEFAULT);
// enabled by default
wid->enabled = rofi_theme_get_boolean ( wid, "enabled", TRUE );
wid->enabled = rofi_theme_get_boolean(wid, "enabled", TRUE);
}
void widget_set_state ( widget *widget, const char *state )
{
if ( widget == NULL ) {
void widget_set_state(widget *widget, const char *state) {
if (widget == NULL) {
return;
}
if ( g_strcmp0 ( widget->state, state ) ) {
if (g_strcmp0(widget->state, state)) {
widget->state = state;
// Update border.
widget->border = rofi_theme_get_padding ( widget, "border", widget->def_border );
widget->border_radius = rofi_theme_get_padding ( widget, "border-radius", widget->def_border_radius );
if ( widget->set_state != NULL ) {
widget->set_state ( widget, state );
widget->border =
rofi_theme_get_padding(widget, "border", widget->def_border);
widget->border_radius = rofi_theme_get_padding(widget, "border-radius",
widget->def_border_radius);
if (widget->set_state != NULL) {
widget->set_state(widget, state);
}
widget_queue_redraw ( widget );
widget_queue_redraw(widget);
}
}
int widget_intersect ( const widget *widget, int x, int y )
{
if ( widget == NULL ) {
int widget_intersect(const widget *widget, int x, int y) {
if (widget == NULL) {
return FALSE;
}
if ( x >= ( widget->x ) && x < ( widget->x + widget->w ) &&
y >= ( widget->y ) && y < ( widget->y + widget->h ) ) {
if (x >= (widget->x) && x < (widget->x + widget->w) && y >= (widget->y) &&
y < (widget->y + widget->h)) {
return TRUE;
}
return FALSE;
}
void widget_resize ( widget *widget, short w, short h )
{
if ( widget == NULL ) {
void widget_resize(widget *widget, short w, short h) {
if (widget == NULL) {
return;
}
if ( widget->resize != NULL ) {
if ( widget->w != w || widget->h != h ) {
widget->resize ( widget, w, h );
if (widget->resize != NULL) {
if (widget->w != w || widget->h != h) {
widget->resize(widget, w, h);
}
}
else {
} else {
widget->w = w;
widget->h = h;
}
// On a resize we always want to update.
widget_queue_redraw ( widget );
widget_queue_redraw(widget);
}
void widget_move ( widget *widget, short x, short y )
{
if ( widget == NULL ) {
void widget_move(widget *widget, short x, short y) {
if (widget == NULL) {
return;
}
widget->x = x;
widget->y = y;
}
void widget_set_type ( widget *widget, WidgetType type )
{
if ( widget == NULL ) {
void widget_set_type(widget *widget, WidgetType type) {
if (widget == NULL) {
return;
}
widget->type = type;
}
WidgetType widget_type ( widget *widget )
{
if ( widget == NULL ) {
WidgetType widget_type(widget *widget) {
if (widget == NULL) {
return WIDGET_TYPE_UNKNOWN;
}
return widget->type;
}
gboolean widget_enabled ( widget *widget )
{
if ( widget == NULL ) {
gboolean widget_enabled(widget *widget) {
if (widget == NULL) {
return FALSE;
}
return widget->enabled;
}
void widget_set_enabled ( widget *widget, gboolean enabled )
{
if ( widget == NULL ) {
void widget_set_enabled(widget *widget, gboolean enabled) {
if (widget == NULL) {
return;
}
if ( widget->enabled != enabled ) {
if (widget->enabled != enabled) {
widget->enabled = enabled;
widget_update ( widget );
widget_update ( widget->parent );
widget_queue_redraw ( widget );
widget_update(widget);
widget_update(widget->parent);
widget_queue_redraw(widget);
}
}
void widget_draw ( widget *widget, cairo_t *d )
{
if ( widget == NULL ) {
void widget_draw(widget *widget, cairo_t *d) {
if (widget == NULL) {
return;
}
// Check if enabled and if draw is implemented.
if ( widget->enabled && widget->draw ) {
if (widget->enabled && widget->draw) {
// Don't draw if there is no space.
if ( widget->h < 1 || widget->w < 1 ) {
if (widget->h < 1 || widget->w < 1) {
widget->need_redraw = FALSE;
return;
}
// Store current state.
cairo_save ( d );
const int margin_left = distance_get_pixel ( widget->margin.left, ROFI_ORIENTATION_HORIZONTAL );
const int margin_top = distance_get_pixel ( widget->margin.top, ROFI_ORIENTATION_VERTICAL );
const int margin_right = distance_get_pixel ( widget->margin.right, ROFI_ORIENTATION_HORIZONTAL );
const int margin_bottom = distance_get_pixel ( widget->margin.bottom, ROFI_ORIENTATION_VERTICAL );
const int left = distance_get_pixel ( widget->border.left, ROFI_ORIENTATION_HORIZONTAL );
const int right = distance_get_pixel ( widget->border.right, ROFI_ORIENTATION_HORIZONTAL );
const int top = distance_get_pixel ( widget->border.top, ROFI_ORIENTATION_VERTICAL );
const int bottom = distance_get_pixel ( widget->border.bottom, ROFI_ORIENTATION_VERTICAL );
int radius_bl = distance_get_pixel ( widget->border_radius.left, ROFI_ORIENTATION_HORIZONTAL );
int radius_tr = distance_get_pixel ( widget->border_radius.right, ROFI_ORIENTATION_HORIZONTAL );
int radius_tl = distance_get_pixel ( widget->border_radius.top, ROFI_ORIENTATION_VERTICAL );
int radius_br = distance_get_pixel ( widget->border_radius.bottom, ROFI_ORIENTATION_VERTICAL );
cairo_save(d);
const int margin_left =
distance_get_pixel(widget->margin.left, ROFI_ORIENTATION_HORIZONTAL);
const int margin_top =
distance_get_pixel(widget->margin.top, ROFI_ORIENTATION_VERTICAL);
const int margin_right =
distance_get_pixel(widget->margin.right, ROFI_ORIENTATION_HORIZONTAL);
const int margin_bottom =
distance_get_pixel(widget->margin.bottom, ROFI_ORIENTATION_VERTICAL);
const int left =
distance_get_pixel(widget->border.left, ROFI_ORIENTATION_HORIZONTAL);
const int right =
distance_get_pixel(widget->border.right, ROFI_ORIENTATION_HORIZONTAL);
const int top =
distance_get_pixel(widget->border.top, ROFI_ORIENTATION_VERTICAL);
const int bottom =
distance_get_pixel(widget->border.bottom, ROFI_ORIENTATION_VERTICAL);
int radius_bl = distance_get_pixel(widget->border_radius.left,
ROFI_ORIENTATION_HORIZONTAL);
int radius_tr = distance_get_pixel(widget->border_radius.right,
ROFI_ORIENTATION_HORIZONTAL);
int radius_tl = distance_get_pixel(widget->border_radius.top,
ROFI_ORIENTATION_VERTICAL);
int radius_br = distance_get_pixel(widget->border_radius.bottom,
ROFI_ORIENTATION_VERTICAL);
double vspace = widget->h - margin_top - margin_bottom - top / 2.0 - bottom / 2.0;
double hspace = widget->w - margin_left - margin_right - left / 2.0 - right / 2.0;
if ( ( radius_bl + radius_tl ) > ( vspace ) ) {
int j = ( ( vspace ) / 2.0 );
radius_bl = MIN ( radius_bl, j );
radius_tl = MIN ( radius_tl, j );
double vspace =
widget->h - margin_top - margin_bottom - top / 2.0 - bottom / 2.0;
double hspace =
widget->w - margin_left - margin_right - left / 2.0 - right / 2.0;
if ((radius_bl + radius_tl) > (vspace)) {
int j = ((vspace) / 2.0);
radius_bl = MIN(radius_bl, j);
radius_tl = MIN(radius_tl, j);
}
if ( ( radius_br + radius_tr ) > ( vspace ) ) {
int j = ( ( vspace ) / 2.0 );
radius_br = MIN ( radius_br, j );
radius_tr = MIN ( radius_tr, j );
if ((radius_br + radius_tr) > (vspace)) {
int j = ((vspace) / 2.0);
radius_br = MIN(radius_br, j);
radius_tr = MIN(radius_tr, j);
}
if ( ( radius_tl + radius_tr ) > ( hspace ) ) {
int j = ( ( hspace ) / 2.0 );
radius_tr = MIN ( radius_tr, j );
radius_tl = MIN ( radius_tl, j );
if ((radius_tl + radius_tr) > (hspace)) {
int j = ((hspace) / 2.0);
radius_tr = MIN(radius_tr, j);
radius_tl = MIN(radius_tl, j);
}
if ( ( radius_bl + radius_br ) > ( hspace ) ) {
int j = ( ( hspace ) / 2.0 );
radius_br = MIN ( radius_br, j );
radius_bl = MIN ( radius_bl, j );
if ((radius_bl + radius_br) > (hspace)) {
int j = ((hspace) / 2.0);
radius_br = MIN(radius_br, j);
radius_bl = MIN(radius_bl, j);
}
// Background painting.
// Set new x/y position.
cairo_translate ( d, widget->x, widget->y );
cairo_set_line_width ( d, 0 );
cairo_translate(d, widget->x, widget->y);
cairo_set_line_width(d, 0);
// Outer outline outlines
double x1, y1, x2, y2;
x1 = margin_left + left / 2.0,
y1 = margin_top + top / 2.0,
x1 = margin_left + left / 2.0, y1 = margin_top + top / 2.0,
x2 = widget->w - margin_right - right / 2.0,
y2 = widget->h - margin_bottom - bottom / 2.0;
if ( radius_tl > 0 ) {
cairo_move_to ( d, x1, y1 + radius_tl );
cairo_arc ( d, x1 + radius_tl, y1 + radius_tl, radius_tl, -1.0 * G_PI, -G_PI_2 );
if (radius_tl > 0) {
cairo_move_to(d, x1, y1 + radius_tl);
cairo_arc(d, x1 + radius_tl, y1 + radius_tl, radius_tl, -1.0 * G_PI,
-G_PI_2);
} else {
cairo_move_to ( d, x1, y1 );
cairo_move_to(d, x1, y1);
}
if ( radius_tr > 0 ) {
cairo_line_to ( d, x2 - radius_tr, y1 );
cairo_arc ( d, x2 - radius_tr, y1 + radius_tr, radius_tr, -G_PI_2, 0 * G_PI );
if (radius_tr > 0) {
cairo_line_to(d, x2 - radius_tr, y1);
cairo_arc(d, x2 - radius_tr, y1 + radius_tr, radius_tr, -G_PI_2,
0 * G_PI);
} else {
cairo_line_to ( d, x2, y1 );
cairo_line_to(d, x2, y1);
}
if ( radius_br > 0 ) {
cairo_line_to ( d, x2, y2 - radius_br );
cairo_arc ( d, x2 - radius_br, y2 - radius_br, radius_br, 0.0 * G_PI, G_PI_2 );
if (radius_br > 0) {
cairo_line_to(d, x2, y2 - radius_br);
cairo_arc(d, x2 - radius_br, y2 - radius_br, radius_br, 0.0 * G_PI,
G_PI_2);
} else {
cairo_line_to ( d, x2, y2 );
cairo_line_to(d, x2, y2);
}
if ( radius_bl > 0 ) {
cairo_line_to ( d, x1 + radius_bl, y2 );
cairo_arc ( d, x1 + radius_bl, y2 - radius_bl, radius_bl, G_PI_2, 1.0 * G_PI );
if (radius_bl > 0) {
cairo_line_to(d, x1 + radius_bl, y2);
cairo_arc(d, x1 + radius_bl, y2 - radius_bl, radius_bl, G_PI_2,
1.0 * G_PI);
} else {
cairo_line_to ( d, x1, y2 );
cairo_line_to(d, x1, y2);
}
cairo_close_path ( d );
cairo_close_path(d);
cairo_set_source_rgba ( d, 1.0, 1.0, 1.0, 1.0 );
rofi_theme_get_color ( widget, "background-color", d );
cairo_fill_preserve ( d );
if ( rofi_theme_get_image ( widget, "background-image", d ) ) {
cairo_fill_preserve ( d );
cairo_set_source_rgba(d, 1.0, 1.0, 1.0, 1.0);
rofi_theme_get_color(widget, "background-color", d);
cairo_fill_preserve(d);
if (rofi_theme_get_image(widget, "background-image", d)) {
cairo_fill_preserve(d);
}
cairo_clip ( d );
cairo_clip(d);
widget->draw ( widget, d );
widget->draw(widget, d);
widget->need_redraw = FALSE;
cairo_restore ( d );
cairo_restore(d);
if ( left != 0 || top != 0 || right != 0 || bottom != 0 ) {
cairo_save ( d );
cairo_translate ( d, widget->x, widget->y );
cairo_new_path ( d );
rofi_theme_get_color ( widget, "border-color", d );
if (left != 0 || top != 0 || right != 0 || bottom != 0) {
cairo_save(d);
cairo_translate(d, widget->x, widget->y);
cairo_new_path(d);
rofi_theme_get_color(widget, "border-color", d);
// Calculate the different offsets for the corners.
double minof_tr = MIN ( right / 2.0, top / 2.0 );
double minof_tl = MIN ( left / 2.0, top / 2.0 );
double minof_br = MIN ( right / 2.0, bottom / 2.0 );
double minof_bl = MIN ( left / 2.0, bottom / 2.0 );
double minof_tr = MIN(right / 2.0, top / 2.0);
double minof_tl = MIN(left / 2.0, top / 2.0);
double minof_br = MIN(right / 2.0, bottom / 2.0);
double minof_bl = MIN(left / 2.0, bottom / 2.0);
// Inner radius
double radius_inner_tl = radius_tl - minof_tl;
double radius_inner_tr = radius_tr - minof_tr;
@@ -280,376 +301,387 @@ void widget_draw ( widget *widget, cairo_t *d )
// bbl bbr
// | |
//
// The left and right part ($) start at thinkness top bottom when no radius
double offset_ltl = ( radius_inner_tl > 0 ) ? ( left ) + radius_inner_tl : left;
double offset_rtr = ( radius_inner_tr > 0 ) ? ( right ) + radius_inner_tr : right;
double offset_lbl = ( radius_inner_bl > 0 ) ? ( left ) + radius_inner_bl : left;
double offset_rbr = ( radius_inner_br > 0 ) ? ( right ) + radius_inner_br : right;
// The left and right part ($) start at thinkness top bottom when no
// radius
double offset_ltl =
(radius_inner_tl > 0) ? (left) + radius_inner_tl : left;
double offset_rtr =
(radius_inner_tr > 0) ? (right) + radius_inner_tr : right;
double offset_lbl =
(radius_inner_bl > 0) ? (left) + radius_inner_bl : left;
double offset_rbr =
(radius_inner_br > 0) ? (right) + radius_inner_br : right;
// The top and bottom part (#) go into the corner when no radius
double offset_ttl = ( radius_inner_tl > 0 ) ? ( top ) + radius_inner_tl : ( radius_tl > 0 ) ? top : 0;
double offset_ttr = ( radius_inner_tr > 0 ) ? ( top ) + radius_inner_tr : ( radius_tr > 0 ) ? top : 0;
double offset_bbl = ( radius_inner_bl > 0 ) ? ( bottom ) + radius_inner_bl : ( radius_bl > 0 ) ? bottom : 0;
double offset_bbr = ( radius_inner_br > 0 ) ? ( bottom ) + radius_inner_br : ( radius_br > 0 ) ? bottom : 0;
double offset_ttl = (radius_inner_tl > 0) ? (top) + radius_inner_tl
: (radius_tl > 0) ? top
: 0;
double offset_ttr = (radius_inner_tr > 0) ? (top) + radius_inner_tr
: (radius_tr > 0) ? top
: 0;
double offset_bbl = (radius_inner_bl > 0) ? (bottom) + radius_inner_bl
: (radius_bl > 0) ? bottom
: 0;
double offset_bbr = (radius_inner_br > 0) ? (bottom) + radius_inner_br
: (radius_br > 0) ? bottom
: 0;
if ( left > 0 ) {
cairo_set_line_width ( d, left );
distance_get_linestyle ( widget->border.left, d );
cairo_move_to ( d, x1, margin_top + offset_ttl );
cairo_line_to ( d, x1, widget->h - margin_bottom - offset_bbl );
cairo_stroke ( d );
if (left > 0) {
cairo_set_line_width(d, left);
distance_get_linestyle(widget->border.left, d);
cairo_move_to(d, x1, margin_top + offset_ttl);
cairo_line_to(d, x1, widget->h - margin_bottom - offset_bbl);
cairo_stroke(d);
}
if ( right > 0 ) {
cairo_set_line_width ( d, right );
distance_get_linestyle ( widget->border.right, d );
cairo_move_to ( d, x2, margin_top + offset_ttr );
cairo_line_to ( d, x2, widget->h - margin_bottom - offset_bbr );
cairo_stroke ( d );
if (right > 0) {
cairo_set_line_width(d, right);
distance_get_linestyle(widget->border.right, d);
cairo_move_to(d, x2, margin_top + offset_ttr);
cairo_line_to(d, x2, widget->h - margin_bottom - offset_bbr);
cairo_stroke(d);
}
if ( top > 0 ) {
cairo_set_line_width ( d, top );
distance_get_linestyle ( widget->border.top, d );
cairo_move_to ( d, margin_left + offset_ltl, y1 );
cairo_line_to ( d, widget->w - margin_right - offset_rtr, y1 );
cairo_stroke ( d );
if (top > 0) {
cairo_set_line_width(d, top);
distance_get_linestyle(widget->border.top, d);
cairo_move_to(d, margin_left + offset_ltl, y1);
cairo_line_to(d, widget->w - margin_right - offset_rtr, y1);
cairo_stroke(d);
}
if ( bottom > 0 ) {
cairo_set_line_width ( d, bottom );
distance_get_linestyle ( widget->border.bottom, d );
cairo_move_to ( d, margin_left + offset_lbl, y2 );
cairo_line_to ( d, widget->w - margin_right - offset_rbr, y2 );
cairo_stroke ( d );
if (bottom > 0) {
cairo_set_line_width(d, bottom);
distance_get_linestyle(widget->border.bottom, d);
cairo_move_to(d, margin_left + offset_lbl, y2);
cairo_line_to(d, widget->w - margin_right - offset_rbr, y2);
cairo_stroke(d);
}
if ( radius_tl > 0 ) {
distance_get_linestyle ( widget->border.left, d );
cairo_set_line_width ( d, 0 );
if (radius_tl > 0) {
distance_get_linestyle(widget->border.left, d);
cairo_set_line_width(d, 0);
double radius_outer = radius_tl + minof_tl;
cairo_arc ( d, margin_left + radius_outer, margin_top + radius_outer, radius_outer, -G_PI, -G_PI_2 );
cairo_line_to ( d, margin_left + offset_ltl, margin_top );
cairo_line_to ( d, margin_left + offset_ltl, margin_top + top );
if ( radius_inner_tl > 0 ) {
cairo_arc_negative ( d,
margin_left + left + radius_inner_tl,
cairo_arc(d, margin_left + radius_outer, margin_top + radius_outer,
radius_outer, -G_PI, -G_PI_2);
cairo_line_to(d, margin_left + offset_ltl, margin_top);
cairo_line_to(d, margin_left + offset_ltl, margin_top + top);
if (radius_inner_tl > 0) {
cairo_arc_negative(d, margin_left + left + radius_inner_tl,
margin_top + top + radius_inner_tl,
radius_inner_tl, -G_PI_2, G_PI );
cairo_line_to ( d, margin_left + left, margin_top + offset_ttl );
radius_inner_tl, -G_PI_2, G_PI);
cairo_line_to(d, margin_left + left, margin_top + offset_ttl);
}
cairo_line_to ( d, margin_left, margin_top + offset_ttl );
cairo_close_path ( d );
cairo_fill ( d );
cairo_line_to(d, margin_left, margin_top + offset_ttl);
cairo_close_path(d);
cairo_fill(d);
}
if ( radius_tr > 0 ) {
distance_get_linestyle ( widget->border.right, d );
cairo_set_line_width ( d, 0 );
if (radius_tr > 0) {
distance_get_linestyle(widget->border.right, d);
cairo_set_line_width(d, 0);
double radius_outer = radius_tr + minof_tr;
cairo_arc ( d, widget->w - margin_right - radius_outer, margin_top + radius_outer, radius_outer, -G_PI_2, 0 );
cairo_line_to ( d, widget->w - margin_right, margin_top + offset_ttr );
cairo_line_to ( d, widget->w - margin_right - right, margin_top + offset_ttr );
if ( radius_inner_tr > 0 ) {
cairo_arc_negative ( d, widget->w - margin_right - right - radius_inner_tr,
margin_top + top + radius_inner_tr,
radius_inner_tr, 0, -G_PI_2 );
cairo_line_to ( d, widget->w - margin_right - offset_rtr, margin_top + top );
cairo_arc(d, widget->w - margin_right - radius_outer,
margin_top + radius_outer, radius_outer, -G_PI_2, 0);
cairo_line_to(d, widget->w - margin_right, margin_top + offset_ttr);
cairo_line_to(d, widget->w - margin_right - right,
margin_top + offset_ttr);
if (radius_inner_tr > 0) {
cairo_arc_negative(
d, widget->w - margin_right - right - radius_inner_tr,
margin_top + top + radius_inner_tr, radius_inner_tr, 0, -G_PI_2);
cairo_line_to(d, widget->w - margin_right - offset_rtr,
margin_top + top);
}
cairo_line_to ( d, widget->w - margin_right - offset_rtr, margin_top );
cairo_close_path ( d );
cairo_fill ( d );
cairo_line_to(d, widget->w - margin_right - offset_rtr, margin_top);
cairo_close_path(d);
cairo_fill(d);
}
if ( radius_br > 0 ) {
distance_get_linestyle ( widget->border.right, d );
cairo_set_line_width ( d, 1 );
if (radius_br > 0) {
distance_get_linestyle(widget->border.right, d);
cairo_set_line_width(d, 1);
double radius_outer = radius_br + minof_br;
cairo_arc ( d, widget->w - margin_right - radius_outer, widget->h - margin_bottom - radius_outer, radius_outer, 0.0, G_PI_2 );
cairo_line_to ( d, widget->w - margin_right - offset_rbr, widget->h - margin_bottom );
cairo_line_to ( d, widget->w - margin_right - offset_rbr, widget->h - margin_bottom - bottom );
if ( radius_inner_br > 0 ) {
cairo_arc_negative ( d, widget->w - margin_right - right - radius_inner_br,
cairo_arc(d, widget->w - margin_right - radius_outer,
widget->h - margin_bottom - radius_outer, radius_outer, 0.0,
G_PI_2);
cairo_line_to(d, widget->w - margin_right - offset_rbr,
widget->h - margin_bottom);
cairo_line_to(d, widget->w - margin_right - offset_rbr,
widget->h - margin_bottom - bottom);
if (radius_inner_br > 0) {
cairo_arc_negative(
d, widget->w - margin_right - right - radius_inner_br,
widget->h - margin_bottom - bottom - radius_inner_br,
radius_inner_br, G_PI_2, 0.0 );
cairo_line_to ( d, widget->w - margin_right - right, widget->h - margin_bottom - offset_bbr );
radius_inner_br, G_PI_2, 0.0);
cairo_line_to(d, widget->w - margin_right - right,
widget->h - margin_bottom - offset_bbr);
}
cairo_line_to ( d, widget->w - margin_right, widget->h - margin_bottom - offset_bbr );
cairo_close_path ( d );
cairo_fill ( d );
cairo_line_to(d, widget->w - margin_right,
widget->h - margin_bottom - offset_bbr);
cairo_close_path(d);
cairo_fill(d);
}
if ( radius_bl > 0 ) {
distance_get_linestyle ( widget->border.left, d );
cairo_set_line_width ( d, 1.0 );
if (radius_bl > 0) {
distance_get_linestyle(widget->border.left, d);
cairo_set_line_width(d, 1.0);
double radius_outer = radius_bl + minof_bl;
cairo_arc ( d, margin_left + radius_outer, widget->h - margin_bottom - radius_outer, radius_outer, G_PI_2, G_PI );
cairo_line_to ( d, margin_left, widget->h - margin_bottom - offset_bbl );
cairo_line_to ( d, margin_left + left, widget->h - margin_bottom - offset_bbl );
if ( radius_inner_bl > 0 ) {
cairo_arc_negative ( d, margin_left + left + radius_inner_bl,
widget->h - margin_bottom - bottom - radius_inner_bl,
radius_inner_bl, G_PI, G_PI_2 );
cairo_line_to ( d, margin_left + offset_lbl, widget->h - margin_bottom - bottom );
cairo_arc(d, margin_left + radius_outer,
widget->h - margin_bottom - radius_outer, radius_outer,
G_PI_2, G_PI);
cairo_line_to(d, margin_left, widget->h - margin_bottom - offset_bbl);
cairo_line_to(d, margin_left + left,
widget->h - margin_bottom - offset_bbl);
if (radius_inner_bl > 0) {
cairo_arc_negative(d, margin_left + left + radius_inner_bl,
widget->h - margin_bottom - bottom -
radius_inner_bl,
radius_inner_bl, G_PI, G_PI_2);
cairo_line_to(d, margin_left + offset_lbl,
widget->h - margin_bottom - bottom);
}
cairo_line_to ( d, margin_left + offset_lbl, widget->h - margin_bottom );
cairo_close_path ( d );
cairo_line_to(d, margin_left + offset_lbl, widget->h - margin_bottom);
cairo_close_path(d);
cairo_fill ( d );
cairo_fill(d);
}
cairo_restore ( d );
cairo_restore(d);
}
}
}
void widget_free ( widget *wid )
{
if ( wid == NULL ) {
void widget_free(widget *wid) {
if (wid == NULL) {
return;
}
if ( wid->name != NULL ) {
g_free ( wid->name );
if (wid->name != NULL) {
g_free(wid->name);
}
if ( wid->free != NULL ) {
wid->free ( wid );
if (wid->free != NULL) {
wid->free(wid);
}
}
int widget_get_height ( widget *widget )
{
if ( widget == NULL ) {
int widget_get_height(widget *widget) {
if (widget == NULL) {
return 0;
}
if ( widget->get_height == NULL ) {
if (widget->get_height == NULL) {
return widget->h;
}
return widget->get_height ( widget );
return widget->get_height(widget);
}
int widget_get_width ( widget *widget )
{
if ( widget == NULL ) {
int widget_get_width(widget *widget) {
if (widget == NULL) {
return 0;
}
if ( widget->get_width == NULL ) {
if (widget->get_width == NULL) {
return widget->w;
}
return widget->get_width ( widget );
return widget->get_width(widget);
}
int widget_get_x_pos ( widget *widget )
{
if ( widget == NULL ) {
int widget_get_x_pos(widget *widget) {
if (widget == NULL) {
return 0;
}
return widget->x;
}
int widget_get_y_pos ( widget *widget )
{
if ( widget == NULL ) {
int widget_get_y_pos(widget *widget) {
if (widget == NULL) {
return 0;
}
return widget->y;
}
void widget_xy_to_relative ( widget *widget, gint *x, gint *y )
{
void widget_xy_to_relative(widget *widget, gint *x, gint *y) {
*x -= widget->x;
*y -= widget->y;
if ( widget->parent == NULL ) {
if (widget->parent == NULL) {
return;
}
widget_xy_to_relative ( widget->parent, x, y );
widget_xy_to_relative(widget->parent, x, y);
}
void widget_update ( widget *widget )
{
if ( widget == NULL ) {
void widget_update(widget *widget) {
if (widget == NULL) {
return;
}
// When (desired )size of widget changes.
if ( widget->update != NULL ) {
widget->update ( widget );
if (widget->update != NULL) {
widget->update(widget);
}
}
void widget_queue_redraw ( widget *wid )
{
if ( wid == NULL ) {
void widget_queue_redraw(widget *wid) {
if (wid == NULL) {
return;
}
widget *iter = wid;
// Find toplevel widget.
while ( iter->parent != NULL ) {
while (iter->parent != NULL) {
iter->need_redraw = TRUE;
iter = iter->parent;
}
iter->need_redraw = TRUE;
}
gboolean widget_need_redraw ( widget *wid )
{
if ( wid == NULL ) {
gboolean widget_need_redraw(widget *wid) {
if (wid == NULL) {
return FALSE;
}
if ( !wid->enabled ) {
if (!wid->enabled) {
return FALSE;
}
return wid->need_redraw;
}
widget *widget_find_mouse_target ( widget *wid, WidgetType type, gint x, gint y )
{
if ( wid == NULL ) {
widget *widget_find_mouse_target(widget *wid, WidgetType type, gint x, gint y) {
if (wid == NULL) {
return NULL;
}
if ( wid->find_mouse_target != NULL ) {
widget *target = wid->find_mouse_target ( wid, type, x, y );
if ( target != NULL ) {
if (wid->find_mouse_target != NULL) {
widget *target = wid->find_mouse_target(wid, type, x, y);
if (target != NULL) {
return target;
}
}
if ( wid->type == type || type == WIDGET_TYPE_UNKNOWN ) {
if (wid->type == type || type == WIDGET_TYPE_UNKNOWN) {
return wid;
}
return NULL;
}
WidgetTriggerActionResult widget_trigger_action ( widget *wid, guint action, gint x, gint y )
{
if ( wid == NULL ) {
WidgetTriggerActionResult widget_trigger_action(widget *wid, guint action,
gint x, gint y) {
if (wid == NULL) {
return FALSE;
}
if ( wid->trigger_action == NULL ) {
if (wid->trigger_action == NULL) {
return FALSE;
}
return wid->trigger_action ( wid, action, x, y, wid->trigger_action_cb_data );
return wid->trigger_action(wid, action, x, y, wid->trigger_action_cb_data);
}
void widget_set_trigger_action_handler ( widget *wid, widget_trigger_action_cb cb, void * cb_data )
{
if ( wid == NULL ) {
void widget_set_trigger_action_handler(widget *wid, widget_trigger_action_cb cb,
void *cb_data) {
if (wid == NULL) {
return;
}
wid->trigger_action = cb;
wid->trigger_action_cb_data = cb_data;
}
gboolean widget_motion_notify ( widget *wid, gint x, gint y )
{
if ( wid == NULL ) {
gboolean widget_motion_notify(widget *wid, gint x, gint y) {
if (wid == NULL) {
return FALSE;
}
if ( wid->motion_notify == NULL ) {
if (wid->motion_notify == NULL) {
return FALSE;
}
return wid->motion_notify ( wid, x, y );
return wid->motion_notify(wid, x, y);
}
int widget_padding_get_left ( const widget *wid )
{
if ( wid == NULL ) {
int widget_padding_get_left(const widget *wid) {
if (wid == NULL) {
return 0;
}
int distance = distance_get_pixel ( wid->padding.left, ROFI_ORIENTATION_HORIZONTAL );
distance += distance_get_pixel ( wid->border.left, ROFI_ORIENTATION_HORIZONTAL );
distance += distance_get_pixel ( wid->margin.left, ROFI_ORIENTATION_HORIZONTAL );
int distance =
distance_get_pixel(wid->padding.left, ROFI_ORIENTATION_HORIZONTAL);
distance += distance_get_pixel(wid->border.left, ROFI_ORIENTATION_HORIZONTAL);
distance += distance_get_pixel(wid->margin.left, ROFI_ORIENTATION_HORIZONTAL);
return distance;
}
int widget_padding_get_right ( const widget *wid )
{
if ( wid == NULL ) {
int widget_padding_get_right(const widget *wid) {
if (wid == NULL) {
return 0;
}
int distance = distance_get_pixel ( wid->padding.right, ROFI_ORIENTATION_HORIZONTAL );
distance += distance_get_pixel ( wid->border.right, ROFI_ORIENTATION_HORIZONTAL );
distance += distance_get_pixel ( wid->margin.right, ROFI_ORIENTATION_HORIZONTAL );
int distance =
distance_get_pixel(wid->padding.right, ROFI_ORIENTATION_HORIZONTAL);
distance +=
distance_get_pixel(wid->border.right, ROFI_ORIENTATION_HORIZONTAL);
distance +=
distance_get_pixel(wid->margin.right, ROFI_ORIENTATION_HORIZONTAL);
return distance;
}
int widget_padding_get_top ( const widget *wid )
{
if ( wid == NULL ) {
int widget_padding_get_top(const widget *wid) {
if (wid == NULL) {
return 0;
}
int distance = distance_get_pixel ( wid->padding.top, ROFI_ORIENTATION_VERTICAL );
distance += distance_get_pixel ( wid->border.top, ROFI_ORIENTATION_VERTICAL );
distance += distance_get_pixel ( wid->margin.top, ROFI_ORIENTATION_VERTICAL );
int distance =
distance_get_pixel(wid->padding.top, ROFI_ORIENTATION_VERTICAL);
distance += distance_get_pixel(wid->border.top, ROFI_ORIENTATION_VERTICAL);
distance += distance_get_pixel(wid->margin.top, ROFI_ORIENTATION_VERTICAL);
return distance;
}
int widget_padding_get_bottom ( const widget *wid )
{
if ( wid == NULL ) {
int widget_padding_get_bottom(const widget *wid) {
if (wid == NULL) {
return 0;
}
int distance = distance_get_pixel ( wid->padding.bottom, ROFI_ORIENTATION_VERTICAL );
distance += distance_get_pixel ( wid->border.bottom, ROFI_ORIENTATION_VERTICAL );
distance += distance_get_pixel ( wid->margin.bottom, ROFI_ORIENTATION_VERTICAL );
int distance =
distance_get_pixel(wid->padding.bottom, ROFI_ORIENTATION_VERTICAL);
distance += distance_get_pixel(wid->border.bottom, ROFI_ORIENTATION_VERTICAL);
distance += distance_get_pixel(wid->margin.bottom, ROFI_ORIENTATION_VERTICAL);
return distance;
}
int widget_padding_get_remaining_width ( const widget *wid )
{
int widget_padding_get_remaining_width(const widget *wid) {
int width = wid->w;
width -= widget_padding_get_left ( wid );
width -= widget_padding_get_right ( wid );
width -= widget_padding_get_left(wid);
width -= widget_padding_get_right(wid);
return width;
}
int widget_padding_get_remaining_height ( const widget *wid )
{
int widget_padding_get_remaining_height(const widget *wid) {
int height = wid->h;
height -= widget_padding_get_top ( wid );
height -= widget_padding_get_bottom ( wid );
height -= widget_padding_get_top(wid);
height -= widget_padding_get_bottom(wid);
return height;
}
int widget_padding_get_padding_height ( const widget *wid )
{
int widget_padding_get_padding_height(const widget *wid) {
int height = 0;
height += widget_padding_get_top ( wid );
height += widget_padding_get_bottom ( wid );
height += widget_padding_get_top(wid);
height += widget_padding_get_bottom(wid);
return height;
}
int widget_padding_get_padding_width ( const widget *wid )
{
int widget_padding_get_padding_width(const widget *wid) {
int width = 0;
width += widget_padding_get_left ( wid );
width += widget_padding_get_right ( wid );
width += widget_padding_get_left(wid);
width += widget_padding_get_right(wid);
return width;
}
int widget_get_desired_height ( widget *wid )
{
if ( wid == NULL ) {
int widget_get_desired_height(widget *wid) {
if (wid == NULL) {
return 0;
}
if ( wid->get_desired_height == NULL ) {
if (wid->get_desired_height == NULL) {
return wid->h;
}
return wid->get_desired_height ( wid );
return wid->get_desired_height(wid);
}
int widget_get_desired_width ( widget *wid )
{
if ( wid == NULL ) {
int widget_get_desired_width(widget *wid) {
if (wid == NULL) {
return 0;
}
if ( wid->get_desired_width == NULL ) {
if (wid->get_desired_width == NULL) {
return wid->w;
}
return wid->get_desired_width ( wid );
return wid->get_desired_width(wid);
}
int widget_get_absolute_xpos ( widget *wid )
{
if ( wid == NULL ) {
int widget_get_absolute_xpos(widget *wid) {
if (wid == NULL) {
return 0;
}
int retv = wid->x;
if ( wid->parent != NULL ) {
retv += widget_get_absolute_xpos ( wid->parent );
if (wid->parent != NULL) {
retv += widget_get_absolute_xpos(wid->parent);
}
return retv;
}
int widget_get_absolute_ypos ( widget *wid )
{
if ( wid == NULL ) {
int widget_get_absolute_ypos(widget *wid) {
if (wid == NULL) {
return 0;
}
int retv = wid->y;
if ( wid->parent != NULL ) {
retv += widget_get_absolute_ypos ( wid->parent );
if (wid->parent != NULL) {
retv += widget_get_absolute_ypos(wid->parent);
}
return retv;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff