[Cleanup] Using clang-tidy
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#ifndef ROFI_INCLUDE_CSS_COLORS_H
|
#ifndef ROFI_INCLUDE_CSS_COLORS_H
|
||||||
#define ROFI_INCLUDE_CSS_COLORS_H
|
#define ROFI_INCLUDE_CSS_COLORS_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
/**
|
/**
|
||||||
* @defgroup CSSCOLORS CssColors
|
* @defgroup CSSCOLORS CssColors
|
||||||
* @ingroup HELPERS
|
* @ingroup HELPERS
|
||||||
@@ -13,16 +14,16 @@
|
|||||||
/**
|
/**
|
||||||
* Structure of colors.
|
* Structure of colors.
|
||||||
*/
|
*/
|
||||||
typedef struct CSSColor
|
typedef struct CSSColor {
|
||||||
{
|
|
||||||
/** CSS name of the color. */
|
/** CSS name of the color. */
|
||||||
char *name;
|
char *name;
|
||||||
/** BGRA 8 bit color components. */
|
/** BGRA 8 bit color components. */
|
||||||
uint8_t b, g, r, a;
|
uint8_t b, g, r, a;
|
||||||
}CSSColor;
|
} CSSColor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Array with all the named colors. Of type #CSSColor, there are #num_CSSColors items in this array.
|
* Array with all the named colors. Of type #CSSColor, there are #num_CSSColors
|
||||||
|
* items in this array.
|
||||||
*/
|
*/
|
||||||
extern const CSSColor CSSColors[];
|
extern const CSSColor CSSColors[];
|
||||||
/**
|
/**
|
||||||
|
@@ -28,12 +28,13 @@
|
|||||||
#ifndef ROFI_DIALOG_DRUN_H
|
#ifndef ROFI_DIALOG_DRUN_H
|
||||||
#define ROFI_DIALOG_DRUN_H
|
#define ROFI_DIALOG_DRUN_H
|
||||||
|
|
||||||
|
#include "mode.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup DRUNMode DRun
|
* @defgroup DRUNMode DRun
|
||||||
* @ingroup MODES
|
* @ingroup MODES
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
#include <config.h>
|
|
||||||
#ifdef ENABLE_DRUN
|
#ifdef ENABLE_DRUN
|
||||||
/** #Mode object representing the desktop menu run dialog. */
|
/** #Mode object representing the desktop menu run dialog. */
|
||||||
extern Mode drun_mode;
|
extern Mode drun_mode;
|
||||||
|
@@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
#ifndef ROFI_DIALOG_FILE_BROWSER_H
|
#ifndef ROFI_DIALOG_FILE_BROWSER_H
|
||||||
#define ROFI_DIALOG_FILE_BROWSER_H
|
#define ROFI_DIALOG_FILE_BROWSER_H
|
||||||
|
#include "mode.h"
|
||||||
/**
|
/**
|
||||||
* @defgroup FileBrowserMode FileBrowser
|
* @defgroup FileBrowserMode FileBrowser
|
||||||
* @ingroup MODES
|
* @ingroup MODES
|
||||||
@@ -42,7 +42,7 @@ extern Mode file_browser_mode;
|
|||||||
* Create a new filebrowser.
|
* Create a new filebrowser.
|
||||||
* @returns a new filebrowser structure.
|
* @returns a new filebrowser structure.
|
||||||
*/
|
*/
|
||||||
Mode *create_new_file_browser ( void );
|
Mode *create_new_file_browser(void);
|
||||||
/**
|
/**
|
||||||
* @param sw Mode object.
|
* @param sw Mode object.
|
||||||
* @param mretv return value passed in.
|
* @param mretv return value passed in.
|
||||||
@@ -52,6 +52,7 @@ Mode *create_new_file_browser ( void );
|
|||||||
*
|
*
|
||||||
* @returns the state the user selected.
|
* @returns the state the user selected.
|
||||||
*/
|
*/
|
||||||
ModeMode file_browser_mode_completer ( Mode *sw, int mretv, char **input, unsigned int selected_line, char **path );
|
ModeMode file_browser_mode_completer(Mode *sw, int mretv, char **input,
|
||||||
|
unsigned int selected_line, char **path);
|
||||||
/**@}*/
|
/**@}*/
|
||||||
#endif // ROFI_DIALOG_FILE_BROWSER_H
|
#endif // ROFI_DIALOG_FILE_BROWSER_H
|
||||||
|
@@ -28,6 +28,7 @@
|
|||||||
#ifndef ROFI_DIALOG_HELPKEYS_H
|
#ifndef ROFI_DIALOG_HELPKEYS_H
|
||||||
#define ROFI_DIALOG_HELPKEYS_H
|
#define ROFI_DIALOG_HELPKEYS_H
|
||||||
|
|
||||||
|
#include "mode.h"
|
||||||
/**
|
/**
|
||||||
* @defgroup HELPKEYSMode KeysHelp
|
* @defgroup HELPKEYSMode KeysHelp
|
||||||
* @ingroup MODES
|
* @ingroup MODES
|
||||||
|
@@ -28,6 +28,8 @@
|
|||||||
#ifndef ROFI_DIALOG_SCRIPT_H
|
#ifndef ROFI_DIALOG_SCRIPT_H
|
||||||
#define ROFI_DIALOG_SCRIPT_H
|
#define ROFI_DIALOG_SCRIPT_H
|
||||||
|
|
||||||
|
#include "mode.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup SCRIPTMode Script
|
* @defgroup SCRIPTMode Script
|
||||||
* @ingroup MODES
|
* @ingroup MODES
|
||||||
@@ -42,7 +44,7 @@
|
|||||||
*
|
*
|
||||||
* @returns NULL when it fails, a newly allocated ScriptOptions when successful.
|
* @returns NULL when it fails, a newly allocated ScriptOptions when successful.
|
||||||
*/
|
*/
|
||||||
Mode *script_switcher_parse_setup ( const char *str );
|
Mode *script_switcher_parse_setup(const char *str);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param token The modi str to check
|
* @param token The modi str to check
|
||||||
@@ -51,6 +53,6 @@ Mode *script_switcher_parse_setup ( const char *str );
|
|||||||
*
|
*
|
||||||
* @returns true when valid.
|
* @returns true when valid.
|
||||||
*/
|
*/
|
||||||
gboolean script_switcher_is_valid ( const char *token );
|
gboolean script_switcher_is_valid(const char *token);
|
||||||
/**@}*/
|
/**@}*/
|
||||||
#endif // ROFI_DIALOG_SCRIPT_H
|
#endif // ROFI_DIALOG_SCRIPT_H
|
||||||
|
@@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
#ifndef ROFI_DIALOG_SSH_H
|
#ifndef ROFI_DIALOG_SSH_H
|
||||||
#define ROFI_DIALOG_SSH_H
|
#define ROFI_DIALOG_SSH_H
|
||||||
|
#include "mode.h"
|
||||||
/**
|
/**
|
||||||
* @defgroup SSHMode SSH
|
* @defgroup SSHMode SSH
|
||||||
* @ingroup MODES
|
* @ingroup MODES
|
||||||
|
@@ -28,13 +28,14 @@
|
|||||||
#ifndef ROFI_DIALOG_WINDOW_H
|
#ifndef ROFI_DIALOG_WINDOW_H
|
||||||
#define ROFI_DIALOG_WINDOW_H
|
#define ROFI_DIALOG_WINDOW_H
|
||||||
|
|
||||||
|
#include "mode.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup WINDOWMode Window
|
* @defgroup WINDOWMode Window
|
||||||
* @ingroup MODES
|
* @ingroup MODES
|
||||||
*
|
*
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
#include <config.h>
|
|
||||||
#ifdef WINDOW_MODE
|
#ifdef WINDOW_MODE
|
||||||
|
|
||||||
extern Mode window_mode;
|
extern Mode window_mode;
|
||||||
|
@@ -28,9 +28,9 @@
|
|||||||
#ifndef ROFI_DISPLAY_H
|
#ifndef ROFI_DISPLAY_H
|
||||||
#define ROFI_DISPLAY_H
|
#define ROFI_DISPLAY_H
|
||||||
|
|
||||||
#include <glib.h>
|
|
||||||
#include "helper.h"
|
#include "helper.h"
|
||||||
#include "nkutils-bindings.h"
|
#include "nkutils-bindings.h"
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param main_loop The GMainLoop
|
* @param main_loop The GMainLoop
|
||||||
@@ -40,29 +40,29 @@
|
|||||||
*
|
*
|
||||||
* @returns Whether the setup succeeded or not
|
* @returns Whether the setup succeeded or not
|
||||||
*/
|
*/
|
||||||
gboolean display_setup ( GMainLoop *main_loop, NkBindings *bindings );
|
gboolean display_setup(GMainLoop *main_loop, NkBindings *bindings);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do some late setup of the display backend
|
* Do some late setup of the display backend
|
||||||
*
|
*
|
||||||
* @returns Whether the setup succeeded or not
|
* @returns Whether the setup succeeded or not
|
||||||
*/
|
*/
|
||||||
gboolean display_late_setup ( void );
|
gboolean display_late_setup(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do some early cleanup, like unmapping the surface
|
* Do some early cleanup, like unmapping the surface
|
||||||
*/
|
*/
|
||||||
void display_early_cleanup ( void );
|
void display_early_cleanup(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cleanup any remaining display related stuff
|
* Cleanup any remaining display related stuff
|
||||||
*/
|
*/
|
||||||
void display_cleanup ( void );
|
void display_cleanup(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dumps the display layout for -help output
|
* Dumps the display layout for -help output
|
||||||
*/
|
*/
|
||||||
void display_dump_monitor_layout ( void );
|
void display_dump_monitor_layout(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param context The startup notification context for the application to launch
|
* @param context The startup notification context for the application to launch
|
||||||
@@ -71,6 +71,8 @@ void display_dump_monitor_layout ( void );
|
|||||||
*
|
*
|
||||||
* Provides the needed child setup function
|
* Provides the needed child setup function
|
||||||
*/
|
*/
|
||||||
void display_startup_notification ( RofiHelperExecuteContext *context, GSpawnChildSetupFunc *child_setup, gpointer *user_data );
|
void display_startup_notification(RofiHelperExecuteContext *context,
|
||||||
|
GSpawnChildSetupFunc *child_setup,
|
||||||
|
gpointer *user_data);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
132
include/helper.h
132
include/helper.h
@@ -27,8 +27,8 @@
|
|||||||
|
|
||||||
#ifndef ROFI_HELPER_H
|
#ifndef ROFI_HELPER_H
|
||||||
#define ROFI_HELPER_H
|
#define ROFI_HELPER_H
|
||||||
#include <cairo.h>
|
|
||||||
#include "rofi-types.h"
|
#include "rofi-types.h"
|
||||||
|
#include <cairo.h>
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,7 +51,7 @@ G_BEGIN_DECLS
|
|||||||
*
|
*
|
||||||
* @returns TRUE when successful, FALSE when failed.
|
* @returns TRUE when successful, FALSE when failed.
|
||||||
*/
|
*/
|
||||||
int helper_parse_setup ( char * string, char ***output, int *length, ... );
|
int helper_parse_setup(char *string, char ***output, int *length, ...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param input The input string.
|
* @param input The input string.
|
||||||
@@ -61,14 +61,14 @@ int helper_parse_setup ( char * string, char ***output, int *length, ... );
|
|||||||
*
|
*
|
||||||
* @returns a newly allocated array of matching objects
|
* @returns a newly allocated array of matching objects
|
||||||
*/
|
*/
|
||||||
rofi_int_matcher **helper_tokenize ( const char *input, int case_sensitive );
|
rofi_int_matcher **helper_tokenize(const char *input, int case_sensitive);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param tokens Array of regex objects
|
* @param tokens Array of regex objects
|
||||||
*
|
*
|
||||||
* Frees the array of matching objects.
|
* Frees the array of matching objects.
|
||||||
*/
|
*/
|
||||||
void helper_tokenize_free ( rofi_int_matcher ** tokens );
|
void helper_tokenize_free(rofi_int_matcher **tokens);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param key The key to search for
|
* @param key The key to search for
|
||||||
@@ -79,7 +79,7 @@ void helper_tokenize_free ( rofi_int_matcher ** tokens );
|
|||||||
*
|
*
|
||||||
* @returns TRUE if key was found and val was set.
|
* @returns TRUE if key was found and val was set.
|
||||||
*/
|
*/
|
||||||
int find_arg_char ( const char * const key, char *val );
|
int find_arg_char(const char *const key, char *val);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param key The key to search for
|
* @param key The key to search for
|
||||||
@@ -89,7 +89,7 @@ int find_arg_char ( const char * const key, char *val );
|
|||||||
*
|
*
|
||||||
* @returns TRUE if key was found and val was set.
|
* @returns TRUE if key was found and val was set.
|
||||||
*/
|
*/
|
||||||
int find_arg_uint ( const char * const key, unsigned int *val );
|
int find_arg_uint(const char *const key, unsigned int *val);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param key The key to search for
|
* @param key The key to search for
|
||||||
@@ -99,7 +99,7 @@ int find_arg_uint ( const char * const key, unsigned int *val );
|
|||||||
*
|
*
|
||||||
* @returns TRUE if key was found and val was set.
|
* @returns TRUE if key was found and val was set.
|
||||||
*/
|
*/
|
||||||
int find_arg_int ( const char * const key, int *val );
|
int find_arg_int(const char *const key, int *val);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param key The key to search for
|
* @param key The key to search for
|
||||||
@@ -109,7 +109,7 @@ int find_arg_int ( const char * const key, int *val );
|
|||||||
*
|
*
|
||||||
* @returns TRUE if key was found and val was set.
|
* @returns TRUE if key was found and val was set.
|
||||||
*/
|
*/
|
||||||
int find_arg_str ( const char * const key, char** val );
|
int find_arg_str(const char *const key, char **val);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param key The key to search for
|
* @param key The key to search for
|
||||||
@@ -118,7 +118,7 @@ int find_arg_str ( const char * const key, char** val );
|
|||||||
*
|
*
|
||||||
* @returns str vector. user should free array.
|
* @returns str vector. user should free array.
|
||||||
*/
|
*/
|
||||||
const char ** find_arg_strv ( const char *const key );
|
const char **find_arg_strv(const char *const key);
|
||||||
/**
|
/**
|
||||||
* @param key The key to search for
|
* @param key The key to search for
|
||||||
*
|
*
|
||||||
@@ -126,7 +126,7 @@ const char ** find_arg_strv ( const char *const key );
|
|||||||
*
|
*
|
||||||
* @returns return position of string or -1 if not found.
|
* @returns return position of string or -1 if not found.
|
||||||
*/
|
*/
|
||||||
int find_arg ( const char * const key );
|
int find_arg(const char *const key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param tokens List of (input) tokens to match.
|
* @param tokens List of (input) tokens to match.
|
||||||
@@ -136,36 +136,37 @@ int find_arg ( const char * const key );
|
|||||||
*
|
*
|
||||||
* @returns TRUE when matches, FALSE otherwise
|
* @returns TRUE when matches, FALSE otherwise
|
||||||
*/
|
*/
|
||||||
int helper_token_match ( rofi_int_matcher * const *tokens, const char *input );
|
int helper_token_match(rofi_int_matcher *const *tokens, const char *input);
|
||||||
/**
|
/**
|
||||||
* @param cmd The command to execute.
|
* @param cmd The command to execute.
|
||||||
*
|
*
|
||||||
* Execute cmd using config.run_command and outputs the result (stdout) to the opened file
|
* Execute cmd using config.run_command and outputs the result (stdout) to the
|
||||||
* descriptor.
|
* opened file descriptor.
|
||||||
*
|
*
|
||||||
* @returns a valid file descriptor on success, or -1 on failure.
|
* @returns a valid file descriptor on success, or -1 on failure.
|
||||||
*/
|
*/
|
||||||
int execute_generator ( const char * cmd ) __attribute__( ( nonnull ) );
|
int execute_generator(const char *cmd) __attribute__((nonnull));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param pidfile The pidfile to create.
|
* @param pidfile The pidfile to create.
|
||||||
*
|
*
|
||||||
* returns file descriptor (or -1 when failed)
|
* returns file descriptor (or -1 when failed)
|
||||||
*/
|
*/
|
||||||
int create_pid_file ( const char *pidfile );
|
int create_pid_file(const char *pidfile);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove pid file
|
* Remove pid file
|
||||||
*/
|
*/
|
||||||
void remove_pid_file ( int fd );
|
void remove_pid_file(int fd);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do some input validation, especially the first few could break things.
|
* Do some input validation, especially the first few could break things.
|
||||||
* It is good to catch them beforehand.
|
* It is good to catch them beforehand.
|
||||||
*
|
*
|
||||||
* This functions exits the program with 1 when it finds an invalid configuration.
|
* This functions exits the program with 1 when it finds an invalid
|
||||||
|
* configuration.
|
||||||
*/
|
*/
|
||||||
int config_sanity_check ( void );
|
int config_sanity_check(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param arg string to parse.
|
* @param arg string to parse.
|
||||||
@@ -174,7 +175,7 @@ int config_sanity_check ( void );
|
|||||||
*
|
*
|
||||||
* @returns character.
|
* @returns character.
|
||||||
*/
|
*/
|
||||||
char helper_parse_char ( const char *arg );
|
char helper_parse_char(const char *arg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param argc number of arguments.
|
* @param argc number of arguments.
|
||||||
@@ -182,7 +183,7 @@ char helper_parse_char ( const char *arg );
|
|||||||
*
|
*
|
||||||
* Set the application arguments.
|
* Set the application arguments.
|
||||||
*/
|
*/
|
||||||
void cmd_set_arguments ( int argc, char **argv );
|
void cmd_set_arguments(int argc, char **argv);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param input The path to expand
|
* @param input The path to expand
|
||||||
@@ -191,7 +192,7 @@ void cmd_set_arguments ( int argc, char **argv );
|
|||||||
*
|
*
|
||||||
* @returns path
|
* @returns path
|
||||||
*/
|
*/
|
||||||
char *rofi_expand_path ( const char *input );
|
char *rofi_expand_path(const char *input);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param needle The string to find match weight off
|
* @param needle The string to find match weight off
|
||||||
@@ -203,17 +204,19 @@ char *rofi_expand_path ( const char *input );
|
|||||||
*
|
*
|
||||||
* @returns the levenshtein distance between needle and haystack
|
* @returns the levenshtein distance between needle and haystack
|
||||||
*/
|
*/
|
||||||
unsigned int levenshtein ( const char *needle, const glong needlelen, const char *haystack, const glong haystacklen );
|
unsigned int levenshtein(const char *needle, const glong needlelen,
|
||||||
|
const char *haystack, const glong haystacklen);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param data the unvalidated character array holding possible UTF-8 data
|
* @param data the unvalidated character array holding possible UTF-8 data
|
||||||
* @param length the length of the data array
|
* @param length the length of the data array
|
||||||
*
|
*
|
||||||
* Convert string to valid utf-8, replacing invalid parts with replacement character.
|
* Convert string to valid utf-8, replacing invalid parts with replacement
|
||||||
|
* character.
|
||||||
*
|
*
|
||||||
* @returns the converted UTF-8 string
|
* @returns the converted UTF-8 string
|
||||||
*/
|
*/
|
||||||
char * rofi_force_utf8 ( const gchar *data, ssize_t length );
|
char *rofi_force_utf8(const gchar *data, ssize_t length);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param input the char array holding latin text
|
* @param input the char array holding latin text
|
||||||
@@ -223,7 +226,7 @@ char * rofi_force_utf8 ( const gchar *data, ssize_t length );
|
|||||||
*
|
*
|
||||||
* @return the UTF-8 representation of data
|
* @return the UTF-8 representation of data
|
||||||
*/
|
*/
|
||||||
char * rofi_latin_to_utf8_strdup ( const char *input, gssize length );
|
char *rofi_latin_to_utf8_strdup(const char *input, gssize length);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param text the string to escape
|
* @param text the string to escape
|
||||||
@@ -232,7 +235,7 @@ char * rofi_latin_to_utf8_strdup ( const char *input, gssize length );
|
|||||||
*
|
*
|
||||||
* @return the escaped string
|
* @return the escaped string
|
||||||
*/
|
*/
|
||||||
gchar *rofi_escape_markup ( gchar *text );
|
gchar *rofi_escape_markup(gchar *text);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param pattern The user input to match against.
|
* @param pattern The user input to match against.
|
||||||
@@ -240,28 +243,35 @@ gchar *rofi_escape_markup ( gchar *text );
|
|||||||
* @param str The input to match against pattern.
|
* @param str The input to match against pattern.
|
||||||
* @param slen Length of str.
|
* @param slen Length of str.
|
||||||
*
|
*
|
||||||
* rofi_scorer_fuzzy_evaluate implements a global sequence alignment algorithm to find the maximum accumulated score by
|
* rofi_scorer_fuzzy_evaluate implements a global sequence alignment algorithm
|
||||||
* aligning `pattern` to `str`. It applies when `pattern` is a subsequence of `str`.
|
* to find the maximum accumulated score by aligning `pattern` to `str`. It
|
||||||
|
* applies when `pattern` is a subsequence of `str`.
|
||||||
*
|
*
|
||||||
* Scoring criteria
|
* Scoring criteria
|
||||||
* - Prefer matches at the start of a word, or the start of subwords in CamelCase/camelCase/camel123 words. See WORD_START_SCORE/CAMEL_SCORE.
|
* - Prefer matches at the start of a word, or the start of subwords in
|
||||||
|
* CamelCase/camelCase/camel123 words. See WORD_START_SCORE/CAMEL_SCORE.
|
||||||
* - Non-word characters matter. See NON_WORD_SCORE.
|
* - Non-word characters matter. See NON_WORD_SCORE.
|
||||||
* - The first characters of words of `pattern` receive bonus because they usually have more significance than the rest.
|
* - The first characters of words of `pattern` receive bonus because they
|
||||||
* See PATTERN_START_MULTIPLIER/PATTERN_NON_START_MULTIPLIER.
|
* usually have more significance than the rest. See
|
||||||
* - Superfluous characters in `str` will reduce the score (gap penalty). See GAP_SCORE.
|
* PATTERN_START_MULTIPLIER/PATTERN_NON_START_MULTIPLIER.
|
||||||
* - Prefer early occurrence of the first character. See LEADING_GAP_SCORE/GAP_SCORE.
|
* - Superfluous characters in `str` will reduce the score (gap penalty). See
|
||||||
|
* GAP_SCORE.
|
||||||
|
* - Prefer early occurrence of the first character. See
|
||||||
|
* LEADING_GAP_SCORE/GAP_SCORE.
|
||||||
*
|
*
|
||||||
* The recurrence of the dynamic programming:
|
* The recurrence of the dynamic programming:
|
||||||
* dp[i][j]: maximum accumulated score by aligning pattern[0..i] to str[0..j]
|
* dp[i][j]: maximum accumulated score by aligning pattern[0..i] to str[0..j]
|
||||||
* dp[0][j] = leading_gap_penalty(0, j) + score[j]
|
* dp[0][j] = leading_gap_penalty(0, j) + score[j]
|
||||||
* dp[i][j] = max(dp[i-1][j-1] + CONSECUTIVE_SCORE, max(dp[i-1][k] + gap_penalty(k+1, j) + score[j] : k < j))
|
* dp[i][j] = max(dp[i-1][j-1] + CONSECUTIVE_SCORE, max(dp[i-1][k] +
|
||||||
|
* gap_penalty(k+1, j) + score[j] : k < j))
|
||||||
*
|
*
|
||||||
* The first dimension can be suppressed since we do not need a matching scheme, which reduces the space complexity from
|
* The first dimension can be suppressed since we do not need a matching
|
||||||
* O(N*M) to O(M)
|
* scheme, which reduces the space complexity from O(N*M) to O(M)
|
||||||
*
|
*
|
||||||
* @returns the sorting weight.
|
* @returns the sorting weight.
|
||||||
*/
|
*/
|
||||||
int rofi_scorer_fuzzy_evaluate ( const char *pattern, glong plen, const char *str, glong slen );
|
int rofi_scorer_fuzzy_evaluate(const char *pattern, glong plen, const char *str,
|
||||||
|
glong slen);
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -271,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.
|
* Compares the `G_NORMALIZE_ALL_COMPOSE` forms of the two strings.
|
||||||
*
|
*
|
||||||
* @returns less than, equal to, or greater than zero if the first `n` characters (not bytes) of `a`
|
* @returns less than, equal to, or greater than zero if the first `n`
|
||||||
* are found, respectively, to be less than, to match, or be greater than the first `n`
|
* characters (not bytes) of `a` are found, respectively, to be less than, to
|
||||||
* characters (not bytes) of `b`.
|
* match, or be greater than the first `n` characters (not bytes) of `b`.
|
||||||
*/
|
*/
|
||||||
int utf8_strncmp ( const char *a, const char* b, size_t n ) __attribute__( ( nonnull ( 1, 2 ) ) );
|
int utf8_strncmp(const char *a, const char *b, size_t n)
|
||||||
|
__attribute__((nonnull(1, 2)));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The startup notification context of the application to launch
|
* The startup notification context of the application to launch
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
/** The name of the application */
|
/** The name of the application */
|
||||||
const gchar *name;
|
const gchar *name;
|
||||||
/** The binary name of the application */
|
/** The binary name of the application */
|
||||||
@@ -309,7 +319,9 @@ typedef struct
|
|||||||
*
|
*
|
||||||
* @returns TRUE when successful, FALSE when failed.
|
* @returns TRUE when successful, FALSE when failed.
|
||||||
*/
|
*/
|
||||||
gboolean helper_execute ( const char *wd, char **args, const char *error_precmd, const char *error_cmd, RofiHelperExecuteContext *context );
|
gboolean helper_execute(const char *wd, char **args, const char *error_precmd,
|
||||||
|
const char *error_cmd,
|
||||||
|
RofiHelperExecuteContext *context);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param wd The work directory (optional)
|
* @param wd The work directory (optional)
|
||||||
@@ -322,7 +334,9 @@ gboolean helper_execute ( const char *wd, char **args, const char *error_precmd,
|
|||||||
*
|
*
|
||||||
* @returns FALSE On failure, TRUE on success
|
* @returns FALSE On failure, TRUE on success
|
||||||
*/
|
*/
|
||||||
gboolean helper_execute_command ( const char *wd, const char *cmd, gboolean run_in_term, RofiHelperExecuteContext *context );
|
gboolean helper_execute_command(const char *wd, const char *cmd,
|
||||||
|
gboolean run_in_term,
|
||||||
|
RofiHelperExecuteContext *context);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param file The file path
|
* @param file The file path
|
||||||
@@ -331,7 +345,8 @@ gboolean helper_execute_command ( const char *wd, const char *cmd, gboolean run_
|
|||||||
*
|
*
|
||||||
* @returns a cairo surface from an svg path
|
* @returns a cairo surface from an svg path
|
||||||
*/
|
*/
|
||||||
cairo_surface_t *cairo_image_surface_create_from_svg ( const gchar* file, int height );
|
cairo_surface_t *cairo_image_surface_create_from_svg(const gchar *file,
|
||||||
|
int height);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ranges.
|
* Ranges.
|
||||||
@@ -344,7 +359,7 @@ cairo_surface_t *cairo_image_surface_create_from_svg ( const gchar* file, int he
|
|||||||
*
|
*
|
||||||
* ranges
|
* ranges
|
||||||
*/
|
*/
|
||||||
void parse_ranges ( char *input, rofi_range_pair **list, unsigned int *length );
|
void parse_ranges(char *input, rofi_range_pair **list, unsigned int *length);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param format The format string used. See below for possible syntax.
|
* @param format The format string used. See below for possible syntax.
|
||||||
@@ -361,25 +376,28 @@ void parse_ranges ( char *input, rofi_range_pair **list, unsigned int *length );
|
|||||||
* * f: Print the entered filter.
|
* * f: Print the entered filter.
|
||||||
* * F: Print the entered filter, quoted
|
* * F: Print the entered filter, quoted
|
||||||
*
|
*
|
||||||
* This functions outputs the formatted string to stdout, appends a newline (\n) character and
|
* This functions outputs the formatted string to stdout, appends a newline (\n)
|
||||||
* calls flush on the file descriptor.
|
* character and calls flush on the file descriptor.
|
||||||
*/
|
*/
|
||||||
void rofi_output_formatted_line ( const char *format, const char *string, int selected_line, const char *filter );
|
void rofi_output_formatted_line(const char *format, const char *string,
|
||||||
|
int selected_line, const char *filter);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string The string with elements to be replaced
|
* @param string The string with elements to be replaced
|
||||||
* @param ... Set of {key}, value that will be replaced, terminated by a NULL
|
* @param ... Set of {key}, value that will be replaced, terminated by a
|
||||||
|
* NULL
|
||||||
*
|
*
|
||||||
* Items {key} are replaced by the value if '{key}' is passed as key/value pair, otherwise removed from string.
|
* Items {key} are replaced by the value if '{key}' is passed as key/value pair,
|
||||||
* If the {key} is in between [] all the text between [] are removed if {key}
|
* otherwise removed from string. If the {key} is in between [] all the text
|
||||||
* is not found. Otherwise key is replaced and [ & ] removed.
|
* between [] are removed if {key} is not found. Otherwise key is replaced and [
|
||||||
|
* & ] removed.
|
||||||
*
|
*
|
||||||
* This allows for optional replacement, f.e. '{ssh-client} [-t {title}] -e
|
* This allows for optional replacement, f.e. '{ssh-client} [-t {title}] -e
|
||||||
* "{cmd}"' the '-t {title}' is only there if {title} is set.
|
* "{cmd}"' the '-t {title}' is only there if {title} is set.
|
||||||
*
|
*
|
||||||
* @returns a new string with the keys replaced.
|
* @returns a new string with the keys replaced.
|
||||||
*/
|
*/
|
||||||
char *helper_string_replace_if_exists ( char * string, ... );
|
char *helper_string_replace_if_exists(char *string, ...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param file File name passed to option.
|
* @param file File name passed to option.
|
||||||
@@ -387,9 +405,7 @@ char *helper_string_replace_if_exists ( char * string, ... );
|
|||||||
*
|
*
|
||||||
* @returns path to theme or copy of filename if not found.
|
* @returns path to theme or copy of filename if not found.
|
||||||
*/
|
*/
|
||||||
char *helper_get_theme_path ( const char *file, const char *ext );
|
char *helper_get_theme_path(const char *file, const char *ext);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
#ifndef INCLUDE_ROFI_TYPES_H
|
#ifndef INCLUDE_ROFI_TYPES_H
|
||||||
#define INCLUDE_ROFI_TYPES_H
|
#define INCLUDE_ROFI_TYPES_H
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
@@ -8,8 +7,7 @@ G_BEGIN_DECLS
|
|||||||
/**
|
/**
|
||||||
* Type of property
|
* Type of property
|
||||||
*/
|
*/
|
||||||
typedef enum
|
typedef enum {
|
||||||
{
|
|
||||||
/** Integer */
|
/** Integer */
|
||||||
P_INTEGER,
|
P_INTEGER,
|
||||||
/** Double */
|
/** Double */
|
||||||
@@ -48,11 +46,10 @@ typedef enum
|
|||||||
* This array maps PropertyType to a user-readable name.
|
* This array maps PropertyType to a user-readable name.
|
||||||
* It is important this is kept in sync.
|
* It is important this is kept in sync.
|
||||||
*/
|
*/
|
||||||
extern const char * const PropertyTypeName[P_NUM_TYPES];
|
extern const char *const PropertyTypeName[P_NUM_TYPES];
|
||||||
|
|
||||||
/** Style of text highlight */
|
/** Style of text highlight */
|
||||||
typedef enum
|
typedef enum {
|
||||||
{
|
|
||||||
/** no highlight */
|
/** no highlight */
|
||||||
ROFI_HL_NONE = 0,
|
ROFI_HL_NONE = 0,
|
||||||
/** bold */
|
/** bold */
|
||||||
@@ -70,8 +67,7 @@ typedef enum
|
|||||||
} RofiHighlightStyle;
|
} RofiHighlightStyle;
|
||||||
|
|
||||||
/** Style of line */
|
/** Style of line */
|
||||||
typedef enum
|
typedef enum {
|
||||||
{
|
|
||||||
/** Solid line */
|
/** Solid line */
|
||||||
ROFI_HL_SOLID,
|
ROFI_HL_SOLID,
|
||||||
/** Dashed line */
|
/** Dashed line */
|
||||||
@@ -81,8 +77,7 @@ typedef enum
|
|||||||
/**
|
/**
|
||||||
* Distance unit type.
|
* Distance unit type.
|
||||||
*/
|
*/
|
||||||
typedef enum
|
typedef enum {
|
||||||
{
|
|
||||||
/** PixelWidth in pixels. */
|
/** PixelWidth in pixels. */
|
||||||
ROFI_PU_PX,
|
ROFI_PU_PX,
|
||||||
/** PixelWidth in millimeters. */
|
/** PixelWidth in millimeters. */
|
||||||
@@ -98,8 +93,7 @@ typedef enum
|
|||||||
/**
|
/**
|
||||||
* Structure representing a distance.
|
* Structure representing a distance.
|
||||||
*/
|
*/
|
||||||
typedef enum
|
typedef enum {
|
||||||
{
|
|
||||||
ROFI_DISTANCE_MODIFIER_NONE,
|
ROFI_DISTANCE_MODIFIER_NONE,
|
||||||
ROFI_DISTANCE_MODIFIER_ADD,
|
ROFI_DISTANCE_MODIFIER_ADD,
|
||||||
ROFI_DISTANCE_MODIFIER_SUBTRACT,
|
ROFI_DISTANCE_MODIFIER_SUBTRACT,
|
||||||
@@ -111,8 +105,7 @@ typedef enum
|
|||||||
ROFI_DISTANCE_MODIFIER_MAX,
|
ROFI_DISTANCE_MODIFIER_MAX,
|
||||||
} RofiDistanceModifier;
|
} RofiDistanceModifier;
|
||||||
|
|
||||||
typedef struct RofiDistanceUnit
|
typedef struct RofiDistanceUnit {
|
||||||
{
|
|
||||||
/** Distance */
|
/** Distance */
|
||||||
double distance;
|
double distance;
|
||||||
/** Unit type of the distance */
|
/** Unit type of the distance */
|
||||||
@@ -128,8 +121,7 @@ typedef struct RofiDistanceUnit
|
|||||||
struct RofiDistanceUnit *right;
|
struct RofiDistanceUnit *right;
|
||||||
} RofiDistanceUnit;
|
} RofiDistanceUnit;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
/** Base */
|
/** Base */
|
||||||
RofiDistanceUnit base;
|
RofiDistanceUnit base;
|
||||||
/** Style of the line (optional)*/
|
/** Style of the line (optional)*/
|
||||||
@@ -139,8 +131,7 @@ typedef struct
|
|||||||
/**
|
/**
|
||||||
* Type of orientation.
|
* Type of orientation.
|
||||||
*/
|
*/
|
||||||
typedef enum
|
typedef enum {
|
||||||
{
|
|
||||||
ROFI_ORIENTATION_VERTICAL,
|
ROFI_ORIENTATION_VERTICAL,
|
||||||
ROFI_ORIENTATION_HORIZONTAL
|
ROFI_ORIENTATION_HORIZONTAL
|
||||||
} RofiOrientation;
|
} RofiOrientation;
|
||||||
@@ -148,8 +139,7 @@ typedef enum
|
|||||||
/**
|
/**
|
||||||
* Cursor type.
|
* Cursor type.
|
||||||
*/
|
*/
|
||||||
typedef enum
|
typedef enum {
|
||||||
{
|
|
||||||
ROFI_CURSOR_DEFAULT,
|
ROFI_CURSOR_DEFAULT,
|
||||||
ROFI_CURSOR_POINTER,
|
ROFI_CURSOR_POINTER,
|
||||||
ROFI_CURSOR_TEXT
|
ROFI_CURSOR_TEXT
|
||||||
@@ -158,8 +148,7 @@ typedef enum
|
|||||||
/**
|
/**
|
||||||
* Represent the color in theme.
|
* Represent the color in theme.
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
/** red channel */
|
/** red channel */
|
||||||
double red;
|
double red;
|
||||||
/** green channel */
|
/** green channel */
|
||||||
@@ -173,14 +162,9 @@ typedef struct
|
|||||||
/**
|
/**
|
||||||
* Theme Image
|
* Theme Image
|
||||||
*/
|
*/
|
||||||
typedef enum
|
typedef enum { ROFI_IMAGE_URL, ROFI_IMAGE_LINEAR_GRADIENT } RofiImageType;
|
||||||
{
|
|
||||||
ROFI_IMAGE_URL,
|
|
||||||
ROFI_IMAGE_LINEAR_GRADIENT
|
|
||||||
} RofiImageType;
|
|
||||||
|
|
||||||
typedef enum
|
typedef enum {
|
||||||
{
|
|
||||||
ROFI_DIRECTION_LEFT,
|
ROFI_DIRECTION_LEFT,
|
||||||
ROFI_DIRECTION_RIGHT,
|
ROFI_DIRECTION_RIGHT,
|
||||||
ROFI_DIRECTION_TOP,
|
ROFI_DIRECTION_TOP,
|
||||||
@@ -188,16 +172,14 @@ typedef enum
|
|||||||
ROFI_DIRECTION_ANGLE,
|
ROFI_DIRECTION_ANGLE,
|
||||||
} RofiDirection;
|
} RofiDirection;
|
||||||
|
|
||||||
typedef enum
|
typedef enum {
|
||||||
{
|
|
||||||
ROFI_SCALE_NONE,
|
ROFI_SCALE_NONE,
|
||||||
ROFI_SCALE_BOTH,
|
ROFI_SCALE_BOTH,
|
||||||
ROFI_SCALE_HEIGHT,
|
ROFI_SCALE_HEIGHT,
|
||||||
ROFI_SCALE_WIDTH,
|
ROFI_SCALE_WIDTH,
|
||||||
} RofiScaleType;
|
} RofiScaleType;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
RofiImageType type;
|
RofiImageType type;
|
||||||
char *url;
|
char *url;
|
||||||
RofiScaleType scaling;
|
RofiScaleType scaling;
|
||||||
@@ -217,8 +199,7 @@ typedef struct
|
|||||||
/**
|
/**
|
||||||
* RofiPadding
|
* RofiPadding
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
RofiDistance top;
|
RofiDistance top;
|
||||||
RofiDistance right;
|
RofiDistance right;
|
||||||
RofiDistance bottom;
|
RofiDistance bottom;
|
||||||
@@ -228,8 +209,7 @@ typedef struct
|
|||||||
/**
|
/**
|
||||||
* Theme highlight.
|
* Theme highlight.
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
/** style to display */
|
/** style to display */
|
||||||
RofiHighlightStyle style;
|
RofiHighlightStyle style;
|
||||||
/** Color */
|
/** Color */
|
||||||
@@ -245,8 +225,7 @@ typedef struct
|
|||||||
*
|
*
|
||||||
* @ingroup CONFIGURATION
|
* @ingroup CONFIGURATION
|
||||||
*/
|
*/
|
||||||
typedef enum
|
typedef enum {
|
||||||
{
|
|
||||||
/** Center */
|
/** Center */
|
||||||
WL_CENTER = 0,
|
WL_CENTER = 0,
|
||||||
/** Top middle */
|
/** Top middle */
|
||||||
@@ -267,8 +246,7 @@ typedef enum
|
|||||||
WL_SOUTH_WEST = WL_SOUTH | WL_WEST,
|
WL_SOUTH_WEST = WL_SOUTH | WL_WEST,
|
||||||
} WindowLocation;
|
} WindowLocation;
|
||||||
|
|
||||||
typedef union _PropertyValue
|
typedef union _PropertyValue {
|
||||||
{
|
|
||||||
/** integer */
|
/** integer */
|
||||||
int i;
|
int i;
|
||||||
/** Double */
|
/** Double */
|
||||||
@@ -284,8 +262,7 @@ typedef union _PropertyValue
|
|||||||
/** RofiPadding */
|
/** RofiPadding */
|
||||||
RofiPadding padding;
|
RofiPadding padding;
|
||||||
/** Reference */
|
/** Reference */
|
||||||
struct
|
struct {
|
||||||
{
|
|
||||||
/** Name */
|
/** Name */
|
||||||
char *name;
|
char *name;
|
||||||
/** Cached looked up ref */
|
/** Cached looked up ref */
|
||||||
@@ -304,8 +281,7 @@ typedef union _PropertyValue
|
|||||||
/**
|
/**
|
||||||
* Property structure.
|
* Property structure.
|
||||||
*/
|
*/
|
||||||
typedef struct Property
|
typedef struct Property {
|
||||||
{
|
|
||||||
/** Name of property */
|
/** Name of property */
|
||||||
char *name;
|
char *name;
|
||||||
/** Type of property. */
|
/** Type of property. */
|
||||||
@@ -317,8 +293,7 @@ typedef struct Property
|
|||||||
/**
|
/**
|
||||||
* Structure to hold a range.
|
* Structure to hold a range.
|
||||||
*/
|
*/
|
||||||
typedef struct rofi_range_pair
|
typedef struct rofi_range_pair {
|
||||||
{
|
|
||||||
int start;
|
int start;
|
||||||
int stop;
|
int stop;
|
||||||
} rofi_range_pair;
|
} rofi_range_pair;
|
||||||
@@ -326,8 +301,7 @@ typedef struct rofi_range_pair
|
|||||||
/**
|
/**
|
||||||
* Internal structure for matching.
|
* Internal structure for matching.
|
||||||
*/
|
*/
|
||||||
typedef struct rofi_int_matcher_t
|
typedef struct rofi_int_matcher_t {
|
||||||
{
|
|
||||||
GRegex *regex;
|
GRegex *regex;
|
||||||
gboolean invert;
|
gboolean invert;
|
||||||
} rofi_int_matcher;
|
} rofi_int_matcher;
|
||||||
@@ -336,9 +310,8 @@ typedef struct rofi_int_matcher_t
|
|||||||
* Structure with data to process by each worker thread.
|
* Structure with data to process by each worker thread.
|
||||||
* TODO: Make this more generic wrapper.
|
* TODO: Make this more generic wrapper.
|
||||||
*/
|
*/
|
||||||
typedef struct _thread_state
|
typedef struct _thread_state {
|
||||||
{
|
void (*callback)(struct _thread_state *t, gpointer data);
|
||||||
void ( *callback )( struct _thread_state *t, gpointer data );
|
|
||||||
} thread_state;
|
} thread_state;
|
||||||
|
|
||||||
extern GThreadPool *tpool;
|
extern GThreadPool *tpool;
|
||||||
|
@@ -32,13 +32,12 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef ROFI_TIMINGS_H
|
#ifndef ROFI_TIMINGS_H
|
||||||
#define ROFI_TIMINGS_H
|
#define ROFI_TIMINGS_H
|
||||||
#include <config.h>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init the timestamping mechanism .
|
* Init the timestamping mechanism .
|
||||||
* implementation.
|
* implementation.
|
||||||
*/
|
*/
|
||||||
void rofi_timings_init ( void );
|
void rofi_timings_init(void);
|
||||||
/**
|
/**
|
||||||
* @param file filename tick originates from
|
* @param file filename tick originates from
|
||||||
* @param str function name.
|
* @param str function name.
|
||||||
@@ -47,30 +46,31 @@ void rofi_timings_init ( void );
|
|||||||
*
|
*
|
||||||
* Report a tick.
|
* Report a tick.
|
||||||
*/
|
*/
|
||||||
void rofi_timings_tick ( const char *file, char const *str, int line, char const *msg );
|
void rofi_timings_tick(const char *file, char const *str, int line,
|
||||||
|
char const *msg);
|
||||||
/**
|
/**
|
||||||
* Stop the timestamping mechanism
|
* Stop the timestamping mechanism
|
||||||
*/
|
*/
|
||||||
void rofi_timings_quit ( void );
|
void rofi_timings_quit(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start timestamping mechanism.
|
* Start timestamping mechanism.
|
||||||
* Call to this function is time 0.
|
* Call to this function is time 0.
|
||||||
*/
|
*/
|
||||||
#define TIMINGS_START() rofi_timings_init ()
|
#define TIMINGS_START() rofi_timings_init()
|
||||||
/**
|
/**
|
||||||
* Report current time since TIMINGS_START
|
* Report current time since TIMINGS_START
|
||||||
*/
|
*/
|
||||||
#define TICK() rofi_timings_tick ( __FILE__, __func__, __LINE__, "" )
|
#define TICK() rofi_timings_tick(__FILE__, __func__, __LINE__, "")
|
||||||
/**
|
/**
|
||||||
* @param a an string
|
* @param a an string
|
||||||
* Report current time since TIMINGS_START
|
* Report current time since TIMINGS_START
|
||||||
*/
|
*/
|
||||||
#define TICK_N( a ) rofi_timings_tick ( __FILE__, __func__, __LINE__, a )
|
#define TICK_N(a) rofi_timings_tick(__FILE__, __func__, __LINE__, a)
|
||||||
/**
|
/**
|
||||||
* Stop timestamping mechanism.
|
* Stop timestamping mechanism.
|
||||||
*/
|
*/
|
||||||
#define TIMINGS_STOP() rofi_timings_quit ()
|
#define TIMINGS_STOP() rofi_timings_quit()
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ void rofi_timings_quit ( void );
|
|||||||
* @param a an string
|
* @param a an string
|
||||||
* Report current time since TIMINGS_START
|
* Report current time since TIMINGS_START
|
||||||
*/
|
*/
|
||||||
#define TICK_N( a )
|
#define TICK_N(a)
|
||||||
|
|
||||||
#endif // ROFI_TIMINGS_H
|
#endif // ROFI_TIMINGS_H
|
||||||
/**@}*/
|
/**@}*/
|
||||||
|
@@ -29,6 +29,7 @@
|
|||||||
#define ROFI_HBOX_H
|
#define ROFI_HBOX_H
|
||||||
|
|
||||||
#include "widget.h"
|
#include "widget.h"
|
||||||
|
#include "rofi-types.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup box box
|
* @defgroup box box
|
||||||
|
@@ -28,6 +28,8 @@
|
|||||||
#ifndef ROFI_LISTVIEW_H
|
#ifndef ROFI_LISTVIEW_H
|
||||||
#define ROFI_LISTVIEW_H
|
#define ROFI_LISTVIEW_H
|
||||||
|
|
||||||
|
#include "widgets/textbox.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup listview listview
|
* @defgroup listview listview
|
||||||
* @ingroup widget
|
* @ingroup widget
|
||||||
|
@@ -1,154 +1,152 @@
|
|||||||
#include <stdint.h>
|
|
||||||
#include "css-colors.h"
|
#include "css-colors.h"
|
||||||
const CSSColor CSSColors[] = {
|
const CSSColor CSSColors[] = {
|
||||||
{ .name = "AliceBlue", .r = 0xF0, .g = 0xF8, .b = 0xFF },
|
{.name = "AliceBlue", .r = 0xF0, .g = 0xF8, .b = 0xFF},
|
||||||
{ .name = "AntiqueWhite", .r = 0xFA, .g = 0xEB, .b = 0xD7 },
|
{.name = "AntiqueWhite", .r = 0xFA, .g = 0xEB, .b = 0xD7},
|
||||||
{ .name = "Aqua", .r = 0x00, .g = 0xFF, .b = 0xFF },
|
{.name = "Aqua", .r = 0x00, .g = 0xFF, .b = 0xFF},
|
||||||
{ .name = "Aquamarine", .r = 0x7F, .g = 0xFF, .b = 0xD4 },
|
{.name = "Aquamarine", .r = 0x7F, .g = 0xFF, .b = 0xD4},
|
||||||
{ .name = "Azure", .r = 0xF0, .g = 0xFF, .b = 0xFF },
|
{.name = "Azure", .r = 0xF0, .g = 0xFF, .b = 0xFF},
|
||||||
{ .name = "Beige", .r = 0xF5, .g = 0xF5, .b = 0xDC },
|
{.name = "Beige", .r = 0xF5, .g = 0xF5, .b = 0xDC},
|
||||||
{ .name = "Bisque", .r = 0xFF, .g = 0xE4, .b = 0xC4 },
|
{.name = "Bisque", .r = 0xFF, .g = 0xE4, .b = 0xC4},
|
||||||
{ .name = "Black", .r = 0x00, .g = 0x00, .b = 0x00 },
|
{.name = "Black", .r = 0x00, .g = 0x00, .b = 0x00},
|
||||||
{ .name = "BlanchedAlmond", .r = 0xFF, .g = 0xEB, .b = 0xCD },
|
{.name = "BlanchedAlmond", .r = 0xFF, .g = 0xEB, .b = 0xCD},
|
||||||
{ .name = "Blue", .r = 0x00, .g = 0x00, .b = 0xFF },
|
{.name = "Blue", .r = 0x00, .g = 0x00, .b = 0xFF},
|
||||||
{ .name = "BlueViolet", .r = 0x8A, .g = 0x2B, .b = 0xE2 },
|
{.name = "BlueViolet", .r = 0x8A, .g = 0x2B, .b = 0xE2},
|
||||||
{ .name = "Brown", .r = 0xA5, .g = 0x2A, .b = 0x2A },
|
{.name = "Brown", .r = 0xA5, .g = 0x2A, .b = 0x2A},
|
||||||
{ .name = "BurlyWood", .r = 0xDE, .g = 0xB8, .b = 0x87 },
|
{.name = "BurlyWood", .r = 0xDE, .g = 0xB8, .b = 0x87},
|
||||||
{ .name = "CadetBlue", .r = 0x5F, .g = 0x9E, .b = 0xA0 },
|
{.name = "CadetBlue", .r = 0x5F, .g = 0x9E, .b = 0xA0},
|
||||||
{ .name = "Chartreuse", .r = 0x7F, .g = 0xFF, .b = 0x00 },
|
{.name = "Chartreuse", .r = 0x7F, .g = 0xFF, .b = 0x00},
|
||||||
{ .name = "Chocolate", .r = 0xD2, .g = 0x69, .b = 0x1E },
|
{.name = "Chocolate", .r = 0xD2, .g = 0x69, .b = 0x1E},
|
||||||
{ .name = "Coral", .r = 0xFF, .g = 0x7F, .b = 0x50 },
|
{.name = "Coral", .r = 0xFF, .g = 0x7F, .b = 0x50},
|
||||||
{ .name = "CornflowerBlue", .r = 0x64, .g = 0x95, .b = 0xED },
|
{.name = "CornflowerBlue", .r = 0x64, .g = 0x95, .b = 0xED},
|
||||||
{ .name = "Cornsilk", .r = 0xFF, .g = 0xF8, .b = 0xDC },
|
{.name = "Cornsilk", .r = 0xFF, .g = 0xF8, .b = 0xDC},
|
||||||
{ .name = "Crimson", .r = 0xDC, .g = 0x14, .b = 0x3C },
|
{.name = "Crimson", .r = 0xDC, .g = 0x14, .b = 0x3C},
|
||||||
{ .name = "Cyan", .r = 0x00, .g = 0xFF, .b = 0xFF },
|
{.name = "Cyan", .r = 0x00, .g = 0xFF, .b = 0xFF},
|
||||||
{ .name = "DarkBlue", .r = 0x00, .g = 0x00, .b = 0x8B },
|
{.name = "DarkBlue", .r = 0x00, .g = 0x00, .b = 0x8B},
|
||||||
{ .name = "DarkCyan", .r = 0x00, .g = 0x8B, .b = 0x8B },
|
{.name = "DarkCyan", .r = 0x00, .g = 0x8B, .b = 0x8B},
|
||||||
{ .name = "DarkGoldenRod", .r = 0xB8, .g = 0x86, .b = 0x0B },
|
{.name = "DarkGoldenRod", .r = 0xB8, .g = 0x86, .b = 0x0B},
|
||||||
{ .name = "DarkGray", .r = 0xA9, .g = 0xA9, .b = 0xA9 },
|
{.name = "DarkGray", .r = 0xA9, .g = 0xA9, .b = 0xA9},
|
||||||
{ .name = "DarkGrey", .r = 0xA9, .g = 0xA9, .b = 0xA9 },
|
{.name = "DarkGrey", .r = 0xA9, .g = 0xA9, .b = 0xA9},
|
||||||
{ .name = "DarkGreen", .r = 0x00, .g = 0x64, .b = 0x00 },
|
{.name = "DarkGreen", .r = 0x00, .g = 0x64, .b = 0x00},
|
||||||
{ .name = "DarkKhaki", .r = 0xBD, .g = 0xB7, .b = 0x6B },
|
{.name = "DarkKhaki", .r = 0xBD, .g = 0xB7, .b = 0x6B},
|
||||||
{ .name = "DarkMagenta", .r = 0x8B, .g = 0x00, .b = 0x8B },
|
{.name = "DarkMagenta", .r = 0x8B, .g = 0x00, .b = 0x8B},
|
||||||
{ .name = "DarkOliveGreen", .r = 0x55, .g = 0x6B, .b = 0x2F },
|
{.name = "DarkOliveGreen", .r = 0x55, .g = 0x6B, .b = 0x2F},
|
||||||
{ .name = "DarkOrange", .r = 0xFF, .g = 0x8C, .b = 0x00 },
|
{.name = "DarkOrange", .r = 0xFF, .g = 0x8C, .b = 0x00},
|
||||||
{ .name = "DarkOrchid", .r = 0x99, .g = 0x32, .b = 0xCC },
|
{.name = "DarkOrchid", .r = 0x99, .g = 0x32, .b = 0xCC},
|
||||||
{ .name = "DarkRed", .r = 0x8B, .g = 0x00, .b = 0x00 },
|
{.name = "DarkRed", .r = 0x8B, .g = 0x00, .b = 0x00},
|
||||||
{ .name = "DarkSalmon", .r = 0xE9, .g = 0x96, .b = 0x7A },
|
{.name = "DarkSalmon", .r = 0xE9, .g = 0x96, .b = 0x7A},
|
||||||
{ .name = "DarkSeaGreen", .r = 0x8F, .g = 0xBC, .b = 0x8F },
|
{.name = "DarkSeaGreen", .r = 0x8F, .g = 0xBC, .b = 0x8F},
|
||||||
{ .name = "DarkSlateBlue", .r = 0x48, .g = 0x3D, .b = 0x8B },
|
{.name = "DarkSlateBlue", .r = 0x48, .g = 0x3D, .b = 0x8B},
|
||||||
{ .name = "DarkSlateGray", .r = 0x2F, .g = 0x4F, .b = 0x4F },
|
{.name = "DarkSlateGray", .r = 0x2F, .g = 0x4F, .b = 0x4F},
|
||||||
{ .name = "DarkSlateGrey", .r = 0x2F, .g = 0x4F, .b = 0x4F },
|
{.name = "DarkSlateGrey", .r = 0x2F, .g = 0x4F, .b = 0x4F},
|
||||||
{ .name = "DarkTurquoise", .r = 0x00, .g = 0xCE, .b = 0xD1 },
|
{.name = "DarkTurquoise", .r = 0x00, .g = 0xCE, .b = 0xD1},
|
||||||
{ .name = "DarkViolet", .r = 0x94, .g = 0x00, .b = 0xD3 },
|
{.name = "DarkViolet", .r = 0x94, .g = 0x00, .b = 0xD3},
|
||||||
{ .name = "DeepPink", .r = 0xFF, .g = 0x14, .b = 0x93 },
|
{.name = "DeepPink", .r = 0xFF, .g = 0x14, .b = 0x93},
|
||||||
{ .name = "DeepSkyBlue", .r = 0x00, .g = 0xBF, .b = 0xFF },
|
{.name = "DeepSkyBlue", .r = 0x00, .g = 0xBF, .b = 0xFF},
|
||||||
{ .name = "DimGray", .r = 0x69, .g = 0x69, .b = 0x69 },
|
{.name = "DimGray", .r = 0x69, .g = 0x69, .b = 0x69},
|
||||||
{ .name = "DimGrey", .r = 0x69, .g = 0x69, .b = 0x69 },
|
{.name = "DimGrey", .r = 0x69, .g = 0x69, .b = 0x69},
|
||||||
{ .name = "DodgerBlue", .r = 0x1E, .g = 0x90, .b = 0xFF },
|
{.name = "DodgerBlue", .r = 0x1E, .g = 0x90, .b = 0xFF},
|
||||||
{ .name = "FireBrick", .r = 0xB2, .g = 0x22, .b = 0x22 },
|
{.name = "FireBrick", .r = 0xB2, .g = 0x22, .b = 0x22},
|
||||||
{ .name = "FloralWhite", .r = 0xFF, .g = 0xFA, .b = 0xF0 },
|
{.name = "FloralWhite", .r = 0xFF, .g = 0xFA, .b = 0xF0},
|
||||||
{ .name = "ForestGreen", .r = 0x22, .g = 0x8B, .b = 0x22 },
|
{.name = "ForestGreen", .r = 0x22, .g = 0x8B, .b = 0x22},
|
||||||
{ .name = "Fuchsia", .r = 0xFF, .g = 0x00, .b = 0xFF },
|
{.name = "Fuchsia", .r = 0xFF, .g = 0x00, .b = 0xFF},
|
||||||
{ .name = "Gainsboro", .r = 0xDC, .g = 0xDC, .b = 0xDC },
|
{.name = "Gainsboro", .r = 0xDC, .g = 0xDC, .b = 0xDC},
|
||||||
{ .name = "GhostWhite", .r = 0xF8, .g = 0xF8, .b = 0xFF },
|
{.name = "GhostWhite", .r = 0xF8, .g = 0xF8, .b = 0xFF},
|
||||||
{ .name = "Gold", .r = 0xFF, .g = 0xD7, .b = 0x00 },
|
{.name = "Gold", .r = 0xFF, .g = 0xD7, .b = 0x00},
|
||||||
{ .name = "GoldenRod", .r = 0xDA, .g = 0xA5, .b = 0x20 },
|
{.name = "GoldenRod", .r = 0xDA, .g = 0xA5, .b = 0x20},
|
||||||
{ .name = "Gray", .r = 0x80, .g = 0x80, .b = 0x80 },
|
{.name = "Gray", .r = 0x80, .g = 0x80, .b = 0x80},
|
||||||
{ .name = "Grey", .r = 0x80, .g = 0x80, .b = 0x80 },
|
{.name = "Grey", .r = 0x80, .g = 0x80, .b = 0x80},
|
||||||
{ .name = "Green", .r = 0x00, .g = 0x80, .b = 0x00 },
|
{.name = "Green", .r = 0x00, .g = 0x80, .b = 0x00},
|
||||||
{ .name = "GreenYellow", .r = 0xAD, .g = 0xFF, .b = 0x2F },
|
{.name = "GreenYellow", .r = 0xAD, .g = 0xFF, .b = 0x2F},
|
||||||
{ .name = "HoneyDew", .r = 0xF0, .g = 0xFF, .b = 0xF0 },
|
{.name = "HoneyDew", .r = 0xF0, .g = 0xFF, .b = 0xF0},
|
||||||
{ .name = "HotPink", .r = 0xFF, .g = 0x69, .b = 0xB4 },
|
{.name = "HotPink", .r = 0xFF, .g = 0x69, .b = 0xB4},
|
||||||
{ .name = "IndianRed", .r = 0xCD, .g = 0x5C, .b = 0x5C },
|
{.name = "IndianRed", .r = 0xCD, .g = 0x5C, .b = 0x5C},
|
||||||
{ .name = "Indigo", .r = 0x4B, .g = 0x00, .b = 0x82 },
|
{.name = "Indigo", .r = 0x4B, .g = 0x00, .b = 0x82},
|
||||||
{ .name = "Ivory", .r = 0xFF, .g = 0xFF, .b = 0xF0 },
|
{.name = "Ivory", .r = 0xFF, .g = 0xFF, .b = 0xF0},
|
||||||
{ .name = "Khaki", .r = 0xF0, .g = 0xE6, .b = 0x8C },
|
{.name = "Khaki", .r = 0xF0, .g = 0xE6, .b = 0x8C},
|
||||||
{ .name = "Lavender", .r = 0xE6, .g = 0xE6, .b = 0xFA },
|
{.name = "Lavender", .r = 0xE6, .g = 0xE6, .b = 0xFA},
|
||||||
{ .name = "LavenderBlush", .r = 0xFF, .g = 0xF0, .b = 0xF5 },
|
{.name = "LavenderBlush", .r = 0xFF, .g = 0xF0, .b = 0xF5},
|
||||||
{ .name = "LawnGreen", .r = 0x7C, .g = 0xFC, .b = 0x00 },
|
{.name = "LawnGreen", .r = 0x7C, .g = 0xFC, .b = 0x00},
|
||||||
{ .name = "LemonChiffon", .r = 0xFF, .g = 0xFA, .b = 0xCD },
|
{.name = "LemonChiffon", .r = 0xFF, .g = 0xFA, .b = 0xCD},
|
||||||
{ .name = "LightBlue", .r = 0xAD, .g = 0xD8, .b = 0xE6 },
|
{.name = "LightBlue", .r = 0xAD, .g = 0xD8, .b = 0xE6},
|
||||||
{ .name = "LightCoral", .r = 0xF0, .g = 0x80, .b = 0x80 },
|
{.name = "LightCoral", .r = 0xF0, .g = 0x80, .b = 0x80},
|
||||||
{ .name = "LightCyan", .r = 0xE0, .g = 0xFF, .b = 0xFF },
|
{.name = "LightCyan", .r = 0xE0, .g = 0xFF, .b = 0xFF},
|
||||||
{ .name = "LightGoldenRodYellow", .r = 0xFA, .g = 0xFA, .b = 0xD2 },
|
{.name = "LightGoldenRodYellow", .r = 0xFA, .g = 0xFA, .b = 0xD2},
|
||||||
{ .name = "LightGray", .r = 0xD3, .g = 0xD3, .b = 0xD3 },
|
{.name = "LightGray", .r = 0xD3, .g = 0xD3, .b = 0xD3},
|
||||||
{ .name = "LightGrey", .r = 0xD3, .g = 0xD3, .b = 0xD3 },
|
{.name = "LightGrey", .r = 0xD3, .g = 0xD3, .b = 0xD3},
|
||||||
{ .name = "LightGreen", .r = 0x90, .g = 0xEE, .b = 0x90 },
|
{.name = "LightGreen", .r = 0x90, .g = 0xEE, .b = 0x90},
|
||||||
{ .name = "LightPink", .r = 0xFF, .g = 0xB6, .b = 0xC1 },
|
{.name = "LightPink", .r = 0xFF, .g = 0xB6, .b = 0xC1},
|
||||||
{ .name = "LightSalmon", .r = 0xFF, .g = 0xA0, .b = 0x7A },
|
{.name = "LightSalmon", .r = 0xFF, .g = 0xA0, .b = 0x7A},
|
||||||
{ .name = "LightSeaGreen", .r = 0x20, .g = 0xB2, .b = 0xAA },
|
{.name = "LightSeaGreen", .r = 0x20, .g = 0xB2, .b = 0xAA},
|
||||||
{ .name = "LightSkyBlue", .r = 0x87, .g = 0xCE, .b = 0xFA },
|
{.name = "LightSkyBlue", .r = 0x87, .g = 0xCE, .b = 0xFA},
|
||||||
{ .name = "LightSlateGray", .r = 0x77, .g = 0x88, .b = 0x99 },
|
{.name = "LightSlateGray", .r = 0x77, .g = 0x88, .b = 0x99},
|
||||||
{ .name = "LightSlateGrey", .r = 0x77, .g = 0x88, .b = 0x99 },
|
{.name = "LightSlateGrey", .r = 0x77, .g = 0x88, .b = 0x99},
|
||||||
{ .name = "LightSteelBlue", .r = 0xB0, .g = 0xC4, .b = 0xDE },
|
{.name = "LightSteelBlue", .r = 0xB0, .g = 0xC4, .b = 0xDE},
|
||||||
{ .name = "LightYellow", .r = 0xFF, .g = 0xFF, .b = 0xE0 },
|
{.name = "LightYellow", .r = 0xFF, .g = 0xFF, .b = 0xE0},
|
||||||
{ .name = "Lime", .r = 0x00, .g = 0xFF, .b = 0x00 },
|
{.name = "Lime", .r = 0x00, .g = 0xFF, .b = 0x00},
|
||||||
{ .name = "LimeGreen", .r = 0x32, .g = 0xCD, .b = 0x32 },
|
{.name = "LimeGreen", .r = 0x32, .g = 0xCD, .b = 0x32},
|
||||||
{ .name = "Linen", .r = 0xFA, .g = 0xF0, .b = 0xE6 },
|
{.name = "Linen", .r = 0xFA, .g = 0xF0, .b = 0xE6},
|
||||||
{ .name = "Magenta", .r = 0xFF, .g = 0x00, .b = 0xFF },
|
{.name = "Magenta", .r = 0xFF, .g = 0x00, .b = 0xFF},
|
||||||
{ .name = "Maroon", .r = 0x80, .g = 0x00, .b = 0x00 },
|
{.name = "Maroon", .r = 0x80, .g = 0x00, .b = 0x00},
|
||||||
{ .name = "MediumAquaMarine", .r = 0x66, .g = 0xCD, .b = 0xAA },
|
{.name = "MediumAquaMarine", .r = 0x66, .g = 0xCD, .b = 0xAA},
|
||||||
{ .name = "MediumBlue", .r = 0x00, .g = 0x00, .b = 0xCD },
|
{.name = "MediumBlue", .r = 0x00, .g = 0x00, .b = 0xCD},
|
||||||
{ .name = "MediumOrchid", .r = 0xBA, .g = 0x55, .b = 0xD3 },
|
{.name = "MediumOrchid", .r = 0xBA, .g = 0x55, .b = 0xD3},
|
||||||
{ .name = "MediumPurple", .r = 0x93, .g = 0x70, .b = 0xDB },
|
{.name = "MediumPurple", .r = 0x93, .g = 0x70, .b = 0xDB},
|
||||||
{ .name = "MediumSeaGreen", .r = 0x3C, .g = 0xB3, .b = 0x71 },
|
{.name = "MediumSeaGreen", .r = 0x3C, .g = 0xB3, .b = 0x71},
|
||||||
{ .name = "MediumSlateBlue", .r = 0x7B, .g = 0x68, .b = 0xEE },
|
{.name = "MediumSlateBlue", .r = 0x7B, .g = 0x68, .b = 0xEE},
|
||||||
{ .name = "MediumSpringGreen", .r = 0x00, .g = 0xFA, .b = 0x9A },
|
{.name = "MediumSpringGreen", .r = 0x00, .g = 0xFA, .b = 0x9A},
|
||||||
{ .name = "MediumTurquoise", .r = 0x48, .g = 0xD1, .b = 0xCC },
|
{.name = "MediumTurquoise", .r = 0x48, .g = 0xD1, .b = 0xCC},
|
||||||
{ .name = "MediumVioletRed", .r = 0xC7, .g = 0x15, .b = 0x85 },
|
{.name = "MediumVioletRed", .r = 0xC7, .g = 0x15, .b = 0x85},
|
||||||
{ .name = "MidnightBlue", .r = 0x19, .g = 0x19, .b = 0x70 },
|
{.name = "MidnightBlue", .r = 0x19, .g = 0x19, .b = 0x70},
|
||||||
{ .name = "MintCream", .r = 0xF5, .g = 0xFF, .b = 0xFA },
|
{.name = "MintCream", .r = 0xF5, .g = 0xFF, .b = 0xFA},
|
||||||
{ .name = "MistyRose", .r = 0xFF, .g = 0xE4, .b = 0xE1 },
|
{.name = "MistyRose", .r = 0xFF, .g = 0xE4, .b = 0xE1},
|
||||||
{ .name = "Moccasin", .r = 0xFF, .g = 0xE4, .b = 0xB5 },
|
{.name = "Moccasin", .r = 0xFF, .g = 0xE4, .b = 0xB5},
|
||||||
{ .name = "NavajoWhite", .r = 0xFF, .g = 0xDE, .b = 0xAD },
|
{.name = "NavajoWhite", .r = 0xFF, .g = 0xDE, .b = 0xAD},
|
||||||
{ .name = "Navy", .r = 0x00, .g = 0x00, .b = 0x80 },
|
{.name = "Navy", .r = 0x00, .g = 0x00, .b = 0x80},
|
||||||
{ .name = "OldLace", .r = 0xFD, .g = 0xF5, .b = 0xE6 },
|
{.name = "OldLace", .r = 0xFD, .g = 0xF5, .b = 0xE6},
|
||||||
{ .name = "Olive", .r = 0x80, .g = 0x80, .b = 0x00 },
|
{.name = "Olive", .r = 0x80, .g = 0x80, .b = 0x00},
|
||||||
{ .name = "OliveDrab", .r = 0x6B, .g = 0x8E, .b = 0x23 },
|
{.name = "OliveDrab", .r = 0x6B, .g = 0x8E, .b = 0x23},
|
||||||
{ .name = "Orange", .r = 0xFF, .g = 0xA5, .b = 0x00 },
|
{.name = "Orange", .r = 0xFF, .g = 0xA5, .b = 0x00},
|
||||||
{ .name = "OrangeRed", .r = 0xFF, .g = 0x45, .b = 0x00 },
|
{.name = "OrangeRed", .r = 0xFF, .g = 0x45, .b = 0x00},
|
||||||
{ .name = "Orchid", .r = 0xDA, .g = 0x70, .b = 0xD6 },
|
{.name = "Orchid", .r = 0xDA, .g = 0x70, .b = 0xD6},
|
||||||
{ .name = "PaleGoldenRod", .r = 0xEE, .g = 0xE8, .b = 0xAA },
|
{.name = "PaleGoldenRod", .r = 0xEE, .g = 0xE8, .b = 0xAA},
|
||||||
{ .name = "PaleGreen", .r = 0x98, .g = 0xFB, .b = 0x98 },
|
{.name = "PaleGreen", .r = 0x98, .g = 0xFB, .b = 0x98},
|
||||||
{ .name = "PaleTurquoise", .r = 0xAF, .g = 0xEE, .b = 0xEE },
|
{.name = "PaleTurquoise", .r = 0xAF, .g = 0xEE, .b = 0xEE},
|
||||||
{ .name = "PaleVioletRed", .r = 0xDB, .g = 0x70, .b = 0x93 },
|
{.name = "PaleVioletRed", .r = 0xDB, .g = 0x70, .b = 0x93},
|
||||||
{ .name = "PapayaWhip", .r = 0xFF, .g = 0xEF, .b = 0xD5 },
|
{.name = "PapayaWhip", .r = 0xFF, .g = 0xEF, .b = 0xD5},
|
||||||
{ .name = "PeachPuff", .r = 0xFF, .g = 0xDA, .b = 0xB9 },
|
{.name = "PeachPuff", .r = 0xFF, .g = 0xDA, .b = 0xB9},
|
||||||
{ .name = "Peru", .r = 0xCD, .g = 0x85, .b = 0x3F },
|
{.name = "Peru", .r = 0xCD, .g = 0x85, .b = 0x3F},
|
||||||
{ .name = "Pink", .r = 0xFF, .g = 0xC0, .b = 0xCB },
|
{.name = "Pink", .r = 0xFF, .g = 0xC0, .b = 0xCB},
|
||||||
{ .name = "Plum", .r = 0xDD, .g = 0xA0, .b = 0xDD },
|
{.name = "Plum", .r = 0xDD, .g = 0xA0, .b = 0xDD},
|
||||||
{ .name = "PowderBlue", .r = 0xB0, .g = 0xE0, .b = 0xE6 },
|
{.name = "PowderBlue", .r = 0xB0, .g = 0xE0, .b = 0xE6},
|
||||||
{ .name = "Purple", .r = 0x80, .g = 0x00, .b = 0x80 },
|
{.name = "Purple", .r = 0x80, .g = 0x00, .b = 0x80},
|
||||||
{ .name = "RebeccaPurple", .r = 0x66, .g = 0x33, .b = 0x99 },
|
{.name = "RebeccaPurple", .r = 0x66, .g = 0x33, .b = 0x99},
|
||||||
{ .name = "Red", .r = 0xFF, .g = 0x00, .b = 0x00 },
|
{.name = "Red", .r = 0xFF, .g = 0x00, .b = 0x00},
|
||||||
{ .name = "RosyBrown", .r = 0xBC, .g = 0x8F, .b = 0x8F },
|
{.name = "RosyBrown", .r = 0xBC, .g = 0x8F, .b = 0x8F},
|
||||||
{ .name = "RoyalBlue", .r = 0x41, .g = 0x69, .b = 0xE1 },
|
{.name = "RoyalBlue", .r = 0x41, .g = 0x69, .b = 0xE1},
|
||||||
{ .name = "SaddleBrown", .r = 0x8B, .g = 0x45, .b = 0x13 },
|
{.name = "SaddleBrown", .r = 0x8B, .g = 0x45, .b = 0x13},
|
||||||
{ .name = "Salmon", .r = 0xFA, .g = 0x80, .b = 0x72 },
|
{.name = "Salmon", .r = 0xFA, .g = 0x80, .b = 0x72},
|
||||||
{ .name = "SandyBrown", .r = 0xF4, .g = 0xA4, .b = 0x60 },
|
{.name = "SandyBrown", .r = 0xF4, .g = 0xA4, .b = 0x60},
|
||||||
{ .name = "SeaGreen", .r = 0x2E, .g = 0x8B, .b = 0x57 },
|
{.name = "SeaGreen", .r = 0x2E, .g = 0x8B, .b = 0x57},
|
||||||
{ .name = "SeaShell", .r = 0xFF, .g = 0xF5, .b = 0xEE },
|
{.name = "SeaShell", .r = 0xFF, .g = 0xF5, .b = 0xEE},
|
||||||
{ .name = "Sienna", .r = 0xA0, .g = 0x52, .b = 0x2D },
|
{.name = "Sienna", .r = 0xA0, .g = 0x52, .b = 0x2D},
|
||||||
{ .name = "Silver", .r = 0xC0, .g = 0xC0, .b = 0xC0 },
|
{.name = "Silver", .r = 0xC0, .g = 0xC0, .b = 0xC0},
|
||||||
{ .name = "SkyBlue", .r = 0x87, .g = 0xCE, .b = 0xEB },
|
{.name = "SkyBlue", .r = 0x87, .g = 0xCE, .b = 0xEB},
|
||||||
{ .name = "SlateBlue", .r = 0x6A, .g = 0x5A, .b = 0xCD },
|
{.name = "SlateBlue", .r = 0x6A, .g = 0x5A, .b = 0xCD},
|
||||||
{ .name = "SlateGray", .r = 0x70, .g = 0x80, .b = 0x90 },
|
{.name = "SlateGray", .r = 0x70, .g = 0x80, .b = 0x90},
|
||||||
{ .name = "SlateGrey", .r = 0x70, .g = 0x80, .b = 0x90 },
|
{.name = "SlateGrey", .r = 0x70, .g = 0x80, .b = 0x90},
|
||||||
{ .name = "Snow", .r = 0xFF, .g = 0xFA, .b = 0xFA },
|
{.name = "Snow", .r = 0xFF, .g = 0xFA, .b = 0xFA},
|
||||||
{ .name = "SpringGreen", .r = 0x00, .g = 0xFF, .b = 0x7F },
|
{.name = "SpringGreen", .r = 0x00, .g = 0xFF, .b = 0x7F},
|
||||||
{ .name = "SteelBlue", .r = 0x46, .g = 0x82, .b = 0xB4 },
|
{.name = "SteelBlue", .r = 0x46, .g = 0x82, .b = 0xB4},
|
||||||
{ .name = "Tan", .r = 0xD2, .g = 0xB4, .b = 0x8C },
|
{.name = "Tan", .r = 0xD2, .g = 0xB4, .b = 0x8C},
|
||||||
{ .name = "Teal", .r = 0x00, .g = 0x80, .b = 0x80 },
|
{.name = "Teal", .r = 0x00, .g = 0x80, .b = 0x80},
|
||||||
{ .name = "Thistle", .r = 0xD8, .g = 0xBF, .b = 0xD8 },
|
{.name = "Thistle", .r = 0xD8, .g = 0xBF, .b = 0xD8},
|
||||||
{ .name = "Tomato", .r = 0xFF, .g = 0x63, .b = 0x47 },
|
{.name = "Tomato", .r = 0xFF, .g = 0x63, .b = 0x47},
|
||||||
{ .name = "Turquoise", .r = 0x40, .g = 0xE0, .b = 0xD0 },
|
{.name = "Turquoise", .r = 0x40, .g = 0xE0, .b = 0xD0},
|
||||||
{ .name = "Violet", .r = 0xEE, .g = 0x82, .b = 0xEE },
|
{.name = "Violet", .r = 0xEE, .g = 0x82, .b = 0xEE},
|
||||||
{ .name = "Wheat", .r = 0xF5, .g = 0xDE, .b = 0xB3 },
|
{.name = "Wheat", .r = 0xF5, .g = 0xDE, .b = 0xB3},
|
||||||
{ .name = "White", .r = 0xFF, .g = 0xFF, .b = 0xFF },
|
{.name = "White", .r = 0xFF, .g = 0xFF, .b = 0xFF},
|
||||||
{ .name = "WhiteSmoke", .r = 0xF5, .g = 0xF5, .b = 0xF5 },
|
{.name = "WhiteSmoke", .r = 0xF5, .g = 0xF5, .b = 0xF5},
|
||||||
{ .name = "Yellow", .r = 0xFF, .g = 0xFF, .b = 0x00 },
|
{.name = "Yellow", .r = 0xFF, .g = 0xFF, .b = 0x00},
|
||||||
{ .name = "YellowGreen", .r = 0x9A, .g = 0xCD, .b = 0x32 }
|
{.name = "YellowGreen", .r = 0x9A, .g = 0xCD, .b = 0x32}};
|
||||||
};
|
|
||||||
|
|
||||||
const unsigned int num_CSSColors = sizeof ( CSSColors ) / sizeof ( *CSSColors );
|
const unsigned int num_CSSColors = sizeof(CSSColors) / sizeof(*CSSColors);
|
||||||
|
@@ -28,29 +28,26 @@
|
|||||||
/** The log domain of this dialog. */
|
/** The log domain of this dialog. */
|
||||||
#define G_LOG_DOMAIN "Dialogs.Combi"
|
#define G_LOG_DOMAIN "Dialogs.Combi"
|
||||||
|
|
||||||
#include <config.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <rofi.h>
|
|
||||||
#include "settings.h"
|
|
||||||
#include "helper.h"
|
#include "helper.h"
|
||||||
|
#include "settings.h"
|
||||||
|
#include <rofi.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "mode-private.h"
|
||||||
#include <dialogs/dialogs.h>
|
#include <dialogs/dialogs.h>
|
||||||
#include <pango/pango.h>
|
#include <pango/pango.h>
|
||||||
#include "mode-private.h"
|
|
||||||
#include <theme.h>
|
#include <theme.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Combi Mode
|
* Combi Mode
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
Mode *mode;
|
Mode *mode;
|
||||||
gboolean disable;
|
gboolean disable;
|
||||||
} CombiMode;
|
} CombiMode;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
// List of (combined) entries.
|
// List of (combined) entries.
|
||||||
unsigned int cmd_list_length;
|
unsigned int cmd_list_length;
|
||||||
// List to validate where each switcher starts.
|
// List to validate where each switcher starts.
|
||||||
@@ -61,46 +58,45 @@ typedef struct
|
|||||||
CombiMode *switchers;
|
CombiMode *switchers;
|
||||||
} CombiModePrivateData;
|
} CombiModePrivateData;
|
||||||
|
|
||||||
static void combi_mode_parse_switchers ( Mode *sw )
|
static void combi_mode_parse_switchers(Mode *sw) {
|
||||||
{
|
CombiModePrivateData *pd = mode_get_private_data(sw);
|
||||||
CombiModePrivateData *pd = mode_get_private_data ( sw );
|
|
||||||
char *savept = NULL;
|
char *savept = NULL;
|
||||||
// Make a copy, as strtok will modify it.
|
// Make a copy, as strtok will modify it.
|
||||||
char *switcher_str = g_strdup ( config.combi_modi );
|
char *switcher_str = g_strdup(config.combi_modi);
|
||||||
const char * const sep = ",#";
|
const char *const sep = ",#";
|
||||||
// Split token on ','. This modifies switcher_str.
|
// Split token on ','. This modifies switcher_str.
|
||||||
for ( char *token = strtok_r ( switcher_str, sep, &savept ); token != NULL;
|
for (char *token = strtok_r(switcher_str, sep, &savept); token != NULL;
|
||||||
token = strtok_r ( NULL, sep, &savept ) ) {
|
token = strtok_r(NULL, sep, &savept)) {
|
||||||
// Resize and add entry.
|
// Resize and add entry.
|
||||||
pd->switchers = (CombiMode *) g_realloc ( pd->switchers,
|
pd->switchers = (CombiMode *)g_realloc(
|
||||||
sizeof ( CombiMode ) * ( pd->num_switchers + 1 ) );
|
pd->switchers, sizeof(CombiMode) * (pd->num_switchers + 1));
|
||||||
|
|
||||||
Mode *mode = rofi_collect_modi_search ( token );
|
Mode *mode = rofi_collect_modi_search(token);
|
||||||
if ( mode != NULL ) {
|
if (mode != NULL) {
|
||||||
pd->switchers[pd->num_switchers].disable = FALSE;
|
pd->switchers[pd->num_switchers].disable = FALSE;
|
||||||
pd->switchers[pd->num_switchers++].mode = mode;
|
pd->switchers[pd->num_switchers++].mode = mode;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// If not build in, use custom switchers.
|
// If not build in, use custom switchers.
|
||||||
mode = script_switcher_parse_setup ( token );
|
mode = script_switcher_parse_setup(token);
|
||||||
if ( mode != NULL ) {
|
if (mode != NULL) {
|
||||||
pd->switchers[pd->num_switchers].disable = FALSE;
|
pd->switchers[pd->num_switchers].disable = FALSE;
|
||||||
pd->switchers[pd->num_switchers++].mode = mode;
|
pd->switchers[pd->num_switchers++].mode = mode;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Report error, don't continue.
|
// Report error, don't continue.
|
||||||
g_warning ( "Invalid script switcher: %s", token );
|
g_warning("Invalid script switcher: %s", token);
|
||||||
token = NULL;
|
token = NULL;
|
||||||
}
|
}
|
||||||
// Free string that was modified by strtok_r
|
// 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 )
|
static unsigned int combi_mode_get_num_entries(const Mode *sw) {
|
||||||
{
|
const CombiModePrivateData *pd =
|
||||||
const CombiModePrivateData *pd = (const CombiModePrivateData *) mode_get_private_data ( sw );
|
(const CombiModePrivateData *)mode_get_private_data(sw);
|
||||||
unsigned int length = 0;
|
unsigned int length = 0;
|
||||||
for ( unsigned int i = 0; i < pd->num_switchers; i++ ) {
|
for (unsigned int i = 0; i < pd->num_switchers; i++) {
|
||||||
unsigned int entries = mode_get_num_entries ( pd->switchers[i].mode );
|
unsigned int entries = mode_get_num_entries(pd->switchers[i].mode);
|
||||||
pd->starts[i] = length;
|
pd->starts[i] = length;
|
||||||
pd->lengths[i] = entries;
|
pd->lengths[i] = entries;
|
||||||
length += entries;
|
length += entries;
|
||||||
@@ -108,130 +104,137 @@ static unsigned int combi_mode_get_num_entries ( const Mode *sw )
|
|||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int combi_mode_init ( Mode *sw )
|
static int combi_mode_init(Mode *sw) {
|
||||||
{
|
if (mode_get_private_data(sw) == NULL) {
|
||||||
if ( mode_get_private_data ( sw ) == NULL ) {
|
CombiModePrivateData *pd = g_malloc0(sizeof(*pd));
|
||||||
CombiModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
|
mode_set_private_data(sw, (void *)pd);
|
||||||
mode_set_private_data ( sw, (void *) pd );
|
combi_mode_parse_switchers(sw);
|
||||||
combi_mode_parse_switchers ( sw );
|
pd->starts = g_malloc0(sizeof(int) * pd->num_switchers);
|
||||||
pd->starts = g_malloc0 ( sizeof ( int ) * pd->num_switchers );
|
pd->lengths = g_malloc0(sizeof(int) * pd->num_switchers);
|
||||||
pd->lengths = g_malloc0 ( sizeof ( int ) * pd->num_switchers );
|
for (unsigned int i = 0; i < pd->num_switchers; i++) {
|
||||||
for ( unsigned int i = 0; i < pd->num_switchers; i++ ) {
|
if (!mode_init(pd->switchers[i].mode)) {
|
||||||
if ( !mode_init ( pd->switchers[i].mode ) ) {
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( pd->cmd_list_length == 0 ) {
|
if (pd->cmd_list_length == 0) {
|
||||||
pd->cmd_list_length = combi_mode_get_num_entries ( sw );
|
pd->cmd_list_length = combi_mode_get_num_entries(sw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
static void combi_mode_destroy ( Mode *sw )
|
static void combi_mode_destroy(Mode *sw) {
|
||||||
{
|
CombiModePrivateData *pd = (CombiModePrivateData *)mode_get_private_data(sw);
|
||||||
CombiModePrivateData *pd = (CombiModePrivateData *) mode_get_private_data ( sw );
|
if (pd != NULL) {
|
||||||
if ( pd != NULL ) {
|
g_free(pd->starts);
|
||||||
g_free ( pd->starts );
|
g_free(pd->lengths);
|
||||||
g_free ( pd->lengths );
|
|
||||||
// Cleanup switchers.
|
// Cleanup switchers.
|
||||||
for ( unsigned int i = 0; i < pd->num_switchers; i++ ) {
|
for (unsigned int i = 0; i < pd->num_switchers; i++) {
|
||||||
mode_destroy ( pd->switchers[i].mode );
|
mode_destroy(pd->switchers[i].mode);
|
||||||
}
|
}
|
||||||
g_free ( pd->switchers );
|
g_free(pd->switchers);
|
||||||
g_free ( pd );
|
g_free(pd);
|
||||||
mode_set_private_data ( sw, NULL );
|
mode_set_private_data(sw, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line )
|
static ModeMode combi_mode_result(Mode *sw, int mretv, char **input,
|
||||||
{
|
unsigned int selected_line) {
|
||||||
CombiModePrivateData *pd = mode_get_private_data ( sw );
|
CombiModePrivateData *pd = mode_get_private_data(sw);
|
||||||
|
|
||||||
if ( input[0][0] == '!' ) {
|
if (input[0][0] == '!') {
|
||||||
int switcher = -1;
|
int switcher = -1;
|
||||||
// Implement strchrnul behaviour.
|
// Implement strchrnul behaviour.
|
||||||
char *eob = g_utf8_strchr ( input[0], -1, ' ' );
|
char *eob = g_utf8_strchr(input[0], -1, ' ');
|
||||||
if ( eob == NULL ) {
|
if (eob == NULL) {
|
||||||
eob = &( input[0][strlen ( input[0] )] );
|
eob = &(input[0][strlen(input[0])]);
|
||||||
}
|
}
|
||||||
ssize_t bang_len = g_utf8_pointer_to_offset ( input[0], eob ) - 1;
|
ssize_t bang_len = g_utf8_pointer_to_offset(input[0], eob) - 1;
|
||||||
if ( bang_len > 0 ) {
|
if (bang_len > 0) {
|
||||||
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
|
for (unsigned i = 0; i < pd->num_switchers; i++) {
|
||||||
const char *mode_name = mode_get_name ( pd->switchers[i].mode );
|
const char *mode_name = mode_get_name(pd->switchers[i].mode);
|
||||||
size_t mode_name_len = g_utf8_strlen ( mode_name, -1 );
|
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 ) {
|
if ((size_t)bang_len <= mode_name_len &&
|
||||||
|
utf8_strncmp(&input[0][1], mode_name, bang_len) == 0) {
|
||||||
switcher = i;
|
switcher = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( switcher >= 0 ) {
|
if (switcher >= 0) {
|
||||||
if ( eob[0] == ' ' ) {
|
if (eob[0] == ' ') {
|
||||||
char *n = eob + 1;
|
char *n = eob + 1;
|
||||||
return mode_result ( pd->switchers[switcher].mode, mretv, &n,
|
return mode_result(pd->switchers[switcher].mode, mretv, &n,
|
||||||
selected_line - pd->starts[switcher] );
|
selected_line - pd->starts[switcher]);
|
||||||
}
|
}
|
||||||
return MODE_EXIT;
|
return MODE_EXIT;
|
||||||
}
|
}
|
||||||
} else if ( ( mretv& MENU_COMPLETE) ) {
|
} else if ((mretv & MENU_COMPLETE)) {
|
||||||
return RELOAD_DIALOG;
|
return RELOAD_DIALOG;
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
|
for (unsigned i = 0; i < pd->num_switchers; i++) {
|
||||||
if ( selected_line >= pd->starts[i] &&
|
if (selected_line >= pd->starts[i] &&
|
||||||
selected_line < ( pd->starts[i] + pd->lengths[i] ) ) {
|
selected_line < (pd->starts[i] + pd->lengths[i])) {
|
||||||
return mode_result ( pd->switchers[i].mode, mretv, input, selected_line - pd->starts[i] );
|
return mode_result(pd->switchers[i].mode, mretv, input,
|
||||||
|
selected_line - pd->starts[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( ( mretv & MENU_CUSTOM_INPUT ) ) {
|
if ((mretv & MENU_CUSTOM_INPUT)) {
|
||||||
return mode_result ( pd->switchers[0].mode, mretv, input, selected_line );
|
return mode_result(pd->switchers[0].mode, mretv, input, selected_line);
|
||||||
}
|
}
|
||||||
return MODE_EXIT;
|
return MODE_EXIT;
|
||||||
}
|
}
|
||||||
static int combi_mode_match ( const Mode *sw, rofi_int_matcher **tokens, unsigned int index )
|
static int combi_mode_match(const Mode *sw, rofi_int_matcher **tokens,
|
||||||
{
|
unsigned int index) {
|
||||||
CombiModePrivateData *pd = mode_get_private_data ( sw );
|
CombiModePrivateData *pd = mode_get_private_data(sw);
|
||||||
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
|
for (unsigned i = 0; i < pd->num_switchers; i++) {
|
||||||
if ( pd->switchers[i].disable ) {
|
if (pd->switchers[i].disable) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ( index >= pd->starts[i] && index < ( pd->starts[i] + pd->lengths[i] ) ) {
|
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 mode_token_match(pd->switchers[i].mode, tokens,
|
||||||
|
index - pd->starts[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *state, GList **attr_list, int get_entry )
|
static char *combi_mgrv(const Mode *sw, unsigned int selected_line, int *state,
|
||||||
{
|
GList **attr_list, int get_entry) {
|
||||||
CombiModePrivateData *pd = mode_get_private_data ( sw );
|
CombiModePrivateData *pd = mode_get_private_data(sw);
|
||||||
if ( !get_entry ) {
|
if (!get_entry) {
|
||||||
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
|
for (unsigned i = 0; i < pd->num_switchers; i++) {
|
||||||
if ( selected_line >= pd->starts[i] && selected_line < ( pd->starts[i] + pd->lengths[i] ) ) {
|
if (selected_line >= pd->starts[i] &&
|
||||||
mode_get_display_value ( pd->switchers[i].mode, selected_line - pd->starts[i], state, attr_list, FALSE );
|
selected_line < (pd->starts[i] + pd->lengths[i])) {
|
||||||
|
mode_get_display_value(pd->switchers[i].mode,
|
||||||
|
selected_line - pd->starts[i], state, attr_list,
|
||||||
|
FALSE);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
|
for (unsigned i = 0; i < pd->num_switchers; i++) {
|
||||||
if ( selected_line >= pd->starts[i] && selected_line < ( pd->starts[i] + pd->lengths[i] ) ) {
|
if (selected_line >= pd->starts[i] &&
|
||||||
char * retv;
|
selected_line < (pd->starts[i] + pd->lengths[i])) {
|
||||||
char * str = retv = mode_get_display_value ( pd->switchers[i].mode, selected_line - pd->starts[i], state, attr_list, TRUE );
|
char *retv;
|
||||||
const char *dname = mode_get_display_name ( pd->switchers[i].mode );
|
char *str = retv = mode_get_display_value(pd->switchers[i].mode,
|
||||||
if ( !config.combi_hide_mode_prefix ) {
|
selected_line - pd->starts[i],
|
||||||
retv = g_strdup_printf ( "%s %s", dname, str );
|
state, attr_list, TRUE);
|
||||||
g_free ( str );
|
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 ) {
|
if (attr_list != NULL) {
|
||||||
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_COLOR, pd->switchers[i].mode->name, TRUE );
|
Property *p = rofi_theme_find_property(
|
||||||
if ( p != NULL ) {
|
wid, P_COLOR, pd->switchers[i].mode->name, TRUE);
|
||||||
PangoAttribute *pa = pango_attr_foreground_new (
|
if (p != NULL) {
|
||||||
p->value.color.red * 65535,
|
PangoAttribute *pa = pango_attr_foreground_new(
|
||||||
p->value.color.green * 65535,
|
p->value.color.red * 65535, p->value.color.green * 65535,
|
||||||
p->value.color.blue * 65535 );
|
p->value.color.blue * 65535);
|
||||||
pa->start_index = PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING;
|
pa->start_index = PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING;
|
||||||
pa->end_index = strlen ( dname );
|
pa->end_index = strlen(dname);
|
||||||
*attr_list = g_list_append ( *attr_list, pa );
|
*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;
|
return NULL;
|
||||||
}
|
}
|
||||||
static char * combi_get_completion ( const Mode *sw, unsigned int index )
|
static char *combi_get_completion(const Mode *sw, unsigned int index) {
|
||||||
{
|
CombiModePrivateData *pd = mode_get_private_data(sw);
|
||||||
CombiModePrivateData *pd = mode_get_private_data ( sw );
|
for (unsigned i = 0; i < pd->num_switchers; i++) {
|
||||||
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
|
if (index >= pd->starts[i] && index < (pd->starts[i] + pd->lengths[i])) {
|
||||||
if ( index >= pd->starts[i] && index < ( pd->starts[i] + pd->lengths[i] ) ) {
|
char *comp =
|
||||||
char *comp = mode_get_completion ( pd->switchers[i].mode, index - pd->starts[i] );
|
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 );
|
char *mcomp =
|
||||||
g_free ( comp );
|
g_strdup_printf("!%s %s", mode_get_name(pd->switchers[i].mode), comp);
|
||||||
|
g_free(comp);
|
||||||
return mcomp;
|
return mcomp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Should never get here.
|
// Should never get here.
|
||||||
g_assert_not_reached ();
|
g_assert_not_reached();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static cairo_surface_t * combi_get_icon ( const Mode *sw, unsigned int index, int height )
|
static cairo_surface_t *combi_get_icon(const Mode *sw, unsigned int index,
|
||||||
{
|
int height) {
|
||||||
CombiModePrivateData *pd = mode_get_private_data ( sw );
|
CombiModePrivateData *pd = mode_get_private_data(sw);
|
||||||
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
|
for (unsigned i = 0; i < pd->num_switchers; i++) {
|
||||||
if ( index >= pd->starts[i] && index < ( pd->starts[i] + pd->lengths[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 );
|
cairo_surface_t *icon =
|
||||||
|
mode_get_icon(pd->switchers[i].mode, index - pd->starts[i], height);
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char * combi_preprocess_input ( Mode *sw, const char *input )
|
static char *combi_preprocess_input(Mode *sw, const char *input) {
|
||||||
{
|
CombiModePrivateData *pd = mode_get_private_data(sw);
|
||||||
CombiModePrivateData *pd = mode_get_private_data ( sw );
|
for (unsigned i = 0; i < pd->num_switchers; i++) {
|
||||||
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
|
|
||||||
pd->switchers[i].disable = FALSE;
|
pd->switchers[i].disable = FALSE;
|
||||||
}
|
}
|
||||||
if ( input != NULL && input[0] == '!' ) {
|
if (input != NULL && input[0] == '!') {
|
||||||
// Implement strchrnul behaviour.
|
// Implement strchrnul behaviour.
|
||||||
const char *eob = g_utf8_strchr ( input, -1, ' ' );
|
const char *eob = g_utf8_strchr(input, -1, ' ');
|
||||||
if ( eob == NULL ) {
|
if (eob == NULL) {
|
||||||
// Set it to end.
|
// Set it to end.
|
||||||
eob = &( input[strlen ( input )] );
|
eob = &(input[strlen(input)]);
|
||||||
}
|
}
|
||||||
ssize_t bang_len = g_utf8_pointer_to_offset ( input, eob ) - 1;
|
ssize_t bang_len = g_utf8_pointer_to_offset(input, eob) - 1;
|
||||||
if ( bang_len > 0 ) {
|
if (bang_len > 0) {
|
||||||
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
|
for (unsigned i = 0; i < pd->num_switchers; i++) {
|
||||||
const char *mode_name = mode_get_name ( pd->switchers[i].mode );
|
const char *mode_name = mode_get_name(pd->switchers[i].mode);
|
||||||
size_t mode_name_len = g_utf8_strlen ( mode_name, -1 );
|
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 ) ) {
|
if (!((size_t)bang_len <= mode_name_len &&
|
||||||
|
utf8_strncmp(&input[1], mode_name, bang_len) == 0)) {
|
||||||
// No match.
|
// No match.
|
||||||
pd->switchers[i].disable = TRUE;
|
pd->switchers[i].disable = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( eob[0] == '\0' || eob[1] == '\0' ) {
|
if (eob[0] == '\0' || eob[1] == '\0') {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return g_strdup ( eob + 1 );
|
return g_strdup(eob + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return g_strdup ( input );
|
return g_strdup(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mode combi_mode =
|
Mode combi_mode = {.name = "combi",
|
||||||
{
|
|
||||||
.name = "combi",
|
|
||||||
.cfg_name_key = "display-combi",
|
.cfg_name_key = "display-combi",
|
||||||
._init = combi_mode_init,
|
._init = combi_mode_init,
|
||||||
._get_num_entries = combi_mode_get_num_entries,
|
._get_num_entries = combi_mode_get_num_entries,
|
||||||
@@ -315,5 +318,4 @@ Mode combi_mode =
|
|||||||
._get_icon = combi_get_icon,
|
._get_icon = combi_get_icon,
|
||||||
._preprocess_input = combi_preprocess_input,
|
._preprocess_input = combi_preprocess_input,
|
||||||
.private_data = 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
@@ -23,25 +23,25 @@
|
|||||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* 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 <errno.h>
|
||||||
#include <gmodule.h>
|
|
||||||
#include <gio/gio.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 <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 "dialogs/filebrowser.h"
|
||||||
#include "rofi.h"
|
#include "helper.h"
|
||||||
#include "history.h"
|
#include "history.h"
|
||||||
|
#include "mode-private.h"
|
||||||
|
#include "mode.h"
|
||||||
|
#include "rofi.h"
|
||||||
|
#include "theme.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
@@ -52,8 +52,7 @@
|
|||||||
/**
|
/**
|
||||||
* The internal data structure holding the private data of the TEST Mode.
|
* The internal data structure holding the private data of the TEST Mode.
|
||||||
*/
|
*/
|
||||||
enum FBFileType
|
enum FBFileType {
|
||||||
{
|
|
||||||
UP,
|
UP,
|
||||||
DIRECTORY,
|
DIRECTORY,
|
||||||
RFILE,
|
RFILE,
|
||||||
@@ -63,8 +62,7 @@ enum FBFileType
|
|||||||
/**
|
/**
|
||||||
* Possible sorting methods
|
* Possible sorting methods
|
||||||
*/
|
*/
|
||||||
enum FBSortingMethod
|
enum FBSortingMethod {
|
||||||
{
|
|
||||||
FB_SORT_NAME,
|
FB_SORT_NAME,
|
||||||
FB_SORT_TIME,
|
FB_SORT_TIME,
|
||||||
};
|
};
|
||||||
@@ -72,22 +70,15 @@ enum FBSortingMethod
|
|||||||
/**
|
/**
|
||||||
* Type of time to sort by
|
* Type of time to sort by
|
||||||
*/
|
*/
|
||||||
enum FBSortingTime
|
enum FBSortingTime {
|
||||||
{
|
|
||||||
FB_MTIME,
|
FB_MTIME,
|
||||||
FB_ATIME,
|
FB_ATIME,
|
||||||
FB_CTIME,
|
FB_CTIME,
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Icons to use for the file type */
|
/** Icons to use for the file type */
|
||||||
const char *icon_name[NUM_FILE_TYPES] =
|
const char *icon_name[NUM_FILE_TYPES] = {"go-up", "folder", "gtk-file"};
|
||||||
{
|
typedef struct {
|
||||||
"go-up",
|
|
||||||
"folder",
|
|
||||||
"gtk-file"
|
|
||||||
};
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
char *name;
|
char *name;
|
||||||
char *path;
|
char *path;
|
||||||
enum FBFileType type;
|
enum FBFileType type;
|
||||||
@@ -96,15 +87,13 @@ typedef struct
|
|||||||
time_t time;
|
time_t time;
|
||||||
} FBFile;
|
} FBFile;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
GFile *current_dir;
|
GFile *current_dir;
|
||||||
FBFile *array;
|
FBFile *array;
|
||||||
unsigned int array_length;
|
unsigned int array_length;
|
||||||
} FileBrowserModePrivateData;
|
} FileBrowserModePrivateData;
|
||||||
|
|
||||||
struct
|
struct {
|
||||||
{
|
|
||||||
enum FBSortingMethod sorting_method;
|
enum FBSortingMethod sorting_method;
|
||||||
enum FBSortingTime sorting_time;
|
enum FBSortingTime sorting_time;
|
||||||
gboolean directories_first;
|
gboolean directories_first;
|
||||||
@@ -114,58 +103,55 @@ struct
|
|||||||
.directories_first = TRUE,
|
.directories_first = TRUE,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void free_list ( FileBrowserModePrivateData *pd )
|
static void free_list(FileBrowserModePrivateData *pd) {
|
||||||
{
|
for (unsigned int i = 0; i < pd->array_length; i++) {
|
||||||
for ( unsigned int i = 0; i < pd->array_length; i++ ) {
|
FBFile *fb = &(pd->array[i]);
|
||||||
FBFile *fb = &( pd->array[i] );
|
g_free(fb->name);
|
||||||
g_free ( fb->name );
|
g_free(fb->path);
|
||||||
g_free ( fb->path );
|
|
||||||
}
|
}
|
||||||
g_free ( pd->array );
|
g_free(pd->array);
|
||||||
pd->array = NULL;
|
pd->array = NULL;
|
||||||
pd->array_length = 0;
|
pd->array_length = 0;
|
||||||
}
|
}
|
||||||
#include <sys/types.h>
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
static gint compare_name ( gconstpointer a, gconstpointer b, G_GNUC_UNUSED gpointer data )
|
static gint compare_name(gconstpointer a, gconstpointer b,
|
||||||
{
|
G_GNUC_UNUSED gpointer data) {
|
||||||
FBFile *fa = (FBFile *) a;
|
FBFile *fa = (FBFile *)a;
|
||||||
FBFile *fb = (FBFile *) b;
|
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 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 )
|
static gint compare_time(gconstpointer a, gconstpointer b,
|
||||||
{
|
G_GNUC_UNUSED gpointer data) {
|
||||||
FBFile *fa = (FBFile *) a;
|
FBFile *fa = (FBFile *)a;
|
||||||
FBFile *fb = (FBFile *) b;
|
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 fa->type - fb->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( fa->time < 0 ) {
|
if (fa->time < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( fb->time < 0 ) {
|
if (fb->time < 0) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fb->time - fa->time;
|
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;
|
GCompareDataFunc comparator = NULL;
|
||||||
|
|
||||||
switch ( file_browser_config.sorting_method )
|
switch (file_browser_config.sorting_method) {
|
||||||
{
|
|
||||||
case FB_SORT_NAME:
|
case FB_SORT_NAME:
|
||||||
comparator = compare_name;
|
comparator = compare_name;
|
||||||
break;
|
break;
|
||||||
@@ -177,13 +163,11 @@ static gint compare ( gconstpointer a, gconstpointer b, gpointer data )
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return comparator ( a, b, data );
|
return comparator(a, b, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static time_t get_time ( const struct stat *statbuf )
|
static time_t get_time(const struct stat *statbuf) {
|
||||||
{
|
switch (file_browser_config.sorting_time) {
|
||||||
switch ( file_browser_config.sorting_time )
|
|
||||||
{
|
|
||||||
case FB_MTIME:
|
case FB_MTIME:
|
||||||
return statbuf->st_mtim.tv_sec;
|
return statbuf->st_mtim.tv_sec;
|
||||||
case FB_ATIME:
|
case FB_ATIME:
|
||||||
@@ -195,38 +179,37 @@ static time_t get_time ( const struct stat *statbuf )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_time ( FBFile *file )
|
static void set_time(FBFile *file) {
|
||||||
{
|
gchar *path = g_filename_from_utf8(file->path, -1, NULL, NULL, NULL);
|
||||||
gchar* path = g_filename_from_utf8 ( file->path, -1, NULL, NULL, NULL );
|
|
||||||
|
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
|
|
||||||
if ( stat ( path, &statbuf ) == 0 ) {
|
if (stat(path, &statbuf) == 0) {
|
||||||
file->time = get_time ( &statbuf );
|
file->time = get_time(&statbuf);
|
||||||
}
|
} else {
|
||||||
else {
|
g_warning("Failed to stat file: %s, %s", path, strerror(errno));
|
||||||
g_warning ( "Failed to stat file: %s, %s", path, strerror ( errno ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free ( path );
|
g_free(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void get_file_browser ( Mode *sw )
|
static void get_file_browser(Mode *sw) {
|
||||||
{
|
FileBrowserModePrivateData *pd =
|
||||||
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
|
(FileBrowserModePrivateData *)mode_get_private_data(sw);
|
||||||
/**
|
/**
|
||||||
* Get the entries to display.
|
* Get the entries to display.
|
||||||
* this gets called on plugin initialization.
|
* this gets called on plugin initialization.
|
||||||
*/
|
*/
|
||||||
char *cdir = g_file_get_path ( pd->current_dir );
|
char *cdir = g_file_get_path(pd->current_dir);
|
||||||
DIR *dir = opendir ( cdir );
|
DIR *dir = opendir(cdir);
|
||||||
if ( dir ) {
|
if (dir) {
|
||||||
struct dirent *rd = NULL;
|
struct dirent *rd = NULL;
|
||||||
while ( ( rd = readdir ( dir ) ) != NULL ) {
|
while ((rd = readdir(dir)) != NULL) {
|
||||||
if ( g_strcmp0 ( rd->d_name, ".." ) == 0 ) {
|
if (g_strcmp0(rd->d_name, "..") == 0) {
|
||||||
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.
|
// 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].path = NULL;
|
||||||
pd->array[pd->array_length].type = UP;
|
pd->array[pd->array_length].type = UP;
|
||||||
pd->array[pd->array_length].icon_fetch_uid = 0;
|
pd->array[pd->array_length].icon_fetch_uid = 0;
|
||||||
@@ -235,12 +218,11 @@ static void get_file_browser ( Mode *sw )
|
|||||||
pd->array_length++;
|
pd->array_length++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if ( rd->d_name[0] == '.' ) {
|
if (rd->d_name[0] == '.') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ( rd->d_type )
|
switch (rd->d_type) {
|
||||||
{
|
|
||||||
case DT_BLK:
|
case DT_BLK:
|
||||||
case DT_CHR:
|
case DT_CHR:
|
||||||
case DT_FIFO:
|
case DT_FIFO:
|
||||||
@@ -250,272 +232,267 @@ static void get_file_browser ( Mode *sw )
|
|||||||
break;
|
break;
|
||||||
case DT_REG:
|
case DT_REG:
|
||||||
case DT_DIR:
|
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.
|
// 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].name =
|
||||||
pd->array[pd->array_length].path = g_build_filename ( cdir, rd->d_name, NULL );
|
g_filename_to_utf8(rd->d_name, -1, NULL, NULL, NULL);
|
||||||
pd->array[pd->array_length].type = ( rd->d_type == DT_DIR ) ? DIRECTORY : RFILE;
|
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].icon_fetch_uid = 0;
|
||||||
pd->array[pd->array_length].link = FALSE;
|
pd->array[pd->array_length].link = FALSE;
|
||||||
|
|
||||||
if ( file_browser_config.sorting_method == FB_SORT_TIME ) {
|
if (file_browser_config.sorting_method == FB_SORT_TIME) {
|
||||||
set_time ( &pd->array[pd->array_length] );
|
set_time(&pd->array[pd->array_length]);
|
||||||
}
|
}
|
||||||
|
|
||||||
pd->array_length++;
|
pd->array_length++;
|
||||||
break;
|
break;
|
||||||
case DT_LNK:
|
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.
|
// 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].name =
|
||||||
pd->array[pd->array_length].path = g_build_filename ( cdir, rd->d_name, NULL );
|
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].icon_fetch_uid = 0;
|
||||||
pd->array[pd->array_length].link = TRUE;
|
pd->array[pd->array_length].link = TRUE;
|
||||||
// Default to file.
|
// Default to file.
|
||||||
pd->array[pd->array_length].type = RFILE;
|
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?
|
// TODO have a 'broken link' mode?
|
||||||
// Convert full path to right encoding.
|
// Convert full path to right encoding.
|
||||||
char *file = g_filename_from_utf8 ( pd->array[pd->array_length].path, -1, NULL, NULL, NULL );
|
char *file = g_filename_from_utf8(pd->array[pd->array_length].path,
|
||||||
if ( file ) {
|
-1, NULL, NULL, NULL);
|
||||||
|
if (file) {
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
if ( stat ( file, &statbuf ) == 0 ) {
|
if (stat(file, &statbuf) == 0) {
|
||||||
if ( S_ISDIR ( statbuf.st_mode ) ) {
|
if (S_ISDIR(statbuf.st_mode)) {
|
||||||
pd->array[pd->array_length].type = DIRECTORY;
|
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;
|
pd->array[pd->array_length].type = RFILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( file_browser_config.sorting_method == FB_SORT_TIME ) {
|
if (file_browser_config.sorting_method == FB_SORT_TIME) {
|
||||||
pd->array[pd->array_length].time = get_time ( &statbuf );
|
pd->array[pd->array_length].time = get_time(&statbuf);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
g_warning("Failed to stat file: %s, %s", file, strerror(errno));
|
||||||
g_warning ( "Failed to stat file: %s, %s", file, strerror ( errno ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free ( file );
|
g_free(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pd->array_length++;
|
pd->array_length++;
|
||||||
break;
|
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;
|
char *msg = NULL;
|
||||||
gboolean found_error = FALSE;
|
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 );
|
Property *p = rofi_theme_find_property(wid, P_STRING, "sorting-method", TRUE);
|
||||||
if ( p != NULL && p->type == P_STRING ) {
|
if (p != NULL && p->type == P_STRING) {
|
||||||
if ( g_strcmp0 ( p->value.s, "name" ) == 0 ) {
|
if (g_strcmp0(p->value.s, "name") == 0) {
|
||||||
file_browser_config.sorting_method = FB_SORT_NAME;
|
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_method = FB_SORT_TIME;
|
||||||
file_browser_config.sorting_time = FB_MTIME;
|
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_method = FB_SORT_TIME;
|
||||||
file_browser_config.sorting_time = FB_ATIME;
|
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_method = FB_SORT_TIME;
|
||||||
file_browser_config.sorting_time = FB_CTIME;
|
file_browser_config.sorting_time = FB_CTIME;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
found_error = TRUE;
|
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 );
|
p = rofi_theme_find_property(wid, P_BOOLEAN, "directories-first", TRUE);
|
||||||
if ( p != NULL && p->type == P_BOOLEAN ) {
|
if (p != NULL && p->type == P_BOOLEAN) {
|
||||||
file_browser_config.directories_first = p->value.b;
|
file_browser_config.directories_first = p->value.b;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( found_error ) {
|
if (found_error) {
|
||||||
rofi_view_error_dialog ( msg, FALSE );
|
rofi_view_error_dialog(msg, FALSE);
|
||||||
|
|
||||||
g_free ( msg );
|
g_free(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void file_browser_mode_init_current_dir ( Mode *sw ) {
|
static void file_browser_mode_init_current_dir(Mode *sw) {
|
||||||
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( 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
|
gboolean config_has_valid_dir = p != NULL && p->type == P_STRING &&
|
||||||
&& g_file_test ( p->value.s, G_FILE_TEST_IS_DIR );
|
g_file_test(p->value.s, G_FILE_TEST_IS_DIR);
|
||||||
|
|
||||||
if ( config_has_valid_dir ) {
|
if (config_has_valid_dir) {
|
||||||
pd->current_dir = g_file_new_for_path ( p->value.s );
|
pd->current_dir = g_file_new_for_path(p->value.s);
|
||||||
} else {
|
} else {
|
||||||
char *current_dir = NULL;
|
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, ¤t_dir, NULL, NULL ) ) {
|
if (g_file_get_contents(cache_file, ¤t_dir, NULL, NULL)) {
|
||||||
if ( g_file_test ( current_dir, G_FILE_TEST_IS_DIR ) ) {
|
if (g_file_test(current_dir, G_FILE_TEST_IS_DIR)) {
|
||||||
pd->current_dir = g_file_new_for_path ( current_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).
|
// Store it based on the unique identifiers (desktop_id).
|
||||||
g_free ( cache_file );
|
g_free(cache_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pd->current_dir == NULL) {
|
||||||
if ( pd->current_dir == NULL ) {
|
pd->current_dir = g_file_new_for_path(g_get_home_dir());
|
||||||
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)
|
* Called on startup when enabled (in modi list)
|
||||||
*/
|
*/
|
||||||
if ( mode_get_private_data ( sw ) == NULL ) {
|
if (mode_get_private_data(sw) == NULL) {
|
||||||
FileBrowserModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
|
FileBrowserModePrivateData *pd = g_malloc0(sizeof(*pd));
|
||||||
mode_set_private_data ( sw, (void *) pd );
|
mode_set_private_data(sw, (void *)pd);
|
||||||
|
|
||||||
file_browser_mode_init_config ( sw );
|
file_browser_mode_init_config(sw);
|
||||||
file_browser_mode_init_current_dir ( sw );
|
file_browser_mode_init_current_dir(sw);
|
||||||
|
|
||||||
// Load content.
|
// Load content.
|
||||||
get_file_browser ( sw );
|
get_file_browser(sw);
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
static unsigned int file_browser_mode_get_num_entries ( const Mode *sw )
|
static unsigned int file_browser_mode_get_num_entries(const Mode *sw) {
|
||||||
{
|
const FileBrowserModePrivateData *pd =
|
||||||
const FileBrowserModePrivateData *pd = (const FileBrowserModePrivateData *) mode_get_private_data ( sw );
|
(const FileBrowserModePrivateData *)mode_get_private_data(sw);
|
||||||
return pd->array_length;
|
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;
|
ModeMode retv = MODE_EXIT;
|
||||||
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
|
FileBrowserModePrivateData *pd =
|
||||||
if ( mretv & MENU_NEXT ) {
|
(FileBrowserModePrivateData *)mode_get_private_data(sw);
|
||||||
|
if (mretv & MENU_NEXT) {
|
||||||
retv = NEXT_DIALOG;
|
retv = NEXT_DIALOG;
|
||||||
}
|
} else if (mretv & MENU_PREVIOUS) {
|
||||||
else if ( mretv & MENU_PREVIOUS ) {
|
|
||||||
retv = PREVIOUS_DIALOG;
|
retv = PREVIOUS_DIALOG;
|
||||||
}
|
} else if (mretv & MENU_QUICK_SWITCH) {
|
||||||
else if ( mretv & MENU_QUICK_SWITCH ) {
|
retv = (mretv & MENU_LOWER_MASK);
|
||||||
retv = ( mretv & MENU_LOWER_MASK );
|
} else if (mretv & MENU_CUSTOM_COMMAND) {
|
||||||
}
|
retv = (mretv & MENU_LOWER_MASK);
|
||||||
else if ( mretv & MENU_CUSTOM_COMMAND ) {
|
} else if ((mretv & MENU_OK)) {
|
||||||
retv = ( mretv & MENU_LOWER_MASK );
|
if (selected_line < pd->array_length) {
|
||||||
}
|
if (pd->array[selected_line].type == UP) {
|
||||||
else if ( ( mretv & MENU_OK ) ) {
|
GFile *new = g_file_get_parent(pd->current_dir);
|
||||||
if ( selected_line < pd->array_length ) {
|
if (new) {
|
||||||
if ( pd->array[selected_line].type == UP ) {
|
g_object_unref(pd->current_dir);
|
||||||
GFile *new = g_file_get_parent ( pd->current_dir );
|
|
||||||
if ( new ) {
|
|
||||||
g_object_unref ( pd->current_dir );
|
|
||||||
pd->current_dir = new;
|
pd->current_dir = new;
|
||||||
free_list ( pd );
|
free_list(pd);
|
||||||
get_file_browser ( sw );
|
get_file_browser(sw);
|
||||||
return RESET_DIALOG;
|
return RESET_DIALOG;
|
||||||
}
|
}
|
||||||
}
|
} else if (pd->array[selected_line].type == DIRECTORY) {
|
||||||
else if ( pd->array[selected_line].type == DIRECTORY ) {
|
char *path = g_build_filename(cache_dir, FILEBROWSER_CACHE_FILE, NULL);
|
||||||
char *path = g_build_filename ( cache_dir, FILEBROWSER_CACHE_FILE, NULL );
|
g_file_set_contents(path, pd->array[selected_line].path, -1, NULL);
|
||||||
g_file_set_contents ( path, pd->array[selected_line].path, -1, NULL );
|
g_free(path);
|
||||||
g_free ( path );
|
GFile *new = g_file_new_for_path(pd->array[selected_line].path);
|
||||||
GFile *new = g_file_new_for_path ( pd->array[selected_line].path );
|
g_object_unref(pd->current_dir);
|
||||||
g_object_unref ( pd->current_dir );
|
|
||||||
pd->current_dir = new;
|
pd->current_dir = new;
|
||||||
free_list ( pd );
|
free_list(pd);
|
||||||
get_file_browser ( sw );
|
get_file_browser(sw);
|
||||||
return RESET_DIALOG;
|
return RESET_DIALOG;
|
||||||
}
|
} else if (pd->array[selected_line].type == RFILE) {
|
||||||
else if ( pd->array[selected_line].type == RFILE ) {
|
char *d = g_filename_from_utf8(pd->array[selected_line].path, -1, NULL,
|
||||||
char *d = g_filename_from_utf8 ( pd->array[selected_line].path, -1, NULL, NULL, NULL );
|
NULL, NULL);
|
||||||
char *d_esc = g_shell_quote ( d );
|
char *d_esc = g_shell_quote(d);
|
||||||
char *cmd = g_strdup_printf ( "xdg-open %s", d_esc );
|
char *cmd = g_strdup_printf("xdg-open %s", d_esc);
|
||||||
g_free ( d_esc );
|
g_free(d_esc);
|
||||||
g_free ( d );
|
g_free(d);
|
||||||
char *cdir = g_file_get_path ( pd->current_dir );
|
char *cdir = g_file_get_path(pd->current_dir);
|
||||||
helper_execute_command ( cdir, cmd, FALSE, NULL );
|
helper_execute_command(cdir, cmd, FALSE, NULL);
|
||||||
g_free ( cdir );
|
g_free(cdir);
|
||||||
g_free ( cmd );
|
g_free(cmd);
|
||||||
return MODE_EXIT;
|
return MODE_EXIT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
retv = RELOAD_DIALOG;
|
retv = RELOAD_DIALOG;
|
||||||
}
|
} else if ((mretv & MENU_CUSTOM_INPUT) && *input) {
|
||||||
else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input ) {
|
char *p = rofi_expand_path(*input);
|
||||||
char *p = rofi_expand_path ( *input );
|
char *dir = g_filename_from_utf8(p, -1, NULL, NULL, NULL);
|
||||||
char *dir = g_filename_from_utf8 ( p, -1, NULL, NULL, NULL );
|
g_free(p);
|
||||||
g_free ( p );
|
if (g_file_test(dir, G_FILE_TEST_EXISTS)) {
|
||||||
if ( g_file_test ( dir, G_FILE_TEST_EXISTS ) ) {
|
if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
|
||||||
if ( g_file_test ( dir, G_FILE_TEST_IS_DIR ) ) {
|
g_object_unref(pd->current_dir);
|
||||||
g_object_unref ( pd->current_dir );
|
pd->current_dir = g_file_new_for_path(dir);
|
||||||
pd->current_dir = g_file_new_for_path ( dir );
|
g_free(dir);
|
||||||
g_free ( dir );
|
free_list(pd);
|
||||||
free_list ( pd );
|
get_file_browser(sw);
|
||||||
get_file_browser ( sw );
|
|
||||||
return RESET_DIALOG;
|
return RESET_DIALOG;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_free ( dir );
|
g_free(dir);
|
||||||
retv = RELOAD_DIALOG;
|
retv = RELOAD_DIALOG;
|
||||||
}
|
} else if ((mretv & MENU_ENTRY_DELETE) == MENU_ENTRY_DELETE) {
|
||||||
else if ( ( mretv & MENU_ENTRY_DELETE ) == MENU_ENTRY_DELETE ) {
|
|
||||||
retv = RELOAD_DIALOG;
|
retv = RELOAD_DIALOG;
|
||||||
}
|
}
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void file_browser_mode_destroy ( Mode *sw )
|
static void file_browser_mode_destroy(Mode *sw) {
|
||||||
{
|
FileBrowserModePrivateData *pd =
|
||||||
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
|
(FileBrowserModePrivateData *)mode_get_private_data(sw);
|
||||||
if ( pd != NULL ) {
|
if (pd != NULL) {
|
||||||
g_object_unref ( pd->current_dir );
|
g_object_unref(pd->current_dir);
|
||||||
free_list ( pd );
|
free_list(pd);
|
||||||
g_free ( pd );
|
g_free(pd);
|
||||||
mode_set_private_data ( sw, NULL );
|
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 )
|
static char *_get_display_value(const Mode *sw, unsigned int selected_line,
|
||||||
{
|
G_GNUC_UNUSED int *state,
|
||||||
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
|
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.
|
// Only return the string if requested, otherwise only set state.
|
||||||
if ( !get_entry ) {
|
if (!get_entry) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if ( pd->array[selected_line].type == UP ) {
|
if (pd->array[selected_line].type == UP) {
|
||||||
return g_strdup ( " .." );
|
return g_strdup(" ..");
|
||||||
}
|
}
|
||||||
else {
|
if (pd->array[selected_line].link) {
|
||||||
if ( pd->array[selected_line].link ) {
|
return g_strconcat("@", pd->array[selected_line].name, NULL);
|
||||||
return g_strconcat ( "@", pd->array[selected_line].name, NULL );
|
|
||||||
}
|
}
|
||||||
else {
|
return g_strdup(pd->array[selected_line].name);
|
||||||
return g_strdup ( pd->array[selected_line].name );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return g_strdup ( "n/a" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -527,54 +504,55 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_
|
|||||||
*
|
*
|
||||||
* @returns try when a match.
|
* @returns try when a match.
|
||||||
*/
|
*/
|
||||||
static int file_browser_token_match ( const Mode *sw, rofi_int_matcher **tokens, unsigned int index )
|
static int file_browser_token_match(const Mode *sw, rofi_int_matcher **tokens,
|
||||||
{
|
unsigned int index) {
|
||||||
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
|
FileBrowserModePrivateData *pd =
|
||||||
|
(FileBrowserModePrivateData *)mode_get_private_data(sw);
|
||||||
|
|
||||||
// Call default matching function.
|
// 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 )
|
static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line,
|
||||||
{
|
int height) {
|
||||||
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
|
FileBrowserModePrivateData *pd =
|
||||||
g_return_val_if_fail ( pd->array != NULL, NULL );
|
(FileBrowserModePrivateData *)mode_get_private_data(sw);
|
||||||
FBFile *dr = &( pd->array[selected_line] );
|
g_return_val_if_fail(pd->array != NULL, NULL);
|
||||||
if ( dr->icon_fetch_uid > 0 ) {
|
FBFile *dr = &(pd->array[selected_line]);
|
||||||
return rofi_icon_fetcher_get ( dr->icon_fetch_uid );
|
if (dr->icon_fetch_uid > 0) {
|
||||||
|
return rofi_icon_fetcher_get(dr->icon_fetch_uid);
|
||||||
}
|
}
|
||||||
if ( rofi_icon_fetcher_file_is_image ( dr->path ) ) {
|
if (rofi_icon_fetcher_file_is_image(dr->path)) {
|
||||||
dr->icon_fetch_uid = rofi_icon_fetcher_query ( dr->path, height );
|
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 {
|
return rofi_icon_fetcher_get(dr->icon_fetch_uid);
|
||||||
dr->icon_fetch_uid = rofi_icon_fetcher_query ( icon_name[dr->type], height );
|
|
||||||
}
|
|
||||||
return rofi_icon_fetcher_get ( dr->icon_fetch_uid );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static char * _get_message ( const Mode *sw )
|
static char *_get_message(const Mode *sw) {
|
||||||
{
|
FileBrowserModePrivateData *pd =
|
||||||
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
|
(FileBrowserModePrivateData *)mode_get_private_data(sw);
|
||||||
if ( pd->current_dir ) {
|
if (pd->current_dir) {
|
||||||
char *dirname = g_file_get_parse_name ( 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 );
|
char *str =
|
||||||
g_free ( dirname );
|
g_markup_printf_escaped("<b>Current directory:</b> %s", dirname);
|
||||||
|
g_free(dirname);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
return "n/a";
|
return "n/a";
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *_get_completion ( const Mode *sw, unsigned int index )
|
static char *_get_completion(const Mode *sw, unsigned int index) {
|
||||||
{
|
FileBrowserModePrivateData *pd =
|
||||||
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
|
(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;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mode *create_new_file_browser ( void )
|
Mode *create_new_file_browser(void) {
|
||||||
{
|
Mode *sw = g_malloc0(sizeof(Mode));
|
||||||
Mode *sw = g_malloc0 ( sizeof ( Mode ) );
|
|
||||||
|
|
||||||
*sw = file_browser_mode;
|
*sw = file_browser_mode;
|
||||||
|
|
||||||
@@ -583,72 +561,65 @@ Mode *create_new_file_browser ( void )
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if 1
|
#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;
|
ModeMode retv = MODE_EXIT;
|
||||||
FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
|
FileBrowserModePrivateData *pd =
|
||||||
if ( mretv & MENU_NEXT ) {
|
(FileBrowserModePrivateData *)mode_get_private_data(sw);
|
||||||
|
if (mretv & MENU_NEXT) {
|
||||||
retv = NEXT_DIALOG;
|
retv = NEXT_DIALOG;
|
||||||
}
|
} else if (mretv & MENU_PREVIOUS) {
|
||||||
else if ( mretv & MENU_PREVIOUS ) {
|
|
||||||
retv = PREVIOUS_DIALOG;
|
retv = PREVIOUS_DIALOG;
|
||||||
}
|
} else if (mretv & MENU_QUICK_SWITCH) {
|
||||||
else if ( mretv & MENU_QUICK_SWITCH ) {
|
retv = (mretv & MENU_LOWER_MASK);
|
||||||
retv = ( mretv & MENU_LOWER_MASK );
|
} else if ((mretv & MENU_OK)) {
|
||||||
}
|
if (selected_line < pd->array_length) {
|
||||||
else if ( ( mretv & MENU_OK ) ) {
|
if (pd->array[selected_line].type == UP) {
|
||||||
if ( selected_line < pd->array_length ) {
|
GFile *new = g_file_get_parent(pd->current_dir);
|
||||||
if ( pd->array[selected_line].type == UP ) {
|
if (new) {
|
||||||
GFile *new = g_file_get_parent ( pd->current_dir );
|
g_object_unref(pd->current_dir);
|
||||||
if ( new ) {
|
|
||||||
g_object_unref ( pd->current_dir );
|
|
||||||
pd->current_dir = new;
|
pd->current_dir = new;
|
||||||
free_list ( pd );
|
free_list(pd);
|
||||||
get_file_browser ( sw );
|
get_file_browser(sw);
|
||||||
return RESET_DIALOG;
|
return RESET_DIALOG;
|
||||||
}
|
}
|
||||||
}
|
} else if (pd->array[selected_line].type == DIRECTORY) {
|
||||||
else if ( pd->array[selected_line].type == DIRECTORY ) {
|
GFile *new = g_file_new_for_path(pd->array[selected_line].path);
|
||||||
GFile *new = g_file_new_for_path ( pd->array[selected_line].path );
|
g_object_unref(pd->current_dir);
|
||||||
g_object_unref ( pd->current_dir );
|
|
||||||
pd->current_dir = new;
|
pd->current_dir = new;
|
||||||
free_list ( pd );
|
free_list(pd);
|
||||||
get_file_browser ( sw );
|
get_file_browser(sw);
|
||||||
return RESET_DIALOG;
|
return RESET_DIALOG;
|
||||||
}
|
} else if (pd->array[selected_line].type == RFILE) {
|
||||||
else if ( pd->array[selected_line].type == RFILE ) {
|
*path = g_strescape(pd->array[selected_line].path, NULL);
|
||||||
*path = g_strescape ( pd->array[selected_line].path, NULL );
|
|
||||||
return MODE_EXIT;
|
return MODE_EXIT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
retv = RELOAD_DIALOG;
|
retv = RELOAD_DIALOG;
|
||||||
}
|
} else if ((mretv & MENU_CUSTOM_INPUT) && *input) {
|
||||||
else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input ) {
|
char *p = rofi_expand_path(*input);
|
||||||
char *p = rofi_expand_path ( *input );
|
char *dir = g_filename_from_utf8(p, -1, NULL, NULL, NULL);
|
||||||
char *dir = g_filename_from_utf8 ( p, -1, NULL, NULL, NULL );
|
g_free(p);
|
||||||
g_free ( p );
|
if (g_file_test(dir, G_FILE_TEST_EXISTS)) {
|
||||||
if ( g_file_test ( dir, G_FILE_TEST_EXISTS ) ) {
|
if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
|
||||||
if ( g_file_test ( dir, G_FILE_TEST_IS_DIR ) ) {
|
g_object_unref(pd->current_dir);
|
||||||
g_object_unref ( pd->current_dir );
|
pd->current_dir = g_file_new_for_path(dir);
|
||||||
pd->current_dir = g_file_new_for_path ( dir );
|
g_free(dir);
|
||||||
g_free ( dir );
|
free_list(pd);
|
||||||
free_list ( pd );
|
get_file_browser(sw);
|
||||||
get_file_browser ( sw );
|
|
||||||
return RESET_DIALOG;
|
return RESET_DIALOG;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_free ( dir );
|
g_free(dir);
|
||||||
retv = RELOAD_DIALOG;
|
retv = RELOAD_DIALOG;
|
||||||
}
|
} else if ((mretv & MENU_ENTRY_DELETE) == MENU_ENTRY_DELETE) {
|
||||||
else if ( ( mretv & MENU_ENTRY_DELETE ) == MENU_ENTRY_DELETE ) {
|
|
||||||
retv = RELOAD_DIALOG;
|
retv = RELOAD_DIALOG;
|
||||||
}
|
}
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Mode file_browser_mode =
|
Mode file_browser_mode = {
|
||||||
{
|
|
||||||
.display_name = NULL,
|
.display_name = NULL,
|
||||||
.abi_version = ABI_VERSION,
|
.abi_version = ABI_VERSION,
|
||||||
.name = "filebrowser",
|
.name = "filebrowser",
|
||||||
|
@@ -26,95 +26,89 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <dirent.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <strings.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <strings.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "dialogs/help-keys.h"
|
||||||
|
#include "helper.h"
|
||||||
#include "rofi.h"
|
#include "rofi.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "helper.h"
|
|
||||||
#include "xrmoptions.h"
|
|
||||||
#include "dialogs/help-keys.h"
|
|
||||||
#include "widgets/textbox.h"
|
#include "widgets/textbox.h"
|
||||||
|
#include "xrmoptions.h"
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
char **messages;
|
char **messages;
|
||||||
unsigned int messages_length;
|
unsigned int messages_length;
|
||||||
} KeysHelpModePrivateData;
|
} KeysHelpModePrivateData;
|
||||||
|
|
||||||
static void get_apps ( KeysHelpModePrivateData *pd )
|
static void get_apps(KeysHelpModePrivateData *pd) {
|
||||||
{
|
pd->messages = config_parser_return_display_help(&(pd->messages_length));
|
||||||
pd->messages = config_parser_return_display_help ( &( pd->messages_length ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int help_keys_mode_init ( Mode *sw )
|
static int help_keys_mode_init(Mode *sw) {
|
||||||
{
|
if (mode_get_private_data(sw) == NULL) {
|
||||||
if ( mode_get_private_data ( sw ) == NULL ) {
|
KeysHelpModePrivateData *pd = g_malloc0(sizeof(*pd));
|
||||||
KeysHelpModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
|
mode_set_private_data(sw, (void *)pd);
|
||||||
mode_set_private_data ( sw, (void *) pd );
|
get_apps(pd);
|
||||||
get_apps ( pd );
|
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ModeMode help_keys_mode_result ( G_GNUC_UNUSED Mode *sw,
|
static ModeMode
|
||||||
int mretv,
|
help_keys_mode_result(G_GNUC_UNUSED Mode *sw, int mretv,
|
||||||
G_GNUC_UNUSED char **input,
|
G_GNUC_UNUSED char **input,
|
||||||
G_GNUC_UNUSED unsigned int selected_line )
|
G_GNUC_UNUSED unsigned int selected_line) {
|
||||||
{
|
if (mretv & MENU_CUSTOM_COMMAND) {
|
||||||
if ( mretv & MENU_CUSTOM_COMMAND ) {
|
int retv = (mretv & MENU_LOWER_MASK);
|
||||||
int retv = ( mretv & MENU_LOWER_MASK );
|
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
return MODE_EXIT;
|
return MODE_EXIT;
|
||||||
}
|
}
|
||||||
static void help_keys_mode_destroy ( Mode *sw )
|
static void help_keys_mode_destroy(Mode *sw) {
|
||||||
{
|
KeysHelpModePrivateData *rmpd =
|
||||||
KeysHelpModePrivateData *rmpd = (KeysHelpModePrivateData *) mode_get_private_data ( sw );
|
(KeysHelpModePrivateData *)mode_get_private_data(sw);
|
||||||
if ( rmpd != NULL ) {
|
if (rmpd != NULL) {
|
||||||
g_strfreev ( rmpd->messages );
|
g_strfreev(rmpd->messages);
|
||||||
g_free ( rmpd );
|
g_free(rmpd);
|
||||||
mode_set_private_data ( sw, NULL );
|
mode_set_private_data(sw, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *_get_display_value ( const Mode *sw, unsigned int selected_line, int *state, G_GNUC_UNUSED GList **list, int get_entry )
|
static char *_get_display_value(const Mode *sw, unsigned int selected_line,
|
||||||
{
|
int *state, G_GNUC_UNUSED GList **list,
|
||||||
KeysHelpModePrivateData *pd = (KeysHelpModePrivateData *) mode_get_private_data ( sw );
|
int get_entry) {
|
||||||
|
KeysHelpModePrivateData *pd =
|
||||||
|
(KeysHelpModePrivateData *)mode_get_private_data(sw);
|
||||||
*state |= MARKUP;
|
*state |= MARKUP;
|
||||||
if ( !get_entry ) {
|
if (!get_entry) {
|
||||||
return NULL;
|
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,
|
static int help_keys_token_match(const Mode *data, rofi_int_matcher **tokens,
|
||||||
rofi_int_matcher **tokens,
|
unsigned int index) {
|
||||||
unsigned int index
|
KeysHelpModePrivateData *rmpd =
|
||||||
)
|
(KeysHelpModePrivateData *)mode_get_private_data(data);
|
||||||
{
|
return helper_token_match(tokens, rmpd->messages[index]);
|
||||||
KeysHelpModePrivateData *rmpd = (KeysHelpModePrivateData *) mode_get_private_data ( data );
|
|
||||||
return helper_token_match ( tokens, rmpd->messages[index] );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int help_keys_mode_get_num_entries ( const Mode *sw )
|
static unsigned int help_keys_mode_get_num_entries(const Mode *sw) {
|
||||||
{
|
const KeysHelpModePrivateData *pd =
|
||||||
const KeysHelpModePrivateData *pd = (const KeysHelpModePrivateData *) mode_get_private_data ( sw );
|
(const KeysHelpModePrivateData *)mode_get_private_data(sw);
|
||||||
return pd->messages_length;
|
return pd->messages_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "mode-private.h"
|
#include "mode-private.h"
|
||||||
Mode help_keys_mode =
|
Mode help_keys_mode = {.name = "keys",
|
||||||
{
|
|
||||||
.name = "keys",
|
|
||||||
.cfg_name_key = "display-keys",
|
.cfg_name_key = "display-keys",
|
||||||
._init = help_keys_mode_init,
|
._init = help_keys_mode_init,
|
||||||
._get_num_entries = help_keys_mode_get_num_entries,
|
._get_num_entries = help_keys_mode_get_num_entries,
|
||||||
@@ -124,5 +118,4 @@ Mode help_keys_mode =
|
|||||||
._get_completion = NULL,
|
._get_completion = NULL,
|
||||||
._get_display_value = _get_display_value,
|
._get_display_value = _get_display_value,
|
||||||
.private_data = NULL,
|
.private_data = NULL,
|
||||||
.free = NULL
|
.free = NULL};
|
||||||
};
|
|
||||||
|
@@ -34,36 +34,35 @@
|
|||||||
#define G_LOG_DOMAIN "Dialogs.Run"
|
#define G_LOG_DOMAIN "Dialogs.Run"
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <dirent.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <strings.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <strings.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "rofi.h"
|
#include "dialogs/filebrowser.h"
|
||||||
#include "settings.h"
|
#include "dialogs/run.h"
|
||||||
#include "helper.h"
|
#include "helper.h"
|
||||||
#include "history.h"
|
#include "history.h"
|
||||||
#include "dialogs/run.h"
|
#include "rofi.h"
|
||||||
#include "dialogs/filebrowser.h"
|
#include "settings.h"
|
||||||
|
|
||||||
#include "mode-private.h"
|
#include "mode-private.h"
|
||||||
|
|
||||||
#include "timings.h"
|
|
||||||
#include "rofi-icon-fetcher.h"
|
#include "rofi-icon-fetcher.h"
|
||||||
|
#include "timings.h"
|
||||||
/**
|
/**
|
||||||
* Name of the history file where previously chosen commands are stored.
|
* Name of the history file where previously chosen commands are stored.
|
||||||
*/
|
*/
|
||||||
#define RUN_CACHE_FILE "rofi-3.runcache"
|
#define RUN_CACHE_FILE "rofi-3.runcache"
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
char *entry;
|
char *entry;
|
||||||
uint32_t icon_fetch_uid;
|
uint32_t icon_fetch_uid;
|
||||||
/* Surface holding the icon. */
|
/* Surface holding the icon. */
|
||||||
@@ -73,8 +72,7 @@ typedef struct
|
|||||||
/**
|
/**
|
||||||
* The internal data structure holding the private data of the Run Mode.
|
* The internal data structure holding the private data of the Run Mode.
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
/** list of available commands. */
|
/** list of available commands. */
|
||||||
RunEntry *cmd_list;
|
RunEntry *cmd_list;
|
||||||
/** Length of the #cmd_list. */
|
/** Length of the #cmd_list. */
|
||||||
@@ -98,40 +96,39 @@ typedef struct
|
|||||||
*
|
*
|
||||||
* Execute command and add to history.
|
* 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;
|
GError *error = NULL;
|
||||||
if ( !cmd || !cmd[0] ) {
|
if (!cmd || !cmd[0]) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
gsize lf_cmd_size = 0;
|
gsize lf_cmd_size = 0;
|
||||||
gchar *lf_cmd = g_locale_from_utf8 ( cmd, -1, NULL, &lf_cmd_size, &error );
|
gchar *lf_cmd = g_locale_from_utf8(cmd, -1, NULL, &lf_cmd_size, &error);
|
||||||
if ( error != NULL ) {
|
if (error != NULL) {
|
||||||
g_warning ( "Failed to convert command to locale encoding: %s", error->message );
|
g_warning("Failed to convert command to locale encoding: %s",
|
||||||
g_error_free ( error );
|
error->message);
|
||||||
|
g_error_free(error);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *path = g_build_filename ( cache_dir, RUN_CACHE_FILE, NULL );
|
char *path = g_build_filename(cache_dir, RUN_CACHE_FILE, NULL);
|
||||||
RofiHelperExecuteContext context = { .name = NULL };
|
RofiHelperExecuteContext context = {.name = NULL};
|
||||||
// FIXME: assume startup notification support for terminals
|
// 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)
|
* This happens in non-critical time (After launching app)
|
||||||
* It is allowed to be a bit slower.
|
* It is allowed to be a bit slower.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
history_set ( path, cmd );
|
history_set(path, cmd);
|
||||||
g_free ( path );
|
g_free(path);
|
||||||
g_free ( lf_cmd );
|
g_free(lf_cmd);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
else {
|
history_remove(path, cmd);
|
||||||
history_remove ( path, cmd );
|
g_free(path);
|
||||||
g_free ( path );
|
g_free(lf_cmd);
|
||||||
g_free ( lf_cmd );
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -139,13 +136,12 @@ static gboolean exec_cmd ( const char *cmd, int run_in_term )
|
|||||||
*
|
*
|
||||||
* Remove command from history.
|
* Remove command from history.
|
||||||
*/
|
*/
|
||||||
static void delete_entry ( const RunEntry *cmd )
|
static void delete_entry(const RunEntry *cmd) {
|
||||||
{
|
char *path = g_build_filename(cache_dir, RUN_CACHE_FILE, NULL);
|
||||||
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.
|
* 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 )
|
static int sort_func(const void *a, const void *b, G_GNUC_UNUSED void *data) {
|
||||||
{
|
const RunEntry *astr = (const RunEntry *)a;
|
||||||
const RunEntry *astr = ( const RunEntry * ) a;
|
const RunEntry *bstr = (const RunEntry *)b;
|
||||||
const RunEntry *bstr = ( const RunEntry * ) b;
|
|
||||||
|
|
||||||
if ( astr->entry == NULL && bstr->entry == NULL ) {
|
if (astr->entry == NULL && bstr->entry == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if ( astr->entry == NULL ) {
|
if (astr->entry == NULL) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if ( bstr->entry == NULL ) {
|
if (bstr->entry == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return g_strcmp0 ( astr->entry , bstr->entry );
|
return g_strcmp0(astr->entry, bstr->entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* External spider to get list of executables.
|
* External spider to get list of executables.
|
||||||
*/
|
*/
|
||||||
static RunEntry * get_apps_external ( RunEntry *retv, unsigned int *length, unsigned int num_favorites )
|
static RunEntry *get_apps_external(RunEntry *retv, unsigned int *length,
|
||||||
{
|
unsigned int num_favorites) {
|
||||||
int fd = execute_generator ( config.run_list_command );
|
int fd = execute_generator(config.run_list_command);
|
||||||
if ( fd >= 0 ) {
|
if (fd >= 0) {
|
||||||
FILE *inp = fdopen ( fd, "r" );
|
FILE *inp = fdopen(fd, "r");
|
||||||
if ( inp ) {
|
if (inp) {
|
||||||
char *buffer = NULL;
|
char *buffer = NULL;
|
||||||
size_t buffer_length = 0;
|
size_t buffer_length = 0;
|
||||||
|
|
||||||
while ( getline ( &buffer, &buffer_length, inp ) > 0 ) {
|
while (getline(&buffer, &buffer_length, inp) > 0) {
|
||||||
int found = 0;
|
int found = 0;
|
||||||
// Filter out line-end.
|
// Filter out line-end.
|
||||||
if ( buffer[strlen ( buffer ) - 1] == '\n' ) {
|
if (buffer[strlen(buffer) - 1] == '\n') {
|
||||||
buffer[strlen ( buffer ) - 1] = '\0';
|
buffer[strlen(buffer) - 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is a nice little penalty, but doable? time will tell.
|
// This is a nice little penalty, but doable? time will tell.
|
||||||
// given num_favorites is max 25.
|
// given num_favorites is max 25.
|
||||||
for ( unsigned int j = 0; found == 0 && j < num_favorites; j++ ) {
|
for (unsigned int j = 0; found == 0 && j < num_favorites; j++) {
|
||||||
if ( strcasecmp ( buffer, retv[j].entry ) == 0 ) {
|
if (strcasecmp(buffer, retv[j].entry) == 0) {
|
||||||
found = 1;
|
found = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( found == 1 ) {
|
if (found == 1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// No duplicate, add it.
|
// No duplicate, add it.
|
||||||
retv = g_realloc ( retv, ( ( *length ) + 2 ) * sizeof ( RunEntry ) );
|
retv = g_realloc(retv, ((*length) + 2) * sizeof(RunEntry));
|
||||||
retv[( *length )].entry = g_strdup ( buffer );
|
retv[(*length)].entry = g_strdup(buffer);
|
||||||
retv[( *length )].icon = NULL;
|
retv[(*length)].icon = NULL;
|
||||||
retv[( *length )].icon_fetch_uid = 0;
|
retv[(*length)].icon_fetch_uid = 0;
|
||||||
|
|
||||||
( *length )++;
|
(*length)++;
|
||||||
}
|
}
|
||||||
if ( buffer != NULL ) {
|
if (buffer != NULL) {
|
||||||
free ( buffer );
|
free(buffer);
|
||||||
}
|
}
|
||||||
if ( fclose ( inp ) != 0 ) {
|
if (fclose(inp) != 0) {
|
||||||
g_warning ( "Failed to close stdout off executor script: '%s'",
|
g_warning("Failed to close stdout off executor script: '%s'",
|
||||||
g_strerror ( errno ) );
|
g_strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
retv[( *length ) ].entry = NULL;
|
retv[(*length)].entry = NULL;
|
||||||
retv[( *length ) ].icon = NULL;
|
retv[(*length)].icon = NULL;
|
||||||
retv[( *length ) ].icon_fetch_uid = 0;
|
retv[(*length)].icon_fetch_uid = 0;
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal spider used to get list of executables.
|
* 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;
|
GError *error = NULL;
|
||||||
RunEntry *retv = NULL;
|
RunEntry *retv = NULL;
|
||||||
unsigned int num_favorites = 0;
|
unsigned int num_favorites = 0;
|
||||||
char *path;
|
char *path;
|
||||||
|
|
||||||
if ( g_getenv ( "PATH" ) == NULL ) {
|
if (g_getenv("PATH") == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
TICK_N ( "start" );
|
TICK_N("start");
|
||||||
path = g_build_filename ( cache_dir, RUN_CACHE_FILE, NULL );
|
path = g_build_filename(cache_dir, RUN_CACHE_FILE, NULL);
|
||||||
char **hretv = history_get_list ( path, length );
|
char **hretv = history_get_list(path, length);
|
||||||
retv = (RunEntry*)g_malloc0((*length+1)*sizeof(RunEntry));
|
retv = (RunEntry *)g_malloc0((*length + 1) * sizeof(RunEntry));
|
||||||
for ( unsigned int i = 0; i < *length; i++ ) {
|
for (unsigned int i = 0; i < *length; i++) {
|
||||||
retv[i].entry = hretv[i];
|
retv[i].entry = hretv[i];
|
||||||
}
|
}
|
||||||
g_free(hretv);
|
g_free(hretv);
|
||||||
g_free ( path );
|
g_free(path);
|
||||||
// Keep track of how many where loaded as favorite.
|
// 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;
|
gsize l = 0;
|
||||||
gchar *homedir = g_locale_to_utf8 ( g_get_home_dir (), -1, NULL, &l, &error );
|
gchar *homedir = g_locale_to_utf8(g_get_home_dir(), -1, NULL, &l, &error);
|
||||||
if ( error != NULL ) {
|
if (error != NULL) {
|
||||||
g_debug ( "Failed to convert homedir to UTF-8: %s", error->message );
|
g_debug("Failed to convert homedir to UTF-8: %s", error->message);
|
||||||
for ( unsigned int i = 0; retv[i].entry != NULL ; i++ ) {
|
for (unsigned int i = 0; retv[i].entry != NULL; i++) {
|
||||||
g_free ( retv[i].entry );
|
g_free(retv[i].entry);
|
||||||
}
|
}
|
||||||
g_free(retv);
|
g_free(retv);
|
||||||
g_clear_error ( &error );
|
g_clear_error(&error);
|
||||||
g_free ( homedir );
|
g_free(homedir);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *const sep = ":";
|
const char *const sep = ":";
|
||||||
char *strtok_savepointer = NULL;
|
char *strtok_savepointer = NULL;
|
||||||
for ( const char *dirname = strtok_r ( path, sep, &strtok_savepointer ); dirname != NULL; dirname = strtok_r ( NULL, sep, &strtok_savepointer ) ) {
|
for (const char *dirname = strtok_r(path, sep, &strtok_savepointer);
|
||||||
char *fpath = rofi_expand_path ( dirname );
|
dirname != NULL; dirname = strtok_r(NULL, sep, &strtok_savepointer)) {
|
||||||
DIR *dir = opendir ( fpath );
|
char *fpath = rofi_expand_path(dirname);
|
||||||
g_debug ( "Checking path %s for executable.", fpath );
|
DIR *dir = opendir(fpath);
|
||||||
g_free ( fpath );
|
g_debug("Checking path %s for executable.", fpath);
|
||||||
|
g_free(fpath);
|
||||||
|
|
||||||
if ( dir != NULL ) {
|
if (dir != NULL) {
|
||||||
struct dirent *dent;
|
struct dirent *dent;
|
||||||
gsize dirn_len = 0;
|
gsize dirn_len = 0;
|
||||||
gchar *dirn = g_locale_to_utf8 ( dirname, -1, NULL, &dirn_len, &error );
|
gchar *dirn = g_locale_to_utf8(dirname, -1, NULL, &dirn_len, &error);
|
||||||
if ( error != NULL ) {
|
if (error != NULL) {
|
||||||
g_debug ( "Failed to convert directory name to UTF-8: %s", error->message );
|
g_debug("Failed to convert directory name to UTF-8: %s",
|
||||||
g_clear_error ( &error );
|
error->message);
|
||||||
closedir ( dir );
|
g_clear_error(&error);
|
||||||
|
closedir(dir);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
gboolean is_homedir = g_str_has_prefix ( dirn, homedir );
|
gboolean is_homedir = g_str_has_prefix(dirn, homedir);
|
||||||
g_free ( dirn );
|
g_free(dirn);
|
||||||
|
|
||||||
while ( ( dent = readdir ( dir ) ) != NULL ) {
|
while ((dent = readdir(dir)) != NULL) {
|
||||||
if ( dent->d_type != DT_REG && dent->d_type != DT_LNK && dent->d_type != DT_UNKNOWN ) {
|
if (dent->d_type != DT_REG && dent->d_type != DT_LNK &&
|
||||||
|
dent->d_type != DT_UNKNOWN) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Skip dot files.
|
// Skip dot files.
|
||||||
if ( dent->d_name[0] == '.' ) {
|
if (dent->d_name[0] == '.') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ( is_homedir ) {
|
if (is_homedir) {
|
||||||
gchar *fpath = g_build_filename ( dirname, dent->d_name, NULL );
|
gchar *fpath = g_build_filename(dirname, dent->d_name, NULL);
|
||||||
gboolean b = g_file_test ( fpath, G_FILE_TEST_IS_EXECUTABLE );
|
gboolean b = g_file_test(fpath, G_FILE_TEST_IS_EXECUTABLE);
|
||||||
g_free ( fpath );
|
g_free(fpath);
|
||||||
if ( !b ) {
|
if (!b) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gsize name_len;
|
gsize name_len;
|
||||||
gchar *name = g_filename_to_utf8 ( dent->d_name, -1, NULL, &name_len, &error );
|
gchar *name =
|
||||||
if ( error != NULL ) {
|
g_filename_to_utf8(dent->d_name, -1, NULL, &name_len, &error);
|
||||||
g_debug ( "Failed to convert filename to UTF-8: %s", error->message );
|
if (error != NULL) {
|
||||||
g_clear_error ( &error );
|
g_debug("Failed to convert filename to UTF-8: %s", error->message);
|
||||||
g_free ( name );
|
g_clear_error(&error);
|
||||||
|
g_free(name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// This is a nice little penalty, but doable? time will tell.
|
// This is a nice little penalty, but doable? time will tell.
|
||||||
// given num_favorites is max 25.
|
// given num_favorites is max 25.
|
||||||
int found = 0;
|
int found = 0;
|
||||||
for ( unsigned int j = 0; found == 0 && j < num_favorites; j++ ) {
|
for (unsigned int j = 0; found == 0 && j < num_favorites; j++) {
|
||||||
if ( g_strcmp0 ( name, retv[j].entry ) == 0 ) {
|
if (g_strcmp0(name, retv[j].entry) == 0) {
|
||||||
found = 1;
|
found = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( found == 1 ) {
|
if (found == 1) {
|
||||||
g_free ( name );
|
g_free(name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
retv = g_realloc ( retv, ( ( *length ) + 2 ) * sizeof ( RunEntry ) );
|
retv = g_realloc(retv, ((*length) + 2) * sizeof(RunEntry));
|
||||||
retv[( *length )].entry = name;
|
retv[(*length)].entry = name;
|
||||||
retv[( *length )].icon = NULL;
|
retv[(*length)].icon = NULL;
|
||||||
retv[( *length )].icon_fetch_uid = 0;
|
retv[(*length)].icon_fetch_uid = 0;
|
||||||
retv[( *length ) + 1].entry = NULL;
|
retv[(*length) + 1].entry = NULL;
|
||||||
retv[( *length ) + 1].icon = NULL;
|
retv[(*length) + 1].icon = NULL;
|
||||||
retv[( *length ) + 1].icon_fetch_uid = 0;
|
retv[(*length) + 1].icon_fetch_uid = 0;
|
||||||
( *length )++;
|
(*length)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir ( dir );
|
closedir(dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_free ( homedir );
|
g_free(homedir);
|
||||||
|
|
||||||
// Get external apps.
|
// Get external apps.
|
||||||
if ( config.run_list_command != NULL && config.run_list_command[0] != '\0' ) {
|
if (config.run_list_command != NULL && config.run_list_command[0] != '\0') {
|
||||||
retv = get_apps_external ( retv, length, num_favorites );
|
retv = get_apps_external(retv, length, num_favorites);
|
||||||
}
|
}
|
||||||
// No sorting needed.
|
// No sorting needed.
|
||||||
if ( ( *length ) == 0 ) {
|
if ((*length) == 0) {
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
// TODO: check this is still fast enough. (takes 1ms on laptop.)
|
// TODO: check this is still fast enough. (takes 1ms on laptop.)
|
||||||
if ( ( *length ) > num_favorites ) {
|
if ((*length) > num_favorites) {
|
||||||
g_qsort_with_data ( &(retv[num_favorites]), ( *length ) - num_favorites, sizeof ( RunEntry ), sort_func, NULL );
|
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;
|
unsigned int removed = 0;
|
||||||
for ( unsigned int index = num_favorites; index < ( ( *length ) - 1 ); index++ ) {
|
for (unsigned int index = num_favorites; index < ((*length) - 1); index++) {
|
||||||
if ( g_strcmp0 ( retv[index].entry , retv[index + 1].entry ) == 0 ) {
|
if (g_strcmp0(retv[index].entry, retv[index + 1].entry) == 0) {
|
||||||
g_free ( retv[index].entry );
|
g_free(retv[index].entry);
|
||||||
retv[index].entry = NULL;
|
retv[index].entry = NULL;
|
||||||
removed++;
|
removed++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( *length ) > num_favorites ) {
|
if ((*length) > num_favorites) {
|
||||||
g_qsort_with_data ( &(retv[num_favorites]), ( *length ) - num_favorites, sizeof ( RunEntry ),
|
g_qsort_with_data(&(retv[num_favorites]), (*length) - num_favorites,
|
||||||
sort_func,
|
sizeof(RunEntry), sort_func, NULL);
|
||||||
NULL );
|
|
||||||
}
|
}
|
||||||
// Reduce array length;
|
// Reduce array length;
|
||||||
( *length ) -= removed;
|
(*length) -= removed;
|
||||||
|
|
||||||
TICK_N ( "stop" );
|
TICK_N("stop");
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int run_mode_init ( Mode *sw )
|
static int run_mode_init(Mode *sw) {
|
||||||
{
|
if (sw->private_data == NULL) {
|
||||||
if ( sw->private_data == NULL ) {
|
RunModePrivateData *pd = g_malloc0(sizeof(*pd));
|
||||||
RunModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
|
sw->private_data = (void *)pd;
|
||||||
sw->private_data = (void *) pd;
|
pd->cmd_list = get_apps(&(pd->cmd_list_length));
|
||||||
pd->cmd_list = get_apps ( &( pd->cmd_list_length ) );
|
pd->completer = create_new_file_browser();
|
||||||
pd->completer = create_new_file_browser ();
|
mode_init(pd->completer);
|
||||||
mode_init ( pd->completer );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
static void run_mode_destroy ( Mode *sw )
|
static void run_mode_destroy(Mode *sw) {
|
||||||
{
|
RunModePrivateData *rmpd = (RunModePrivateData *)sw->private_data;
|
||||||
RunModePrivateData *rmpd = (RunModePrivateData *) sw->private_data;
|
if (rmpd != NULL) {
|
||||||
if ( rmpd != NULL ) {
|
for (unsigned int i = 0; i < rmpd->cmd_list_length; i++) {
|
||||||
for ( unsigned int i = 0; i < rmpd->cmd_list_length; i++ ) {
|
g_free(rmpd->cmd_list[i].entry);
|
||||||
g_free ( rmpd->cmd_list[i].entry );
|
if (rmpd->cmd_list[i].icon != NULL) {
|
||||||
if ( rmpd->cmd_list[i].icon != NULL ) {
|
cairo_surface_destroy(rmpd->cmd_list[i].icon);
|
||||||
cairo_surface_destroy ( rmpd->cmd_list[i].icon );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_free ( rmpd->cmd_list );
|
g_free(rmpd->cmd_list);
|
||||||
g_free ( rmpd->old_input );
|
g_free(rmpd->old_input);
|
||||||
g_free ( rmpd->old_completer_input );
|
g_free(rmpd->old_completer_input);
|
||||||
mode_destroy ( rmpd->completer );
|
mode_destroy(rmpd->completer);
|
||||||
g_free ( rmpd );
|
g_free(rmpd);
|
||||||
sw->private_data = NULL;
|
sw->private_data = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int run_mode_get_num_entries ( const Mode *sw )
|
static unsigned int run_mode_get_num_entries(const Mode *sw) {
|
||||||
{
|
const RunModePrivateData *rmpd = (const RunModePrivateData *)sw->private_data;
|
||||||
const RunModePrivateData *rmpd = (const RunModePrivateData *) sw->private_data;
|
if (rmpd->file_complete) {
|
||||||
if ( rmpd->file_complete ) {
|
return rmpd->completer->_get_num_entries(rmpd->completer);
|
||||||
return rmpd->completer->_get_num_entries( rmpd->completer );
|
|
||||||
}
|
}
|
||||||
return rmpd->cmd_list_length;
|
return rmpd->cmd_list_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ModeMode run_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line )
|
static ModeMode run_mode_result(Mode *sw, int mretv, char **input,
|
||||||
{
|
unsigned int selected_line) {
|
||||||
RunModePrivateData *rmpd = (RunModePrivateData *) sw->private_data;
|
RunModePrivateData *rmpd = (RunModePrivateData *)sw->private_data;
|
||||||
ModeMode retv = MODE_EXIT;
|
ModeMode retv = MODE_EXIT;
|
||||||
|
|
||||||
gboolean run_in_term = ( ( mretv & MENU_CUSTOM_ACTION ) == MENU_CUSTOM_ACTION );
|
gboolean run_in_term = ((mretv & MENU_CUSTOM_ACTION) == MENU_CUSTOM_ACTION);
|
||||||
if ( rmpd->file_complete == TRUE ) {
|
if (rmpd->file_complete == TRUE) {
|
||||||
|
|
||||||
retv = RELOAD_DIALOG;
|
retv = RELOAD_DIALOG;
|
||||||
|
|
||||||
if ( ( mretv& (MENU_COMPLETE)) ) {
|
if ((mretv & (MENU_COMPLETE))) {
|
||||||
g_free ( rmpd->old_completer_input );
|
g_free(rmpd->old_completer_input);
|
||||||
rmpd->old_completer_input = *input;
|
rmpd->old_completer_input = *input;
|
||||||
*input = NULL;
|
*input = NULL;
|
||||||
if ( rmpd->selected_line < rmpd->cmd_list_length ) {
|
if (rmpd->selected_line < rmpd->cmd_list_length) {
|
||||||
(*input) = g_strdup ( rmpd->old_input );
|
(*input) = g_strdup(rmpd->old_input);
|
||||||
}
|
}
|
||||||
rmpd->file_complete = FALSE;
|
rmpd->file_complete = FALSE;
|
||||||
}
|
} else if ((mretv & MENU_CANCEL)) {
|
||||||
else if ( (mretv&MENU_CANCEL) ) {
|
|
||||||
retv = MODE_EXIT;
|
retv = MODE_EXIT;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
char *path = NULL;
|
char *path = NULL;
|
||||||
retv = file_browser_mode_completer ( rmpd->completer, mretv, input, selected_line, &path );
|
retv = file_browser_mode_completer(rmpd->completer, mretv, input,
|
||||||
if ( retv == MODE_EXIT ) {
|
selected_line, &path);
|
||||||
if ( path == NULL ) {
|
if (retv == MODE_EXIT) {
|
||||||
exec_cmd ( rmpd->cmd_list[rmpd->selected_line].entry, run_in_term );
|
if (path == NULL) {
|
||||||
}
|
exec_cmd(rmpd->cmd_list[rmpd->selected_line].entry, run_in_term);
|
||||||
else {
|
} else {
|
||||||
char *arg= g_strdup_printf ( "%s '%s'", rmpd->cmd_list[rmpd->selected_line].entry, path);
|
char *arg = g_strdup_printf(
|
||||||
exec_cmd ( arg, run_in_term );
|
"%s '%s'", rmpd->cmd_list[rmpd->selected_line].entry, path);
|
||||||
|
exec_cmd(arg, run_in_term);
|
||||||
g_free(arg);
|
g_free(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
g_free (path);
|
g_free(path);
|
||||||
}
|
}
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( mretv & MENU_OK ) && rmpd->cmd_list[selected_line].entry != NULL ) {
|
if ((mretv & MENU_OK) && rmpd->cmd_list[selected_line].entry != NULL) {
|
||||||
if ( !exec_cmd ( rmpd->cmd_list[selected_line].entry, run_in_term ) ) {
|
if (!exec_cmd(rmpd->cmd_list[selected_line].entry, run_in_term)) {
|
||||||
retv = RELOAD_DIALOG;
|
retv = RELOAD_DIALOG;
|
||||||
}
|
}
|
||||||
}
|
} else if ((mretv & MENU_CUSTOM_INPUT) && *input != NULL &&
|
||||||
else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] != '\0' ) {
|
*input[0] != '\0') {
|
||||||
if ( !exec_cmd ( *input, run_in_term ) ) {
|
if (!exec_cmd(*input, run_in_term)) {
|
||||||
retv = RELOAD_DIALOG;
|
retv = RELOAD_DIALOG;
|
||||||
}
|
}
|
||||||
}
|
} else if ((mretv & MENU_ENTRY_DELETE) &&
|
||||||
else if ( ( mretv & MENU_ENTRY_DELETE ) && rmpd->cmd_list[selected_line].entry ) {
|
rmpd->cmd_list[selected_line].entry) {
|
||||||
delete_entry ( &(rmpd->cmd_list[selected_line]) );
|
delete_entry(&(rmpd->cmd_list[selected_line]));
|
||||||
|
|
||||||
// Clear the list.
|
// Clear the list.
|
||||||
retv = RELOAD_DIALOG;
|
retv = RELOAD_DIALOG;
|
||||||
run_mode_destroy ( sw );
|
run_mode_destroy(sw);
|
||||||
run_mode_init ( sw );
|
run_mode_init(sw);
|
||||||
}
|
} else if (mretv & MENU_CUSTOM_COMMAND) {
|
||||||
else if ( mretv & MENU_CUSTOM_COMMAND ) {
|
retv = (mretv & MENU_LOWER_MASK);
|
||||||
retv = ( mretv & MENU_LOWER_MASK );
|
} else if ((mretv & MENU_COMPLETE)) {
|
||||||
}
|
|
||||||
else if ( ( mretv& MENU_COMPLETE) ) {
|
|
||||||
retv = RELOAD_DIALOG;
|
retv = RELOAD_DIALOG;
|
||||||
if ( selected_line < rmpd->cmd_list_length ) {
|
if (selected_line < rmpd->cmd_list_length) {
|
||||||
rmpd->selected_line = selected_line;
|
rmpd->selected_line = selected_line;
|
||||||
|
|
||||||
g_free ( rmpd->old_input );
|
g_free(rmpd->old_input);
|
||||||
rmpd->old_input = g_strdup ( *input );
|
rmpd->old_input = g_strdup(*input);
|
||||||
|
|
||||||
if ( *input ) g_free (*input);
|
if (*input)
|
||||||
*input = g_strdup ( rmpd->old_completer_input );
|
g_free(*input);
|
||||||
|
*input = g_strdup(rmpd->old_completer_input);
|
||||||
|
|
||||||
rmpd->file_complete = TRUE;
|
rmpd->file_complete = TRUE;
|
||||||
}
|
}
|
||||||
@@ -497,84 +490,85 @@ static ModeMode run_mode_result ( Mode *sw, int mretv, char **input, unsigned in
|
|||||||
return retv;
|
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 )
|
static char *_get_display_value(const Mode *sw, unsigned int selected_line,
|
||||||
{
|
G_GNUC_UNUSED int *state,
|
||||||
const RunModePrivateData *rmpd = (const RunModePrivateData *) sw->private_data;
|
G_GNUC_UNUSED GList **list, int get_entry) {
|
||||||
if ( rmpd->file_complete ) {
|
const RunModePrivateData *rmpd = (const RunModePrivateData *)sw->private_data;
|
||||||
return rmpd->completer->_get_display_value (rmpd->completer, selected_line, state, list, get_entry );
|
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 )
|
static int run_token_match(const Mode *sw, rofi_int_matcher **tokens,
|
||||||
{
|
unsigned int index) {
|
||||||
const RunModePrivateData *rmpd = (const RunModePrivateData *) sw->private_data;
|
const RunModePrivateData *rmpd = (const RunModePrivateData *)sw->private_data;
|
||||||
if ( rmpd->file_complete ) {
|
if (rmpd->file_complete) {
|
||||||
return rmpd->completer->_token_match (rmpd->completer, tokens, index );
|
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;
|
RunModePrivateData *pd = sw->private_data;
|
||||||
if ( pd->file_complete ) {
|
if (pd->file_complete) {
|
||||||
if ( pd->selected_line < pd->cmd_list_length ) {
|
if (pd->selected_line < pd->cmd_list_length) {
|
||||||
char *msg = mode_get_message ( pd->completer);
|
char *msg = mode_get_message(pd->completer);
|
||||||
if ( msg ) {
|
if (msg) {
|
||||||
char *retv = g_strdup_printf("File complete for: %s\n%s", pd->cmd_list[pd->selected_line].entry, msg);
|
char *retv =
|
||||||
g_free (msg);
|
g_strdup_printf("File complete for: %s\n%s",
|
||||||
|
pd->cmd_list[pd->selected_line].entry, msg);
|
||||||
|
g_free(msg);
|
||||||
return retv;
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
static cairo_surface_t *fallback_icon ( RunModePrivateData *pd, int height )
|
static cairo_surface_t *fallback_icon(RunModePrivateData *pd, int height) {
|
||||||
{
|
if (config.application_fallback_icon) {
|
||||||
if ( config.application_fallback_icon ) {
|
|
||||||
// FALLBACK
|
// FALLBACK
|
||||||
if ( pd->fallback_icon_fetch_uid > 0 ) {
|
if (pd->fallback_icon_fetch_uid > 0) {
|
||||||
return rofi_icon_fetcher_get ( pd->fallback_icon_fetch_uid );
|
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;
|
return NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
static cairo_surface_t *_get_icon ( const Mode *sw, unsigned int selected_line, int height )
|
static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line,
|
||||||
{
|
int height) {
|
||||||
RunModePrivateData *pd = (RunModePrivateData *) mode_get_private_data ( sw );
|
RunModePrivateData *pd = (RunModePrivateData *)mode_get_private_data(sw);
|
||||||
if ( pd->file_complete ) {
|
if (pd->file_complete) {
|
||||||
return pd->completer->_get_icon ( pd->completer, selected_line, height );
|
return pd->completer->_get_icon(pd->completer, selected_line, height);
|
||||||
}
|
}
|
||||||
g_return_val_if_fail ( pd->cmd_list != NULL, NULL );
|
g_return_val_if_fail(pd->cmd_list != NULL, NULL);
|
||||||
RunEntry *dr = &( pd->cmd_list[selected_line] );
|
RunEntry *dr = &(pd->cmd_list[selected_line]);
|
||||||
|
|
||||||
if ( dr->icon_fetch_uid > 0 ) {
|
if (dr->icon_fetch_uid > 0) {
|
||||||
cairo_surface_t *icon = rofi_icon_fetcher_get ( dr->icon_fetch_uid );
|
cairo_surface_t *icon = rofi_icon_fetcher_get(dr->icon_fetch_uid);
|
||||||
if ( icon ) {
|
if (icon) {
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
return fallback_icon ( pd, height );
|
return fallback_icon(pd, height);
|
||||||
}
|
}
|
||||||
/** lookup icon */
|
/** lookup icon */
|
||||||
char ** str = g_strsplit(dr->entry, " ", 2);
|
char **str = g_strsplit(dr->entry, " ", 2);
|
||||||
if ( str ) {
|
if (str) {
|
||||||
dr->icon_fetch_uid = rofi_icon_fetcher_query ( str[0], height );
|
dr->icon_fetch_uid = rofi_icon_fetcher_query(str[0], height);
|
||||||
g_strfreev ( str );
|
g_strfreev(str);
|
||||||
cairo_surface_t *icon = rofi_icon_fetcher_get ( dr->icon_fetch_uid );
|
cairo_surface_t *icon = rofi_icon_fetcher_get(dr->icon_fetch_uid);
|
||||||
if ( icon ) {
|
if (icon) {
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fallback_icon ( pd, height );
|
return fallback_icon(pd, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "mode-private.h"
|
#include "mode-private.h"
|
||||||
Mode run_mode =
|
Mode run_mode = {.name = "run",
|
||||||
{
|
|
||||||
.name = "run",
|
|
||||||
.cfg_name_key = "display-run",
|
.cfg_name_key = "display-run",
|
||||||
._init = run_mode_init,
|
._init = run_mode_init,
|
||||||
._get_num_entries = run_mode_get_num_entries,
|
._get_num_entries = run_mode_get_num_entries,
|
||||||
@@ -587,6 +581,5 @@ Mode run_mode =
|
|||||||
._get_completion = NULL,
|
._get_completion = NULL,
|
||||||
._preprocess_input = NULL,
|
._preprocess_input = NULL,
|
||||||
.private_data = NULL,
|
.private_data = NULL,
|
||||||
.free = NULL
|
.free = NULL};
|
||||||
};
|
|
||||||
/** @}*/
|
/** @}*/
|
||||||
|
@@ -28,18 +28,17 @@
|
|||||||
/** The log domain of this dialog. */
|
/** The log domain of this dialog. */
|
||||||
#define G_LOG_DOMAIN "Dialogs.Script"
|
#define G_LOG_DOMAIN "Dialogs.Script"
|
||||||
|
|
||||||
#include <config.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <strings.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include "rofi.h"
|
|
||||||
#include "dialogs/script.h"
|
#include "dialogs/script.h"
|
||||||
#include "helper.h"
|
#include "helper.h"
|
||||||
|
#include "rofi.h"
|
||||||
|
#include <assert.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <strings.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "widgets/textbox.h"
|
#include "widgets/textbox.h"
|
||||||
|
|
||||||
@@ -49,8 +48,7 @@
|
|||||||
|
|
||||||
#include "dialogs/dmenuscriptshared.h"
|
#include "dialogs/dmenuscriptshared.h"
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
/** ID of the current script. */
|
/** ID of the current script. */
|
||||||
unsigned int id;
|
unsigned int id;
|
||||||
/** List of visible items. */
|
/** List of visible items. */
|
||||||
@@ -59,10 +57,10 @@ typedef struct
|
|||||||
unsigned int cmd_list_length;
|
unsigned int cmd_list_length;
|
||||||
|
|
||||||
/** Urgent list */
|
/** Urgent list */
|
||||||
struct rofi_range_pair * urgent_list;
|
struct rofi_range_pair *urgent_list;
|
||||||
unsigned int num_urgent_list;
|
unsigned int num_urgent_list;
|
||||||
/** Active list */
|
/** Active list */
|
||||||
struct rofi_range_pair * active_list;
|
struct rofi_range_pair *active_list;
|
||||||
unsigned int num_active_list;
|
unsigned int num_active_list;
|
||||||
/** Configuration settings. */
|
/** Configuration settings. */
|
||||||
char *message;
|
char *message;
|
||||||
@@ -78,82 +76,72 @@ typedef struct
|
|||||||
/**
|
/**
|
||||||
* Shared function between DMENU and Script mode.
|
* Shared function between DMENU and Script mode.
|
||||||
*/
|
*/
|
||||||
void dmenuscript_parse_entry_extras ( G_GNUC_UNUSED Mode *sw, DmenuScriptEntry *entry, char *buffer, G_GNUC_UNUSED size_t length )
|
void dmenuscript_parse_entry_extras(G_GNUC_UNUSED Mode *sw,
|
||||||
{
|
DmenuScriptEntry *entry, char *buffer,
|
||||||
gchar **extras = g_strsplit ( buffer, "\x1f", -1 );
|
G_GNUC_UNUSED size_t length) {
|
||||||
|
gchar **extras = g_strsplit(buffer, "\x1f", -1);
|
||||||
gchar **extra;
|
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 *key = *extra;
|
||||||
gchar *value = *( extra + 1 );
|
gchar *value = *(extra + 1);
|
||||||
if ( strcasecmp ( key, "icon" ) == 0 ) {
|
if (strcasecmp(key, "icon") == 0) {
|
||||||
entry->icon_name = value;
|
entry->icon_name = value;
|
||||||
}
|
} else if (strcasecmp(key, "meta") == 0) {
|
||||||
else if ( strcasecmp ( key, "meta" ) == 0 ) {
|
|
||||||
entry->meta = value;
|
entry->meta = value;
|
||||||
}
|
} else if (strcasecmp(key, "info") == 0) {
|
||||||
else if ( strcasecmp ( key, "info" ) == 0 ) {
|
|
||||||
entry->info = value;
|
entry->info = value;
|
||||||
|
} else if (strcasecmp(key, "nonselectable") == 0) {
|
||||||
|
entry->nonselectable = strcasecmp(value, "true") == 0;
|
||||||
|
g_free(value);
|
||||||
|
} else {
|
||||||
|
g_free(value);
|
||||||
}
|
}
|
||||||
else if ( strcasecmp ( key, "nonselectable" ) == 0 ) {
|
g_free(key);
|
||||||
entry->nonselectable = strcasecmp ( value, "true" ) == 0;
|
|
||||||
g_free ( value );
|
|
||||||
}
|
}
|
||||||
else {
|
g_free(extras);
|
||||||
g_free ( value );
|
|
||||||
}
|
|
||||||
g_free ( key );
|
|
||||||
}
|
|
||||||
g_free ( extras );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* End of shared functions.
|
* End of shared functions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void parse_header_entry ( Mode *sw, char *line, ssize_t length )
|
static void parse_header_entry(Mode *sw, char *line, ssize_t length) {
|
||||||
{
|
ScriptModePrivateData *pd = (ScriptModePrivateData *)sw->private_data;
|
||||||
ScriptModePrivateData *pd = (ScriptModePrivateData *) sw->private_data;
|
ssize_t length_key = 0; // strlen ( line );
|
||||||
ssize_t length_key = 0;//strlen ( line );
|
while (length_key < length && line[length_key] != '\x1f') {
|
||||||
while ( length_key < length && line[length_key] != '\x1f' ) {
|
|
||||||
length_key++;
|
length_key++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( length_key + 1 ) < length ) {
|
if ((length_key + 1) < length) {
|
||||||
line[length_key] = '\0';
|
line[length_key] = '\0';
|
||||||
char *value = line + length_key + 1;
|
char *value = line + length_key + 1;
|
||||||
if ( strcasecmp ( line, "message" ) == 0 ) {
|
if (strcasecmp(line, "message") == 0) {
|
||||||
g_free ( pd->message );
|
g_free(pd->message);
|
||||||
pd->message = strlen ( value ) ? g_strdup ( value ) : NULL;
|
pd->message = strlen(value) ? g_strdup(value) : NULL;
|
||||||
}
|
} else if (strcasecmp(line, "prompt") == 0) {
|
||||||
else if ( strcasecmp ( line, "prompt" ) == 0 ) {
|
g_free(pd->prompt);
|
||||||
g_free ( pd->prompt );
|
pd->prompt = g_strdup(value);
|
||||||
pd->prompt = g_strdup ( value );
|
|
||||||
sw->display_name = pd->prompt;
|
sw->display_name = pd->prompt;
|
||||||
}
|
} else if (strcasecmp(line, "markup-rows") == 0) {
|
||||||
else if ( strcasecmp ( line, "markup-rows" ) == 0 ) {
|
pd->do_markup = (strcasecmp(value, "true") == 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, "urgent" ) == 0 ) {
|
} else if (strcasecmp(line, "active") == 0) {
|
||||||
parse_ranges ( value, &( pd->urgent_list ), &( pd->num_urgent_list ) );
|
parse_ranges(value, &(pd->active_list), &(pd->num_active_list));
|
||||||
}
|
} else if (strcasecmp(line, "delim") == 0) {
|
||||||
else if ( strcasecmp ( line, "active" ) == 0 ) {
|
pd->delim = helper_parse_char(value);
|
||||||
parse_ranges ( value, &( pd->active_list ), &( pd->num_active_list ) );
|
} else if (strcasecmp(line, "no-custom") == 0) {
|
||||||
}
|
pd->no_custom = (strcasecmp(value, "true") == 0);
|
||||||
else if ( strcasecmp ( line, "delim" ) == 0 ) {
|
} else if (strcasecmp(line, "use-hot-keys") == 0) {
|
||||||
pd->delim = helper_parse_char ( value );
|
pd->use_hot_keys = (strcasecmp(value, "true") == 0);
|
||||||
}
|
|
||||||
else if ( strcasecmp ( line, "no-custom" ) == 0 ) {
|
|
||||||
pd->no_custom = ( strcasecmp ( value, "true" ) == 0 );
|
|
||||||
}
|
|
||||||
else if ( strcasecmp ( line, "use-hot-keys" ) == 0 ) {
|
|
||||||
pd->use_hot_keys = ( strcasecmp ( value, "true" ) == 0 );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static DmenuScriptEntry *execute_executor ( Mode *sw, char *arg, unsigned int *length, int value, DmenuScriptEntry *entry )
|
static DmenuScriptEntry *execute_executor(Mode *sw, char *arg,
|
||||||
{
|
unsigned int *length, int value,
|
||||||
ScriptModePrivateData *pd = (ScriptModePrivateData *) sw->private_data;
|
DmenuScriptEntry *entry) {
|
||||||
|
ScriptModePrivateData *pd = (ScriptModePrivateData *)sw->private_data;
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
DmenuScriptEntry *retv = NULL;
|
DmenuScriptEntry *retv = NULL;
|
||||||
@@ -162,172 +150,173 @@ static DmenuScriptEntry *execute_executor ( Mode *sw, char *arg, unsigned int *l
|
|||||||
*length = 0;
|
*length = 0;
|
||||||
|
|
||||||
// Environment
|
// Environment
|
||||||
char ** env = g_get_environ ();
|
char **env = g_get_environ();
|
||||||
|
|
||||||
char *str_value = g_strdup_printf ( "%d", value );
|
char *str_value = g_strdup_printf("%d", value);
|
||||||
env = g_environ_setenv ( env, "ROFI_RETV", str_value, TRUE );
|
env = g_environ_setenv(env, "ROFI_RETV", str_value, TRUE);
|
||||||
g_free ( str_value );
|
g_free(str_value);
|
||||||
|
|
||||||
str_value = g_strdup_printf ( "%d", (int) getpid () );
|
str_value = g_strdup_printf("%d", (int)getpid());
|
||||||
env = g_environ_setenv ( env, "ROFI_OUTSIDE", str_value, TRUE );
|
env = g_environ_setenv(env, "ROFI_OUTSIDE", str_value, TRUE);
|
||||||
g_free ( str_value );
|
g_free(str_value);
|
||||||
|
|
||||||
if ( entry && entry->info ) {
|
if (entry && entry->info) {
|
||||||
env = g_environ_setenv ( env, "ROFI_INFO", entry->info, TRUE );
|
env = g_environ_setenv(env, "ROFI_INFO", entry->info, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( g_shell_parse_argv ( sw->ed, &argc, &argv, &error ) ) {
|
if (g_shell_parse_argv(sw->ed, &argc, &argv, &error)) {
|
||||||
argv = g_realloc ( argv, ( argc + 2 ) * sizeof ( char* ) );
|
argv = g_realloc(argv, (argc + 2) * sizeof(char *));
|
||||||
argv[argc] = g_strdup ( arg );
|
argv[argc] = g_strdup(arg);
|
||||||
argv[argc + 1] = NULL;
|
argv[argc + 1] = NULL;
|
||||||
g_spawn_async_with_pipes ( NULL, argv, env, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL, &fd, NULL, &error );
|
g_spawn_async_with_pipes(NULL, argv, env, G_SPAWN_SEARCH_PATH, NULL, NULL,
|
||||||
|
NULL, NULL, &fd, NULL, &error);
|
||||||
}
|
}
|
||||||
g_strfreev ( env );
|
g_strfreev(env);
|
||||||
if ( error != NULL ) {
|
if (error != NULL) {
|
||||||
char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", (char *) sw->ed, error->message );
|
char *msg = g_strdup_printf("Failed to execute: '%s'\nError: '%s'",
|
||||||
rofi_view_error_dialog ( msg, FALSE );
|
(char *)sw->ed, error->message);
|
||||||
g_free ( msg );
|
rofi_view_error_dialog(msg, FALSE);
|
||||||
|
g_free(msg);
|
||||||
// print error.
|
// print error.
|
||||||
g_error_free ( error );
|
g_error_free(error);
|
||||||
fd = -1;
|
fd = -1;
|
||||||
}
|
}
|
||||||
if ( fd >= 0 ) {
|
if (fd >= 0) {
|
||||||
FILE *inp = fdopen ( fd, "r" );
|
FILE *inp = fdopen(fd, "r");
|
||||||
if ( inp ) {
|
if (inp) {
|
||||||
char *buffer = NULL;
|
char *buffer = NULL;
|
||||||
size_t buffer_length = 0;
|
size_t buffer_length = 0;
|
||||||
ssize_t read_length = 0;
|
ssize_t read_length = 0;
|
||||||
size_t actual_size = 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.
|
// Filter out line-end.
|
||||||
if ( buffer[read_length - 1] == pd->delim ) {
|
if (buffer[read_length - 1] == pd->delim) {
|
||||||
buffer[read_length - 1] = '\0';
|
buffer[read_length - 1] = '\0';
|
||||||
}
|
}
|
||||||
if ( buffer[0] == '\0' ) {
|
if (buffer[0] == '\0') {
|
||||||
parse_header_entry ( sw, &buffer[1], read_length - 1 );
|
parse_header_entry(sw, &buffer[1], read_length - 1);
|
||||||
}
|
} else {
|
||||||
else {
|
if (actual_size < ((*length) + 2)) {
|
||||||
if ( actual_size < ( ( *length ) + 2 ) ) {
|
|
||||||
actual_size += 256;
|
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;
|
size_t buf_length = strlen(buffer) + 1;
|
||||||
retv[( *length )].entry = g_memdup ( buffer, buf_length );
|
retv[(*length)].entry = g_memdup(buffer, buf_length);
|
||||||
retv[( *length )].icon_name = NULL;
|
retv[(*length)].icon_name = NULL;
|
||||||
retv[( *length )].meta = NULL;
|
retv[(*length)].meta = NULL;
|
||||||
retv[( *length )].info = NULL;
|
retv[(*length)].info = NULL;
|
||||||
retv[( *length )].icon_fetch_uid = 0;
|
retv[(*length)].icon_fetch_uid = 0;
|
||||||
retv[( *length )].nonselectable = FALSE;
|
retv[(*length)].nonselectable = FALSE;
|
||||||
if ( buf_length > 0 && ( read_length > (ssize_t) buf_length ) ) {
|
if (buf_length > 0 && (read_length > (ssize_t)buf_length)) {
|
||||||
dmenuscript_parse_entry_extras ( sw, &( retv[( *length )] ), buffer + buf_length, read_length - buf_length );
|
dmenuscript_parse_entry_extras(sw, &(retv[(*length)]),
|
||||||
|
buffer + buf_length,
|
||||||
|
read_length - buf_length);
|
||||||
}
|
}
|
||||||
retv[( *length ) + 1].entry = NULL;
|
retv[(*length) + 1].entry = NULL;
|
||||||
( *length )++;
|
(*length)++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( buffer ) {
|
if (buffer) {
|
||||||
free ( buffer );
|
free(buffer);
|
||||||
}
|
}
|
||||||
if ( fclose ( inp ) != 0 ) {
|
if (fclose(inp) != 0) {
|
||||||
g_warning ( "Failed to close stdout off executor script: '%s'",
|
g_warning("Failed to close stdout off executor script: '%s'",
|
||||||
g_strerror ( errno ) );
|
g_strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_strfreev ( argv );
|
g_strfreev(argv);
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void script_switcher_free ( Mode *sw )
|
static void script_switcher_free(Mode *sw) {
|
||||||
{
|
if (sw == NULL) {
|
||||||
if ( sw == NULL ) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
g_free ( sw->name );
|
g_free(sw->name);
|
||||||
g_free ( sw->ed );
|
g_free(sw->ed);
|
||||||
g_free ( sw );
|
g_free(sw);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int script_mode_init ( Mode *sw )
|
static int script_mode_init(Mode *sw) {
|
||||||
{
|
if (sw->private_data == NULL) {
|
||||||
if ( sw->private_data == NULL ) {
|
ScriptModePrivateData *pd = g_malloc0(sizeof(*pd));
|
||||||
ScriptModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
|
|
||||||
pd->delim = '\n';
|
pd->delim = '\n';
|
||||||
sw->private_data = (void *) pd;
|
sw->private_data = (void *)pd;
|
||||||
pd->cmd_list = execute_executor ( sw, NULL, &( pd->cmd_list_length ), 0, NULL );
|
pd->cmd_list = execute_executor(sw, NULL, &(pd->cmd_list_length), 0, NULL);
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
static unsigned int script_mode_get_num_entries ( const Mode *sw )
|
static unsigned int script_mode_get_num_entries(const Mode *sw) {
|
||||||
{
|
const ScriptModePrivateData *rmpd =
|
||||||
const ScriptModePrivateData *rmpd = (const ScriptModePrivateData *) sw->private_data;
|
(const ScriptModePrivateData *)sw->private_data;
|
||||||
return rmpd->cmd_list_length;
|
return rmpd->cmd_list_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void script_mode_reset_highlight ( Mode *sw )
|
static void script_mode_reset_highlight(Mode *sw) {
|
||||||
{
|
ScriptModePrivateData *rmpd = (ScriptModePrivateData *)sw->private_data;
|
||||||
ScriptModePrivateData *rmpd = (ScriptModePrivateData *) sw->private_data;
|
|
||||||
|
|
||||||
rmpd->num_urgent_list = 0;
|
rmpd->num_urgent_list = 0;
|
||||||
g_free ( rmpd->urgent_list );
|
g_free(rmpd->urgent_list);
|
||||||
rmpd->urgent_list = NULL;
|
rmpd->urgent_list = NULL;
|
||||||
rmpd->num_active_list = 0;
|
rmpd->num_active_list = 0;
|
||||||
g_free ( rmpd->active_list );
|
g_free(rmpd->active_list);
|
||||||
rmpd->active_list = NULL;
|
rmpd->active_list = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line )
|
static ModeMode script_mode_result(Mode *sw, int mretv, char **input,
|
||||||
{
|
unsigned int selected_line) {
|
||||||
ScriptModePrivateData *rmpd = (ScriptModePrivateData *) sw->private_data;
|
ScriptModePrivateData *rmpd = (ScriptModePrivateData *)sw->private_data;
|
||||||
ModeMode retv = MODE_EXIT;
|
ModeMode retv = MODE_EXIT;
|
||||||
DmenuScriptEntry *new_list = NULL;
|
DmenuScriptEntry *new_list = NULL;
|
||||||
unsigned int new_length = 0;
|
unsigned int new_length = 0;
|
||||||
|
|
||||||
if ( ( mretv & MENU_CUSTOM_COMMAND ) ) {
|
if ((mretv & MENU_CUSTOM_COMMAND)) {
|
||||||
if ( rmpd->use_hot_keys ) {
|
if (rmpd->use_hot_keys) {
|
||||||
script_mode_reset_highlight ( sw );
|
script_mode_reset_highlight(sw);
|
||||||
if ( selected_line != UINT32_MAX ) {
|
if (selected_line != UINT32_MAX) {
|
||||||
new_list = execute_executor ( sw, rmpd->cmd_list[selected_line].entry, &new_length, 10 + ( mretv & MENU_LOWER_MASK ), &( rmpd->cmd_list[selected_line] ) );
|
new_list = execute_executor(sw, rmpd->cmd_list[selected_line].entry,
|
||||||
}
|
&new_length, 10 + (mretv & MENU_LOWER_MASK),
|
||||||
else {
|
&(rmpd->cmd_list[selected_line]));
|
||||||
if ( rmpd->no_custom == FALSE ) {
|
} else {
|
||||||
new_list = execute_executor ( sw, *input, &new_length, 10 + ( mretv & MENU_LOWER_MASK ), NULL );
|
if (rmpd->no_custom == FALSE) {
|
||||||
}
|
new_list = execute_executor(sw, *input, &new_length,
|
||||||
else {
|
10 + (mretv & MENU_LOWER_MASK), NULL);
|
||||||
|
} else {
|
||||||
return RELOAD_DIALOG;
|
return RELOAD_DIALOG;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
retv = (mretv & MENU_LOWER_MASK);
|
||||||
retv = ( mretv & MENU_LOWER_MASK );
|
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
}
|
} else if ((mretv & MENU_OK) && rmpd->cmd_list[selected_line].entry != NULL) {
|
||||||
else if ( ( mretv & MENU_OK ) && rmpd->cmd_list[selected_line].entry != NULL ) {
|
if (rmpd->cmd_list[selected_line].nonselectable) {
|
||||||
if ( rmpd->cmd_list[selected_line].nonselectable ) {
|
|
||||||
return RELOAD_DIALOG;
|
return RELOAD_DIALOG;
|
||||||
}
|
}
|
||||||
script_mode_reset_highlight ( sw );
|
script_mode_reset_highlight(sw);
|
||||||
new_list = execute_executor ( sw, rmpd->cmd_list[selected_line].entry, &new_length, 1, &( rmpd->cmd_list[selected_line] ) );
|
new_list =
|
||||||
}
|
execute_executor(sw, rmpd->cmd_list[selected_line].entry, &new_length,
|
||||||
else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] != '\0' ) {
|
1, &(rmpd->cmd_list[selected_line]));
|
||||||
if ( rmpd->no_custom == FALSE ) {
|
} else if ((mretv & MENU_CUSTOM_INPUT) && *input != NULL &&
|
||||||
script_mode_reset_highlight ( sw );
|
*input[0] != '\0') {
|
||||||
new_list = execute_executor ( sw, *input, &new_length, 2, NULL );
|
if (rmpd->no_custom == FALSE) {
|
||||||
}
|
script_mode_reset_highlight(sw);
|
||||||
else {
|
new_list = execute_executor(sw, *input, &new_length, 2, NULL);
|
||||||
|
} else {
|
||||||
return RELOAD_DIALOG;
|
return RELOAD_DIALOG;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a new list was generated, use that an loop around.
|
// If a new list was generated, use that an loop around.
|
||||||
if ( new_list != NULL ) {
|
if (new_list != NULL) {
|
||||||
for ( unsigned int i = 0; i < rmpd->cmd_list_length; i++ ) {
|
for (unsigned int i = 0; i < rmpd->cmd_list_length; i++) {
|
||||||
g_free ( rmpd->cmd_list[i].entry );
|
g_free(rmpd->cmd_list[i].entry);
|
||||||
g_free ( rmpd->cmd_list[i].icon_name );
|
g_free(rmpd->cmd_list[i].icon_name);
|
||||||
g_free ( rmpd->cmd_list[i].meta );
|
g_free(rmpd->cmd_list[i].meta);
|
||||||
}
|
}
|
||||||
g_free ( rmpd->cmd_list );
|
g_free(rmpd->cmd_list);
|
||||||
|
|
||||||
rmpd->cmd_list = new_list;
|
rmpd->cmd_list = new_list;
|
||||||
rmpd->cmd_list_length = new_length;
|
rmpd->cmd_list_length = new_length;
|
||||||
@@ -336,117 +325,117 @@ static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned
|
|||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void script_mode_destroy ( Mode *sw )
|
static void script_mode_destroy(Mode *sw) {
|
||||||
{
|
ScriptModePrivateData *rmpd = (ScriptModePrivateData *)sw->private_data;
|
||||||
ScriptModePrivateData *rmpd = (ScriptModePrivateData *) sw->private_data;
|
if (rmpd != NULL) {
|
||||||
if ( rmpd != NULL ) {
|
for (unsigned int i = 0; i < rmpd->cmd_list_length; i++) {
|
||||||
for ( unsigned int i = 0; i < rmpd->cmd_list_length; i++ ) {
|
g_free(rmpd->cmd_list[i].entry);
|
||||||
g_free ( rmpd->cmd_list[i].entry );
|
g_free(rmpd->cmd_list[i].icon_name);
|
||||||
g_free ( rmpd->cmd_list[i].icon_name );
|
g_free(rmpd->cmd_list[i].meta);
|
||||||
g_free ( rmpd->cmd_list[i].meta );
|
|
||||||
}
|
}
|
||||||
g_free ( rmpd->cmd_list );
|
g_free(rmpd->cmd_list);
|
||||||
g_free ( rmpd->message );
|
g_free(rmpd->message);
|
||||||
g_free ( rmpd->prompt );
|
g_free(rmpd->prompt);
|
||||||
g_free ( rmpd->urgent_list );
|
g_free(rmpd->urgent_list);
|
||||||
g_free ( rmpd->active_list );
|
g_free(rmpd->active_list);
|
||||||
g_free ( rmpd );
|
g_free(rmpd);
|
||||||
sw->private_data = NULL;
|
sw->private_data = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static inline unsigned int get_index ( unsigned int length, int index )
|
static inline unsigned int get_index(unsigned int length, int index) {
|
||||||
{
|
if (index >= 0) {
|
||||||
if ( index >= 0 ) {
|
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
if ( ( (unsigned int) -index ) <= length ) {
|
if (((unsigned int)-index) <= length) {
|
||||||
return length + index;
|
return length + index;
|
||||||
}
|
}
|
||||||
// Out of range.
|
// Out of range.
|
||||||
return UINT_MAX;
|
return UINT_MAX;
|
||||||
}
|
}
|
||||||
static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, G_GNUC_UNUSED GList **list, int get_entry )
|
static char *_get_display_value(const Mode *sw, unsigned int selected_line,
|
||||||
{
|
G_GNUC_UNUSED int *state,
|
||||||
|
G_GNUC_UNUSED GList **list, int get_entry) {
|
||||||
ScriptModePrivateData *pd = sw->private_data;
|
ScriptModePrivateData *pd = sw->private_data;
|
||||||
for ( unsigned int i = 0; i < pd->num_active_list; i++ ) {
|
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 start =
|
||||||
unsigned int stop = get_index ( pd->cmd_list_length, pd->active_list[i].stop );
|
get_index(pd->cmd_list_length, pd->active_list[i].start);
|
||||||
if ( selected_line >= start && selected_line <= stop ) {
|
unsigned int stop = get_index(pd->cmd_list_length, pd->active_list[i].stop);
|
||||||
|
if (selected_line >= start && selected_line <= stop) {
|
||||||
*state |= ACTIVE;
|
*state |= ACTIVE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for ( unsigned int i = 0; i < pd->num_urgent_list; i++ ) {
|
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 start =
|
||||||
unsigned int stop = get_index ( pd->cmd_list_length, pd->urgent_list[i].stop );
|
get_index(pd->cmd_list_length, pd->urgent_list[i].start);
|
||||||
if ( selected_line >= start && selected_line <= stop ) {
|
unsigned int stop = get_index(pd->cmd_list_length, pd->urgent_list[i].stop);
|
||||||
|
if (selected_line >= start && selected_line <= stop) {
|
||||||
*state |= URGENT;
|
*state |= URGENT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( pd->do_markup ) {
|
if (pd->do_markup) {
|
||||||
*state |= MARKUP;
|
*state |= MARKUP;
|
||||||
}
|
}
|
||||||
return get_entry ? g_strdup ( pd->cmd_list[selected_line].entry ) : NULL;
|
return get_entry ? g_strdup(pd->cmd_list[selected_line].entry) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int script_token_match ( const Mode *sw, rofi_int_matcher **tokens, unsigned int index )
|
static int script_token_match(const Mode *sw, rofi_int_matcher **tokens,
|
||||||
{
|
unsigned int index) {
|
||||||
ScriptModePrivateData *rmpd = sw->private_data;
|
ScriptModePrivateData *rmpd = sw->private_data;
|
||||||
int match = 1;
|
int match = 1;
|
||||||
if ( tokens ) {
|
if (tokens) {
|
||||||
for ( int j = 0; match && tokens != NULL && tokens[j] != NULL; j++ ) {
|
for (int j = 0; match && tokens != NULL && tokens[j] != NULL; j++) {
|
||||||
rofi_int_matcher *ftokens[2] = { tokens[j], NULL };
|
rofi_int_matcher *ftokens[2] = {tokens[j], NULL};
|
||||||
int test = 0;
|
int test = 0;
|
||||||
test = helper_token_match ( ftokens, rmpd->cmd_list[index].entry );
|
test = helper_token_match(ftokens, rmpd->cmd_list[index].entry);
|
||||||
if ( test == tokens[j]->invert && rmpd->cmd_list[index].meta ) {
|
if (test == tokens[j]->invert && rmpd->cmd_list[index].meta) {
|
||||||
test = helper_token_match ( ftokens, rmpd->cmd_list[index].meta );
|
test = helper_token_match(ftokens, rmpd->cmd_list[index].meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( test == 0 ) {
|
if (test == 0) {
|
||||||
match = 0;
|
match = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
static char *script_get_message ( const Mode *sw )
|
static char *script_get_message(const Mode *sw) {
|
||||||
{
|
|
||||||
ScriptModePrivateData *pd = sw->private_data;
|
ScriptModePrivateData *pd = sw->private_data;
|
||||||
return g_strdup ( pd->message );
|
return g_strdup(pd->message);
|
||||||
}
|
}
|
||||||
static cairo_surface_t *script_get_icon ( const Mode *sw, unsigned int selected_line, int height )
|
static cairo_surface_t *
|
||||||
{
|
script_get_icon(const Mode *sw, unsigned int selected_line, int height) {
|
||||||
ScriptModePrivateData *pd = (ScriptModePrivateData *) mode_get_private_data ( sw );
|
ScriptModePrivateData *pd =
|
||||||
g_return_val_if_fail ( pd->cmd_list != NULL, NULL );
|
(ScriptModePrivateData *)mode_get_private_data(sw);
|
||||||
DmenuScriptEntry *dr = &( pd->cmd_list[selected_line] );
|
g_return_val_if_fail(pd->cmd_list != NULL, NULL);
|
||||||
if ( dr->icon_name == NULL ) {
|
DmenuScriptEntry *dr = &(pd->cmd_list[selected_line]);
|
||||||
|
if (dr->icon_name == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if ( dr->icon_fetch_uid > 0 ) {
|
if (dr->icon_fetch_uid > 0) {
|
||||||
return rofi_icon_fetcher_get ( dr->icon_fetch_uid );
|
return rofi_icon_fetcher_get(dr->icon_fetch_uid);
|
||||||
}
|
}
|
||||||
dr->icon_fetch_uid = rofi_icon_fetcher_query ( dr->icon_name, height );
|
dr->icon_fetch_uid = rofi_icon_fetcher_query(dr->icon_name, height);
|
||||||
return rofi_icon_fetcher_get ( dr->icon_fetch_uid );
|
return rofi_icon_fetcher_get(dr->icon_fetch_uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "mode-private.h"
|
#include "mode-private.h"
|
||||||
Mode *script_switcher_parse_setup ( const char *str )
|
Mode *script_switcher_parse_setup(const char *str) {
|
||||||
{
|
Mode *sw = g_malloc0(sizeof(*sw));
|
||||||
Mode *sw = g_malloc0 ( sizeof ( *sw ) );
|
|
||||||
char *endp = NULL;
|
char *endp = NULL;
|
||||||
char *parse = g_strdup ( str );
|
char *parse = g_strdup(str);
|
||||||
unsigned int index = 0;
|
unsigned int index = 0;
|
||||||
const char *const sep = ":";
|
const char *const sep = ":";
|
||||||
for ( char *token = strtok_r ( parse, sep, &endp ); token != NULL; token = strtok_r ( NULL, sep, &endp ) ) {
|
for (char *token = strtok_r(parse, sep, &endp); token != NULL;
|
||||||
if ( index == 0 ) {
|
token = strtok_r(NULL, sep, &endp)) {
|
||||||
sw->name = g_strdup ( token );
|
if (index == 0) {
|
||||||
}
|
sw->name = g_strdup(token);
|
||||||
else if ( index == 1 ) {
|
} else if (index == 1) {
|
||||||
sw->ed = (void *) rofi_expand_path ( token );
|
sw->ed = (void *)rofi_expand_path(token);
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
g_free ( parse );
|
g_free(parse);
|
||||||
if ( index == 2 ) {
|
if (index == 2) {
|
||||||
sw->free = script_switcher_free;
|
sw->free = script_switcher_free;
|
||||||
sw->_init = script_mode_init;
|
sw->_init = script_mode_init;
|
||||||
sw->_get_num_entries = script_mode_get_num_entries;
|
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->_token_match = script_token_match;
|
||||||
sw->_get_message = script_get_message;
|
sw->_get_message = script_get_message;
|
||||||
sw->_get_icon = script_get_icon;
|
sw->_get_icon = script_get_icon;
|
||||||
sw->_get_completion = NULL,
|
sw->_get_completion = NULL, sw->_preprocess_input = NULL,
|
||||||
sw->_preprocess_input = NULL,
|
|
||||||
sw->_get_display_value = _get_display_value;
|
sw->_get_display_value = _get_display_value;
|
||||||
|
|
||||||
return sw;
|
return sw;
|
||||||
}
|
}
|
||||||
fprintf ( stderr, "The script command '%s' has %u options, but needs 2: <name>:<script>.", str, index );
|
fprintf(
|
||||||
script_switcher_free ( sw );
|
stderr,
|
||||||
|
"The script command '%s' has %u options, but needs 2: <name>:<script>.",
|
||||||
|
str, index);
|
||||||
|
script_switcher_free(sw);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean script_switcher_is_valid ( const char *token )
|
gboolean script_switcher_is_valid(const char *token) {
|
||||||
{
|
return strchr(token, ':') != NULL;
|
||||||
return strchr ( token, ':' ) != NULL;
|
|
||||||
}
|
}
|
||||||
|
@@ -37,30 +37,29 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.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 <ctype.h>
|
||||||
|
#include <dirent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <helper.h>
|
|
||||||
#include <glob.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 "rofi.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "history.h"
|
|
||||||
#include "dialogs/ssh.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holding an ssh entry.
|
* Holding an ssh entry.
|
||||||
*/
|
*/
|
||||||
typedef struct _SshEntry
|
typedef struct _SshEntry {
|
||||||
{
|
|
||||||
/** SSH hostname */
|
/** SSH hostname */
|
||||||
char *hostname;
|
char *hostname;
|
||||||
/** SSH port number */
|
/** SSH port number */
|
||||||
@@ -69,8 +68,7 @@ typedef struct _SshEntry
|
|||||||
/**
|
/**
|
||||||
* The internal data structure holding the private data of the SSH Mode.
|
* The internal data structure holding the private data of the SSH Mode.
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
GList *user_known_hosts;
|
GList *user_known_hosts;
|
||||||
/** List if available ssh hosts.*/
|
/** List if available ssh hosts.*/
|
||||||
SshEntry *hosts_list;
|
SshEntry *hosts_list;
|
||||||
@@ -96,31 +94,28 @@ typedef struct
|
|||||||
*
|
*
|
||||||
* @returns FALSE On failure, TRUE on success
|
* @returns FALSE On failure, TRUE on success
|
||||||
*/
|
*/
|
||||||
static int execshssh ( const SshEntry *entry )
|
static int execshssh(const SshEntry *entry) {
|
||||||
{
|
|
||||||
char **args = NULL;
|
char **args = NULL;
|
||||||
int argsv = 0;
|
int argsv = 0;
|
||||||
gchar *portstr = NULL;
|
gchar *portstr = NULL;
|
||||||
if ( entry->port > 0 ) {
|
if (entry->port > 0) {
|
||||||
portstr = g_strdup_printf ( "%d", entry->port );
|
portstr = g_strdup_printf("%d", entry->port);
|
||||||
}
|
}
|
||||||
helper_parse_setup ( config.ssh_command, &args, &argsv,
|
helper_parse_setup(config.ssh_command, &args, &argsv, "{host}",
|
||||||
"{host}", entry->hostname,
|
entry->hostname, "{port}", portstr, (char *)0);
|
||||||
"{port}", portstr,
|
g_free(portstr);
|
||||||
(char *) 0 );
|
|
||||||
g_free ( portstr );
|
|
||||||
|
|
||||||
gsize l = strlen ( "Connecting to '' via rofi" ) + strlen ( entry->hostname ) + 1;
|
gsize l = strlen("Connecting to '' via rofi") + strlen(entry->hostname) + 1;
|
||||||
gchar *desc = g_newa ( gchar, l );
|
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 = {
|
RofiHelperExecuteContext context = {
|
||||||
.name = "ssh",
|
.name = "ssh",
|
||||||
.description = desc,
|
.description = desc,
|
||||||
.command = "ssh",
|
.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.
|
* SSH into the selected host, if successful update history.
|
||||||
*/
|
*/
|
||||||
static void exec_ssh ( const SshEntry *entry )
|
static void exec_ssh(const SshEntry *entry) {
|
||||||
{
|
if (!(entry->hostname) || !(entry->hostname[0])) {
|
||||||
if ( !( entry->hostname ) || !( entry->hostname[0] ) ) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !execshssh ( entry ) ) {
|
if (!execshssh(entry)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This happens in non-critical time (After launching app)
|
// This happens in non-critical time (After launching app)
|
||||||
// It is allowed to be a bit slower.
|
// 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.
|
// TODO update.
|
||||||
if ( entry->port > 0 ) {
|
if (entry->port > 0) {
|
||||||
char *store = g_strdup_printf ( "%s\x1F%d", entry->hostname, entry->port );
|
char *store = g_strdup_printf("%s\x1F%d", entry->hostname, entry->port);
|
||||||
history_set ( path, store );
|
history_set(path, store);
|
||||||
g_free ( store );
|
g_free(store);
|
||||||
|
} else {
|
||||||
|
history_set(path, entry->hostname);
|
||||||
}
|
}
|
||||||
else {
|
g_free(path);
|
||||||
history_set ( path, entry->hostname );
|
|
||||||
}
|
|
||||||
g_free ( path );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -158,14 +151,13 @@ static void exec_ssh ( const SshEntry *entry )
|
|||||||
*
|
*
|
||||||
* Remove host from history.
|
* Remove host from history.
|
||||||
*/
|
*/
|
||||||
static void delete_ssh ( const char *host )
|
static void delete_ssh(const char *host) {
|
||||||
{
|
if (!host || !host[0]) {
|
||||||
if ( !host || !host[0] ) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
char *path = g_build_filename ( cache_dir, SSH_CACHE_FILE, NULL );
|
char *path = g_build_filename(cache_dir, SSH_CACHE_FILE, NULL);
|
||||||
history_remove ( path, host );
|
history_remove(path, host);
|
||||||
g_free ( path );
|
g_free(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -177,54 +169,53 @@ static void delete_ssh ( const char *host )
|
|||||||
*
|
*
|
||||||
* @returns updated list of hosts.
|
* @returns updated list of hosts.
|
||||||
*/
|
*/
|
||||||
static SshEntry *read_known_hosts_file ( const char *path, SshEntry * retv, unsigned int *length )
|
static SshEntry *read_known_hosts_file(const char *path, SshEntry *retv,
|
||||||
{
|
unsigned int *length) {
|
||||||
FILE *fd = fopen ( path, "r" );
|
FILE *fd = fopen(path, "r");
|
||||||
if ( fd != NULL ) {
|
if (fd != NULL) {
|
||||||
char *buffer = NULL;
|
char *buffer = NULL;
|
||||||
size_t buffer_length = 0;
|
size_t buffer_length = 0;
|
||||||
// Reading one line per time.
|
// Reading one line per time.
|
||||||
while ( getline ( &buffer, &buffer_length, fd ) > 0 ) {
|
while (getline(&buffer, &buffer_length, fd) > 0) {
|
||||||
// Strip whitespace.
|
// Strip whitespace.
|
||||||
char *start = g_strstrip ( &( buffer[0] ) );
|
char *start = g_strstrip(&(buffer[0]));
|
||||||
// Find start.
|
// Find start.
|
||||||
if ( *start == '#' || *start == '@' ) {
|
if (*start == '#' || *start == '@') {
|
||||||
// skip comments or cert-authority or revoked items.
|
// skip comments or cert-authority or revoked items.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ( *start == '|' ) {
|
if (*start == '|') {
|
||||||
// Skip hashed hostnames.
|
// Skip hashed hostnames.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Find end of hostname set.
|
// Find end of hostname set.
|
||||||
char *end = strstr ( start, " " );
|
char *end = strstr(start, " ");
|
||||||
if ( end == NULL ) {
|
if (end == NULL) {
|
||||||
// Something is wrong.
|
// Something is wrong.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
*end = '\0';
|
*end = '\0';
|
||||||
char *sep = start;
|
char *sep = start;
|
||||||
start = strsep ( &sep, ", " );
|
start = strsep(&sep, ", ");
|
||||||
while ( start ) {
|
while (start) {
|
||||||
int port = 0;
|
int port = 0;
|
||||||
if ( start[0] == '[' ) {
|
if (start[0] == '[') {
|
||||||
start++;
|
start++;
|
||||||
char *end = strchr ( start, ']' );
|
char *end = strchr(start, ']');
|
||||||
if ( end[1] == ':' ) {
|
if (end[1] == ':') {
|
||||||
*end = '\0';
|
*end = '\0';
|
||||||
errno = 0;
|
errno = 0;
|
||||||
gchar *endptr = NULL;
|
gchar *endptr = NULL;
|
||||||
gint64 number = g_ascii_strtoll ( &( end[2] ), &endptr, 10 );
|
gint64 number = g_ascii_strtoll(&(end[2]), &endptr, 10);
|
||||||
if ( errno != 0 ) {
|
if (errno != 0) {
|
||||||
g_warning ( "Failed to parse port number: %s.", &( end[2] ) );
|
g_warning("Failed to parse port number: %s.", &(end[2]));
|
||||||
}
|
} else if (endptr == &(end[2])) {
|
||||||
else if ( endptr == &( end[2] ) ) {
|
g_warning("Failed to parse port number: %s, invalid number.",
|
||||||
g_warning ( "Failed to parse port number: %s, invalid number.", &( end[2] ) );
|
&(end[2]));
|
||||||
}
|
} else if (number < 0 || number > 65535) {
|
||||||
else if ( number < 0 || number > 65535 ) {
|
g_warning("Failed to parse port number: %s, out of range.",
|
||||||
g_warning ( "Failed to parse port number: %s, out of range.", &( end[2] ) );
|
&(end[2]));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
port = number;
|
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?
|
// Is this host name already in the list?
|
||||||
// We often get duplicates in hosts file, so lets check this.
|
// We often get duplicates in hosts file, so lets check this.
|
||||||
int found = 0;
|
int found = 0;
|
||||||
for ( unsigned int j = 0; j < ( *length ); j++ ) {
|
for (unsigned int j = 0; j < (*length); j++) {
|
||||||
if ( !g_ascii_strcasecmp ( start, retv[j].hostname ) ) {
|
if (!g_ascii_strcasecmp(start, retv[j].hostname)) {
|
||||||
found = 1;
|
found = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !found ) {
|
if (!found) {
|
||||||
// Add this host name to the list.
|
// Add this host name to the list.
|
||||||
retv = g_realloc ( retv, ( ( *length ) + 2 ) * sizeof ( SshEntry ) );
|
retv = g_realloc(retv, ((*length) + 2) * sizeof(SshEntry));
|
||||||
retv[( *length )].hostname = g_strdup ( start );
|
retv[(*length)].hostname = g_strdup(start);
|
||||||
retv[( *length )].port = port;
|
retv[(*length)].port = port;
|
||||||
retv[( *length ) + 1].hostname = NULL;
|
retv[(*length) + 1].hostname = NULL;
|
||||||
retv[( *length ) + 1].port = 0;
|
retv[(*length) + 1].port = 0;
|
||||||
( *length )++;
|
(*length)++;
|
||||||
}
|
}
|
||||||
start = strsep ( &sep, ", " );
|
start = strsep(&sep, ", ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( buffer != NULL ) {
|
if (buffer != NULL) {
|
||||||
free ( buffer );
|
free(buffer);
|
||||||
}
|
}
|
||||||
if ( fclose ( fd ) != 0 ) {
|
if (fclose(fd) != 0) {
|
||||||
g_warning ( "Failed to close hosts file: '%s'", g_strerror ( errno ) );
|
g_warning("Failed to close hosts file: '%s'", g_strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
g_debug("Failed to open KnownHostFile: '%s'", path);
|
||||||
g_debug ( "Failed to open KnownHostFile: '%s'", path );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return retv;
|
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.
|
* @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.
|
// Read the hosts file.
|
||||||
FILE *fd = fopen ( "/etc/hosts", "r" );
|
FILE *fd = fopen("/etc/hosts", "r");
|
||||||
if ( fd != NULL ) {
|
if (fd != NULL) {
|
||||||
char *buffer = NULL;
|
char *buffer = NULL;
|
||||||
size_t buffer_length = 0;
|
size_t buffer_length = 0;
|
||||||
// Reading one line per time.
|
// Reading one line per time.
|
||||||
while ( getline ( &buffer, &buffer_length, fd ) > 0 ) {
|
while (getline(&buffer, &buffer_length, fd) > 0) {
|
||||||
// Evaluate one line.
|
// Evaluate one line.
|
||||||
unsigned int index = 0, ti = 0;
|
unsigned int index = 0, ti = 0;
|
||||||
char *token = buffer;
|
char *token = buffer;
|
||||||
@@ -290,136 +279,133 @@ static SshEntry *read_hosts_file ( SshEntry * retv, unsigned int *length )
|
|||||||
do {
|
do {
|
||||||
char c = buffer[index];
|
char c = buffer[index];
|
||||||
// Break on space, tab, newline and \0.
|
// 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';
|
buffer[index] = '\0';
|
||||||
// Ignore empty tokens
|
// Ignore empty tokens
|
||||||
if ( token[0] != '\0' ) {
|
if (token[0] != '\0') {
|
||||||
ti++;
|
ti++;
|
||||||
// and first token.
|
// and first token.
|
||||||
if ( ti > 1 ) {
|
if (ti > 1) {
|
||||||
// Is this host name already in the list?
|
// Is this host name already in the list?
|
||||||
// We often get duplicates in hosts file, so lets check this.
|
// We often get duplicates in hosts file, so lets check this.
|
||||||
int found = 0;
|
int found = 0;
|
||||||
for ( unsigned int j = 0; j < ( *length ); j++ ) {
|
for (unsigned int j = 0; j < (*length); j++) {
|
||||||
if ( !g_ascii_strcasecmp ( token, retv[j].hostname ) ) {
|
if (!g_ascii_strcasecmp(token, retv[j].hostname)) {
|
||||||
found = 1;
|
found = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !found ) {
|
if (!found) {
|
||||||
// Add this host name to the list.
|
// Add this host name to the list.
|
||||||
retv = g_realloc ( retv,
|
retv = g_realloc(retv, ((*length) + 2) * sizeof(SshEntry));
|
||||||
( ( *length ) + 2 ) * sizeof ( SshEntry ) );
|
retv[(*length)].hostname = g_strdup(token);
|
||||||
retv[( *length )].hostname = g_strdup ( token );
|
retv[(*length)].port = 0;
|
||||||
retv[( *length )].port = 0;
|
retv[(*length) + 1].hostname = NULL;
|
||||||
retv[( *length ) + 1].hostname = NULL;
|
(*length)++;
|
||||||
( *length )++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Set start to next element.
|
// Set start to next element.
|
||||||
token = &buffer[index + 1];
|
token = &buffer[index + 1];
|
||||||
// Everything after comment ignore.
|
// Everything after comment ignore.
|
||||||
if ( c == '#' ) {
|
if (c == '#') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Skip to the next entry.
|
// Skip to the next entry.
|
||||||
index++;
|
index++;
|
||||||
} while ( buffer[index] != '\0' && buffer[index] != '#' );
|
} while (buffer[index] != '\0' && buffer[index] != '#');
|
||||||
}
|
}
|
||||||
if ( buffer != NULL ) {
|
if (buffer != NULL) {
|
||||||
free ( buffer );
|
free(buffer);
|
||||||
}
|
}
|
||||||
if ( fclose ( fd ) != 0 ) {
|
if (fclose(fd) != 0) {
|
||||||
g_warning ( "Failed to close hosts file: '%s'", g_strerror ( errno ) );
|
g_warning("Failed to close hosts file: '%s'", g_strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_known_hosts_file ( SSHModePrivateData *pd, const char *token )
|
static void add_known_hosts_file(SSHModePrivateData *pd, const char *token) {
|
||||||
{
|
GList *item =
|
||||||
GList *item = g_list_find_custom ( pd->user_known_hosts, token, (GCompareFunc) g_strcmp0 );
|
g_list_find_custom(pd->user_known_hosts, token, (GCompareFunc)g_strcmp0);
|
||||||
if ( item == NULL ) {
|
if (item == NULL) {
|
||||||
g_debug ( "Add '%s' to UserKnownHost list", token );
|
g_debug("Add '%s' to UserKnownHost list", token);
|
||||||
pd->user_known_hosts = g_list_append ( pd->user_known_hosts, g_strdup ( token ) );
|
pd->user_known_hosts = g_list_append(pd->user_known_hosts, g_strdup(token));
|
||||||
}
|
} else {
|
||||||
else {
|
g_debug("File '%s' already in UserKnownHostsFile list", token);
|
||||||
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 )
|
static void parse_ssh_config_file(SSHModePrivateData *pd, const char *filename,
|
||||||
{
|
SshEntry **retv, unsigned int *length,
|
||||||
FILE *fd = fopen ( filename, "r" );
|
unsigned int num_favorites) {
|
||||||
|
FILE *fd = fopen(filename, "r");
|
||||||
|
|
||||||
g_debug ( "Parsing ssh config file: %s", filename );
|
g_debug("Parsing ssh config file: %s", filename);
|
||||||
if ( fd != NULL ) {
|
if (fd != NULL) {
|
||||||
char *buffer = NULL;
|
char *buffer = NULL;
|
||||||
size_t buffer_length = 0;
|
size_t buffer_length = 0;
|
||||||
char *strtok_pointer = NULL;
|
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 '#'
|
// Each line is either empty, a comment line starting with a '#'
|
||||||
// character or of the form "keyword [=] arguments", where there may
|
// character or of the form "keyword [=] arguments", where there may
|
||||||
// be multiple (possibly quoted) arguments separated by whitespace.
|
// be multiple (possibly quoted) arguments separated by whitespace.
|
||||||
// The keyword is separated from its arguments by whitespace OR by
|
// The keyword is separated from its arguments by whitespace OR by
|
||||||
// optional whitespace and a '=' character.
|
// 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
|
// Skip empty lines and comment lines. Also skip lines where the
|
||||||
// keyword is not "Host".
|
// keyword is not "Host".
|
||||||
if ( !token || *token == '#' ) {
|
if (!token || *token == '#') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
char *low_token = g_ascii_strdown ( token, -1 );
|
char *low_token = g_ascii_strdown(token, -1);
|
||||||
if ( g_strcmp0 ( low_token, "include" ) == 0 ) {
|
if (g_strcmp0(low_token, "include") == 0) {
|
||||||
token = strtok_r ( NULL, SSH_TOKEN_DELIM, &strtok_pointer );
|
token = strtok_r(NULL, SSH_TOKEN_DELIM, &strtok_pointer);
|
||||||
g_debug ( "Found Include: %s", token );
|
g_debug("Found Include: %s", token);
|
||||||
gchar *path = rofi_expand_path ( token );
|
gchar *path = rofi_expand_path(token);
|
||||||
gchar *full_path = NULL;
|
gchar *full_path = NULL;
|
||||||
if ( !g_path_is_absolute ( path ) ) {
|
if (!g_path_is_absolute(path)) {
|
||||||
char *dirname = g_path_get_dirname ( filename );
|
char *dirname = g_path_get_dirname(filename);
|
||||||
full_path = g_build_filename ( dirname, path, NULL );
|
full_path = g_build_filename(dirname, path, NULL);
|
||||||
g_free ( dirname );
|
g_free(dirname);
|
||||||
|
} else {
|
||||||
|
full_path = g_strdup(path);
|
||||||
}
|
}
|
||||||
else {
|
glob_t globbuf = {.gl_pathc = 0, .gl_pathv = NULL, .gl_offs = 0};
|
||||||
full_path = g_strdup ( path );
|
|
||||||
}
|
|
||||||
glob_t globbuf = { .gl_pathc = 0, .gl_pathv = NULL, .gl_offs = 0 };
|
|
||||||
|
|
||||||
if ( glob ( full_path, 0, NULL, &globbuf ) == 0 ) {
|
if (glob(full_path, 0, NULL, &globbuf) == 0) {
|
||||||
for ( size_t iter = 0; iter < globbuf.gl_pathc; iter++ ) {
|
for (size_t iter = 0; iter < globbuf.gl_pathc; iter++) {
|
||||||
parse_ssh_config_file ( pd, globbuf.gl_pathv[iter], retv, length, num_favorites );
|
parse_ssh_config_file(pd, globbuf.gl_pathv[iter], retv, length,
|
||||||
|
num_favorites);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
globfree ( &globbuf );
|
globfree(&globbuf);
|
||||||
|
|
||||||
g_free ( full_path );
|
g_free(full_path);
|
||||||
g_free ( 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 ) {
|
} else if (g_strcmp0(low_token, "host") == 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 ) {
|
|
||||||
// Now we know that this is a "Host" line.
|
// Now we know that this is a "Host" line.
|
||||||
// The "Host" keyword is followed by one more host names separated
|
// The "Host" keyword is followed by one more host names separated
|
||||||
// by whitespace; while host names may be quoted with double quotes
|
// by whitespace; while host names may be quoted with double quotes
|
||||||
// to represent host names containing spaces, we don't support this
|
// to represent host names containing spaces, we don't support this
|
||||||
// (how many host names contain spaces?).
|
// (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.
|
// We do not want to show wildcard entries, as you cannot ssh to them.
|
||||||
const char *const sep = "*?";
|
const char *const sep = "*?";
|
||||||
if ( *token == '!' || strpbrk ( token, sep ) ) {
|
if (*token == '!' || strpbrk(token, sep)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If comment, skip from now on.
|
// If comment, skip from now on.
|
||||||
if ( *token == '#' ) {
|
if (*token == '#') {
|
||||||
break;
|
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.
|
// This is a nice little penalty, but doable? time will tell.
|
||||||
// given num_favorites is max 25.
|
// given num_favorites is max 25.
|
||||||
int found = 0;
|
int found = 0;
|
||||||
for ( unsigned int j = 0; j < num_favorites; j++ ) {
|
for (unsigned int j = 0; j < num_favorites; j++) {
|
||||||
if ( !g_ascii_strcasecmp ( token, ( *retv )[j].hostname ) ) {
|
if (!g_ascii_strcasecmp(token, (*retv)[j].hostname)) {
|
||||||
found = 1;
|
found = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( found ) {
|
if (found) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add this host name to the list.
|
// Add this host name to the list.
|
||||||
( *retv ) = g_realloc ( ( *retv ), ( ( *length ) + 2 ) * sizeof ( SshEntry ) );
|
(*retv) = g_realloc((*retv), ((*length) + 2) * sizeof(SshEntry));
|
||||||
( *retv )[( *length )].hostname = g_strdup ( token );
|
(*retv)[(*length)].hostname = g_strdup(token);
|
||||||
( *retv )[( *length )].port = 0;
|
(*retv)[(*length)].port = 0;
|
||||||
( *retv )[( *length ) + 1].hostname = NULL;
|
(*retv)[(*length) + 1].hostname = NULL;
|
||||||
( *length )++;
|
(*length)++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_free ( low_token );
|
g_free(low_token);
|
||||||
}
|
}
|
||||||
if ( buffer != NULL ) {
|
if (buffer != NULL) {
|
||||||
free ( buffer );
|
free(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( fclose ( fd ) != 0 ) {
|
if (fclose(fd) != 0) {
|
||||||
g_warning ( "Failed to close ssh configuration file: '%s'", g_strerror ( errno ) );
|
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.
|
* @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;
|
SshEntry *retv = NULL;
|
||||||
unsigned int num_favorites = 0;
|
unsigned int num_favorites = 0;
|
||||||
char *path;
|
char *path;
|
||||||
|
|
||||||
if ( g_get_home_dir () == NULL ) {
|
if (g_get_home_dir() == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
path = g_build_filename ( cache_dir, SSH_CACHE_FILE, NULL );
|
path = g_build_filename(cache_dir, SSH_CACHE_FILE, NULL);
|
||||||
char **h = history_get_list ( path, length );
|
char **h = history_get_list(path, length);
|
||||||
|
|
||||||
retv = malloc ( ( *length ) * sizeof ( SshEntry ) );
|
retv = malloc((*length) * sizeof(SshEntry));
|
||||||
for ( unsigned int i = 0; i < ( *length ); i++ ) {
|
for (unsigned int i = 0; i < (*length); i++) {
|
||||||
int port = 0;
|
int port = 0;
|
||||||
char *portstr = strchr ( h[i], '\x1F' );
|
char *portstr = strchr(h[i], '\x1F');
|
||||||
if ( portstr != NULL ) {
|
if (portstr != NULL) {
|
||||||
*portstr = '\0';
|
*portstr = '\0';
|
||||||
errno = 0;
|
errno = 0;
|
||||||
gchar *endptr = NULL;
|
gchar *endptr = NULL;
|
||||||
gint64 number = g_ascii_strtoll ( &( portstr[1] ), &endptr, 10 );
|
gint64 number = g_ascii_strtoll(&(portstr[1]), &endptr, 10);
|
||||||
if ( errno != 0 ) {
|
if (errno != 0) {
|
||||||
g_warning ( "Failed to parse port number: %s.", &( portstr[1] ) );
|
g_warning("Failed to parse port number: %s.", &(portstr[1]));
|
||||||
}
|
} else if (endptr == &(portstr[1])) {
|
||||||
else if ( endptr == &( portstr[1] ) ) {
|
g_warning("Failed to parse port number: %s, invalid number.",
|
||||||
g_warning ( "Failed to parse port number: %s, invalid number.", &( portstr[1] ) );
|
&(portstr[1]));
|
||||||
}
|
} else if (number < 0 || number > 65535) {
|
||||||
else if ( number < 0 || number > 65535 ) {
|
g_warning("Failed to parse port number: %s, out of range.",
|
||||||
g_warning ( "Failed to parse port number: %s, out of range.", &( portstr[1] ) );
|
&(portstr[1]));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
port = number;
|
port = number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
retv[i].hostname = h[i];
|
retv[i].hostname = h[i];
|
||||||
retv[i].port = port;
|
retv[i].port = port;
|
||||||
}
|
}
|
||||||
g_free ( h );
|
g_free(h);
|
||||||
|
|
||||||
g_free ( path );
|
g_free(path);
|
||||||
num_favorites = ( *length );
|
num_favorites = (*length);
|
||||||
|
|
||||||
const char *hd = g_get_home_dir ();
|
const char *hd = g_get_home_dir();
|
||||||
path = g_build_filename ( hd, ".ssh", "config", NULL );
|
path = g_build_filename(hd, ".ssh", "config", NULL);
|
||||||
parse_ssh_config_file ( pd, path, &retv, length, num_favorites );
|
parse_ssh_config_file(pd, path, &retv, length, num_favorites);
|
||||||
|
|
||||||
if ( config.parse_known_hosts == TRUE ) {
|
if (config.parse_known_hosts == TRUE) {
|
||||||
char *path = g_build_filename ( g_get_home_dir (), ".ssh", "known_hosts", NULL );
|
char *path =
|
||||||
retv = read_known_hosts_file ( path, retv, length );
|
g_build_filename(g_get_home_dir(), ".ssh", "known_hosts", NULL);
|
||||||
g_free ( path );
|
retv = read_known_hosts_file(path, retv, length);
|
||||||
for ( GList *iter = g_list_first ( pd->user_known_hosts ); iter; iter = g_list_next ( iter ) ) {
|
g_free(path);
|
||||||
char *path = rofi_expand_path ( (const char *) iter->data );
|
for (GList *iter = g_list_first(pd->user_known_hosts); iter;
|
||||||
retv = read_known_hosts_file ( (const char *) path, retv, length );
|
iter = g_list_next(iter)) {
|
||||||
g_free ( path );
|
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 ) {
|
if (config.parse_hosts == TRUE) {
|
||||||
retv = read_hosts_file ( retv, length );
|
retv = read_hosts_file(retv, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free ( path );
|
g_free(path);
|
||||||
|
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
@@ -538,12 +525,11 @@ static SshEntry * get_ssh ( SSHModePrivateData *pd, unsigned int *length )
|
|||||||
* Initializes the SSH Mode private data object and
|
* Initializes the SSH Mode private data object and
|
||||||
* loads the relevant ssh information.
|
* loads the relevant ssh information.
|
||||||
*/
|
*/
|
||||||
static int ssh_mode_init ( Mode *sw )
|
static int ssh_mode_init(Mode *sw) {
|
||||||
{
|
if (mode_get_private_data(sw) == NULL) {
|
||||||
if ( mode_get_private_data ( sw ) == NULL ) {
|
SSHModePrivateData *pd = g_malloc0(sizeof(*pd));
|
||||||
SSHModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
|
mode_set_private_data(sw, (void *)pd);
|
||||||
mode_set_private_data ( sw, (void *) pd );
|
pd->hosts_list = get_ssh(pd, &(pd->hosts_list_length));
|
||||||
pd->hosts_list = get_ssh ( pd, &( pd->hosts_list_length ) );
|
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -555,27 +541,27 @@ static int ssh_mode_init ( Mode *sw )
|
|||||||
*
|
*
|
||||||
* @returns the number of ssh entries.
|
* @returns the number of ssh entries.
|
||||||
*/
|
*/
|
||||||
static unsigned int ssh_mode_get_num_entries ( const Mode *sw )
|
static unsigned int ssh_mode_get_num_entries(const Mode *sw) {
|
||||||
{
|
const SSHModePrivateData *rmpd =
|
||||||
const SSHModePrivateData *rmpd = (const SSHModePrivateData *) mode_get_private_data ( sw );
|
(const SSHModePrivateData *)mode_get_private_data(sw);
|
||||||
return rmpd->hosts_list_length;
|
return rmpd->hosts_list_length;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param sw Object handle to the SSH Mode object
|
* @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 )
|
static void ssh_mode_destroy(Mode *sw) {
|
||||||
{
|
SSHModePrivateData *rmpd = (SSHModePrivateData *)mode_get_private_data(sw);
|
||||||
SSHModePrivateData *rmpd = (SSHModePrivateData *) mode_get_private_data ( sw );
|
if (rmpd != NULL) {
|
||||||
if ( rmpd != NULL ) {
|
for (unsigned int i = 0; i < rmpd->hosts_list_length; i++) {
|
||||||
for ( unsigned int i = 0; i < rmpd->hosts_list_length; i++ ) {
|
g_free(rmpd->hosts_list[i].hostname);
|
||||||
g_free ( rmpd->hosts_list[i].hostname );
|
|
||||||
}
|
}
|
||||||
g_list_free_full ( rmpd->user_known_hosts, g_free );
|
g_list_free_full(rmpd->user_known_hosts, g_free);
|
||||||
g_free ( rmpd->hosts_list );
|
g_free(rmpd->hosts_list);
|
||||||
g_free ( rmpd );
|
g_free(rmpd);
|
||||||
mode_set_private_data ( sw, NULL );
|
mode_set_private_data(sw, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -589,26 +575,25 @@ static void ssh_mode_destroy ( Mode *sw )
|
|||||||
*
|
*
|
||||||
* @returns the next #ModeMode.
|
* @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;
|
ModeMode retv = MODE_EXIT;
|
||||||
SSHModePrivateData *rmpd = (SSHModePrivateData *) mode_get_private_data ( sw );
|
SSHModePrivateData *rmpd = (SSHModePrivateData *)mode_get_private_data(sw);
|
||||||
if ( ( mretv & MENU_OK ) && rmpd->hosts_list[selected_line].hostname != NULL ) {
|
if ((mretv & MENU_OK) && rmpd->hosts_list[selected_line].hostname != NULL) {
|
||||||
exec_ssh ( &( rmpd->hosts_list[selected_line] ) );
|
exec_ssh(&(rmpd->hosts_list[selected_line]));
|
||||||
}
|
} else if ((mretv & MENU_CUSTOM_INPUT) && *input != NULL &&
|
||||||
else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] != '\0' ) {
|
*input[0] != '\0') {
|
||||||
SshEntry entry = { .hostname = *input, .port = 0 };
|
SshEntry entry = {.hostname = *input, .port = 0};
|
||||||
exec_ssh ( &entry );
|
exec_ssh(&entry);
|
||||||
}
|
} else if ((mretv & MENU_ENTRY_DELETE) &&
|
||||||
else if ( ( mretv & MENU_ENTRY_DELETE ) && rmpd->hosts_list[selected_line].hostname ) {
|
rmpd->hosts_list[selected_line].hostname) {
|
||||||
delete_ssh ( rmpd->hosts_list[selected_line].hostname );
|
delete_ssh(rmpd->hosts_list[selected_line].hostname);
|
||||||
// Stay
|
// Stay
|
||||||
retv = RELOAD_DIALOG;
|
retv = RELOAD_DIALOG;
|
||||||
ssh_mode_destroy ( sw );
|
ssh_mode_destroy(sw);
|
||||||
ssh_mode_init ( sw );
|
ssh_mode_init(sw);
|
||||||
}
|
} else if (mretv & MENU_CUSTOM_COMMAND) {
|
||||||
else if ( mretv & MENU_CUSTOM_COMMAND ) {
|
retv = (mretv & MENU_LOWER_MASK);
|
||||||
retv = ( mretv & MENU_LOWER_MASK );
|
|
||||||
}
|
}
|
||||||
return retv;
|
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.
|
* @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 )
|
static char *_get_display_value(const Mode *sw, unsigned int selected_line,
|
||||||
{
|
G_GNUC_UNUSED int *state,
|
||||||
SSHModePrivateData *rmpd = (SSHModePrivateData *) mode_get_private_data ( sw );
|
G_GNUC_UNUSED GList **attr_list,
|
||||||
return get_entry ? g_strdup ( rmpd->hosts_list[selected_line].hostname ) : NULL;
|
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
|
* @returns TRUE if matches
|
||||||
*/
|
*/
|
||||||
static int ssh_token_match ( const Mode *sw, rofi_int_matcher **tokens, unsigned int index )
|
static int ssh_token_match(const Mode *sw, rofi_int_matcher **tokens,
|
||||||
{
|
unsigned int index) {
|
||||||
SSHModePrivateData *rmpd = (SSHModePrivateData *) mode_get_private_data ( sw );
|
SSHModePrivateData *rmpd = (SSHModePrivateData *)mode_get_private_data(sw);
|
||||||
return helper_token_match ( tokens, rmpd->hosts_list[index].hostname );
|
return helper_token_match(tokens, rmpd->hosts_list[index].hostname);
|
||||||
}
|
}
|
||||||
#include "mode-private.h"
|
#include "mode-private.h"
|
||||||
Mode ssh_mode =
|
Mode ssh_mode = {.name = "ssh",
|
||||||
{
|
|
||||||
.name = "ssh",
|
|
||||||
.cfg_name_key = "display-ssh",
|
.cfg_name_key = "display-ssh",
|
||||||
._init = ssh_mode_init,
|
._init = ssh_mode_init,
|
||||||
._get_num_entries = ssh_mode_get_num_entries,
|
._get_num_entries = ssh_mode_get_num_entries,
|
||||||
@@ -659,6 +644,5 @@ Mode ssh_mode =
|
|||||||
._get_completion = NULL,
|
._get_completion = NULL,
|
||||||
._preprocess_input = NULL,
|
._preprocess_input = NULL,
|
||||||
.private_data = NULL,
|
.private_data = NULL,
|
||||||
.free = NULL
|
.free = NULL};
|
||||||
};
|
|
||||||
/**@}*/
|
/**@}*/
|
||||||
|
File diff suppressed because it is too large
Load Diff
1258
source/helper.c
1258
source/helper.c
File diff suppressed because it is too large
Load Diff
253
source/history.c
253
source/history.c
@@ -25,171 +25,173 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include "history.h"
|
||||||
#include <stdlib.h>
|
#include "rofi.h"
|
||||||
#include <stdio.h>
|
#include "settings.h"
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <glib/gstdio.h>
|
#include <glib/gstdio.h>
|
||||||
#include "rofi.h"
|
#include <stdio.h>
|
||||||
#include "history.h"
|
#include <stdlib.h>
|
||||||
#include "settings.h"
|
#include <string.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* History element
|
* History element
|
||||||
*/
|
*/
|
||||||
typedef struct __element
|
typedef struct __element {
|
||||||
{
|
|
||||||
/** Index in history */
|
/** Index in history */
|
||||||
long int index;
|
long int index;
|
||||||
/** Entry */
|
/** Entry */
|
||||||
char *name;
|
char *name;
|
||||||
}_element;
|
} _element;
|
||||||
|
|
||||||
static int __element_sort_func ( const void *ea, const void *eb, void *data __attribute__( ( unused ) ) )
|
static int __element_sort_func(const void *ea, const void *eb,
|
||||||
{
|
void *data __attribute__((unused))) {
|
||||||
_element *a = *(_element * *) ea;
|
_element *a = *(_element **)ea;
|
||||||
_element *b = *(_element * *) eb;
|
_element *b = *(_element **)eb;
|
||||||
return b->index - a->index;
|
return b->index - a->index;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __history_write_element_list ( FILE *fd, _element **list, unsigned int length )
|
static void __history_write_element_list(FILE *fd, _element **list,
|
||||||
{
|
unsigned int length) {
|
||||||
if ( list == NULL || length == 0 ) {
|
if (list == NULL || length == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Sort the list before writing out.
|
// Sort the list before writing out.
|
||||||
g_qsort_with_data ( list, length, sizeof ( _element* ), __element_sort_func, NULL );
|
g_qsort_with_data(list, length, sizeof(_element *), __element_sort_func,
|
||||||
|
NULL);
|
||||||
|
|
||||||
// Get minimum index.
|
// Get minimum index.
|
||||||
int min_value = list[length - 1]->index;
|
int min_value = list[length - 1]->index;
|
||||||
|
|
||||||
// Set the max length of the list.
|
// Set the max length of the list.
|
||||||
length = ( length > config.max_history_size ) ? config.max_history_size : length;
|
length =
|
||||||
|
(length > config.max_history_size) ? config.max_history_size : length;
|
||||||
|
|
||||||
// Write out entries.
|
// Write out entries.
|
||||||
for ( unsigned int iter = 0; iter < length; iter++ ) {
|
for (unsigned int iter = 0; iter < length; iter++) {
|
||||||
fprintf ( fd, "%ld %s\n", list[iter]->index - min_value, list[iter]->name );
|
fprintf(fd, "%ld %s\n", list[iter]->index - min_value, list[iter]->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static char ** __history_get_element_list_fields ( FILE *fd, unsigned int *length )
|
static char **__history_get_element_list_fields(FILE *fd,
|
||||||
{
|
unsigned int *length) {
|
||||||
unsigned int real_length = 0;
|
unsigned int real_length = 0;
|
||||||
char **retv = NULL;;
|
char **retv = NULL;
|
||||||
if ( length == NULL ) {
|
;
|
||||||
|
if (length == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
*length = 0;
|
*length = 0;
|
||||||
|
|
||||||
if ( fd == NULL ) {
|
if (fd == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
char *buffer = NULL;
|
char *buffer = NULL;
|
||||||
size_t buffer_length = 0;
|
size_t buffer_length = 0;
|
||||||
ssize_t l = 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.
|
// Jump to the first space.
|
||||||
const char *start = strchr ( buffer, ' ' );
|
const char *start = strchr(buffer, ' ');
|
||||||
// not found, skip.
|
// not found, skip.
|
||||||
if ( start == NULL ) {
|
if (start == NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
start++;
|
start++;
|
||||||
// remove trailing \n
|
// remove trailing \n
|
||||||
buffer[l - 1] = '\0';
|
buffer[l - 1] = '\0';
|
||||||
if ( real_length < ( *length + 2 ) ) {
|
if (real_length < (*length + 2)) {
|
||||||
real_length += 15;
|
real_length += 15;
|
||||||
// Resize and check.
|
// Resize and check.
|
||||||
retv = g_realloc ( retv, ( real_length ) * sizeof ( char* ) );
|
retv = g_realloc(retv, (real_length) * sizeof(char *));
|
||||||
}
|
}
|
||||||
// Parse the number of times.
|
// 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'
|
// Force trailing '\0'
|
||||||
retv[( *length ) + 1] = NULL;
|
retv[(*length) + 1] = NULL;
|
||||||
|
|
||||||
( *length )++;
|
(*length)++;
|
||||||
}
|
}
|
||||||
if ( buffer_length > 0 ) {
|
if (buffer_length > 0) {
|
||||||
g_free ( buffer );
|
g_free(buffer);
|
||||||
}
|
}
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static _element ** __history_get_element_list ( FILE *fd, unsigned int *length )
|
static _element **__history_get_element_list(FILE *fd, unsigned int *length) {
|
||||||
{
|
|
||||||
unsigned int real_length = 0;
|
unsigned int real_length = 0;
|
||||||
_element **retv = NULL;
|
_element **retv = NULL;
|
||||||
|
|
||||||
if ( length == NULL ) {
|
if (length == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
*length = 0;
|
*length = 0;
|
||||||
|
|
||||||
if ( fd == NULL ) {
|
if (fd == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
char *buffer = NULL;
|
char *buffer = NULL;
|
||||||
size_t buffer_length = 0;
|
size_t buffer_length = 0;
|
||||||
ssize_t l = 0;
|
ssize_t l = 0;
|
||||||
while ( ( l = getline ( &buffer, &buffer_length, fd ) ) > 0 ) {
|
while ((l = getline(&buffer, &buffer_length, fd)) > 0) {
|
||||||
char * start = NULL;
|
char *start = NULL;
|
||||||
// Skip empty lines.
|
// Skip empty lines.
|
||||||
if ( l <= 1 ) {
|
if (l <= 1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
long int index = strtol ( buffer, &start, 10 );
|
long int index = strtol(buffer, &start, 10);
|
||||||
if ( start == buffer || *start == '\0' ) {
|
if (start == buffer || *start == '\0') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
start++;
|
start++;
|
||||||
if ( ( l - ( start - buffer ) ) < 2 ) {
|
if ((l - (start - buffer)) < 2) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ( real_length < ( *length + 2 ) ) {
|
if (real_length < (*length + 2)) {
|
||||||
real_length += 15;
|
real_length += 15;
|
||||||
// Resize and check.
|
// 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
|
// remove trailing \n
|
||||||
buffer[l - 1] = '\0';
|
buffer[l - 1] = '\0';
|
||||||
// Parse the number of times.
|
// Parse the number of times.
|
||||||
retv[( *length )]->index = index;
|
retv[(*length)]->index = index;
|
||||||
retv[( *length )]->name = g_strndup ( start, l - 1 - ( start - buffer ) );
|
retv[(*length)]->name = g_strndup(start, l - 1 - (start - buffer));
|
||||||
// Force trailing '\0'
|
// Force trailing '\0'
|
||||||
retv[( *length ) + 1] = NULL;
|
retv[(*length) + 1] = NULL;
|
||||||
|
|
||||||
( *length )++;
|
(*length)++;
|
||||||
}
|
}
|
||||||
if ( buffer != NULL ) {
|
if (buffer != NULL) {
|
||||||
free ( buffer );
|
free(buffer);
|
||||||
buffer = NULL;
|
buffer = NULL;
|
||||||
}
|
}
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
|
|
||||||
void history_set ( const char *filename, const char *entry )
|
void history_set(const char *filename, const char *entry) {
|
||||||
{
|
if (config.disable_history) {
|
||||||
if ( config.disable_history ) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if program should be ignored
|
// 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
|
// For each ignored prefix
|
||||||
|
|
||||||
while ( g_unichar_isspace ( g_utf8_get_char ( checked_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.
|
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -199,35 +201,34 @@ void history_set ( const char *filename, const char *entry )
|
|||||||
unsigned int length = 0;
|
unsigned int length = 0;
|
||||||
_element **list = NULL;
|
_element **list = NULL;
|
||||||
// Open file for reading and writing.
|
// Open file for reading and writing.
|
||||||
FILE *fd = g_fopen ( filename, "r" );
|
FILE *fd = g_fopen(filename, "r");
|
||||||
if ( fd != NULL ) {
|
if (fd != NULL) {
|
||||||
// Get list.
|
// Get list.
|
||||||
list = __history_get_element_list ( fd, &length );
|
list = __history_get_element_list(fd, &length);
|
||||||
// Close file, if fails let user know on stderr.
|
// Close file, if fails let user know on stderr.
|
||||||
if ( fclose ( fd ) != 0 ) {
|
if (fclose(fd) != 0) {
|
||||||
g_warning ( "Failed to close history file: %s", g_strerror ( errno ) );
|
g_warning("Failed to close history file: %s", g_strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Look if the entry exists.
|
// Look if the entry exists.
|
||||||
for ( unsigned int iter = 0; !found && iter < length; iter++ ) {
|
for (unsigned int iter = 0; !found && iter < length; iter++) {
|
||||||
if ( strcmp ( list[iter]->name, entry ) == 0 ) {
|
if (strcmp(list[iter]->name, entry) == 0) {
|
||||||
curr = iter;
|
curr = iter;
|
||||||
found = 1;
|
found = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( found ) {
|
if (found) {
|
||||||
// If exists, increment list index number
|
// If exists, increment list index number
|
||||||
list[curr]->index++;
|
list[curr]->index++;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
// If not exists, add it.
|
// If not exists, add it.
|
||||||
// Increase list by one
|
// Increase list by one
|
||||||
list = g_realloc ( list, ( length + 2 ) * sizeof ( _element* ) );
|
list = g_realloc(list, (length + 2) * sizeof(_element *));
|
||||||
list[length] = g_malloc ( sizeof ( _element ) );
|
list[length] = g_malloc(sizeof(_element));
|
||||||
// Copy name
|
// Copy name
|
||||||
if ( list[length] != NULL ) {
|
if (list[length] != NULL) {
|
||||||
list[length]->name = g_strdup ( entry );
|
list[length]->name = g_strdup(entry);
|
||||||
// set # hits
|
// set # hits
|
||||||
list[length]->index = 1;
|
list[length]->index = 1;
|
||||||
|
|
||||||
@@ -236,116 +237,112 @@ void history_set ( const char *filename, const char *entry )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = fopen ( filename, "w" );
|
fd = fopen(filename, "w");
|
||||||
if ( fd == NULL ) {
|
if (fd == NULL) {
|
||||||
g_warning ( "Failed to open file: %s", g_strerror ( errno ) );
|
g_warning("Failed to open file: %s", g_strerror(errno));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Write list.
|
// 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.
|
// Close file, if fails let user know on stderr.
|
||||||
if ( fclose ( fd ) != 0 ) {
|
if (fclose(fd) != 0) {
|
||||||
g_warning ( "Failed to close history file: %s", g_strerror ( errno ) );
|
g_warning("Failed to close history file: %s", g_strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Free the list.
|
// Free the list.
|
||||||
for ( unsigned int iter = 0; iter < length; iter++ ) {
|
for (unsigned int iter = 0; iter < length; iter++) {
|
||||||
g_free ( list[iter]->name );
|
g_free(list[iter]->name);
|
||||||
g_free ( list[iter] );
|
g_free(list[iter]);
|
||||||
}
|
}
|
||||||
g_free ( list );
|
g_free(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
void history_remove ( const char *filename, const char *entry )
|
void history_remove(const char *filename, const char *entry) {
|
||||||
{
|
if (config.disable_history) {
|
||||||
if ( config.disable_history ) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_element ** list = NULL;
|
_element **list = NULL;
|
||||||
int found = 0;
|
int found = 0;
|
||||||
unsigned int curr = 0;
|
unsigned int curr = 0;
|
||||||
unsigned int length = 0;
|
unsigned int length = 0;
|
||||||
// Open file for reading and writing.
|
// Open file for reading and writing.
|
||||||
FILE *fd = g_fopen ( filename, "r" );
|
FILE *fd = g_fopen(filename, "r");
|
||||||
if ( fd == NULL ) {
|
if (fd == NULL) {
|
||||||
g_warning ( "Failed to open file: %s", g_strerror ( errno ) );
|
g_warning("Failed to open file: %s", g_strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Get list.
|
// Get list.
|
||||||
list = __history_get_element_list ( fd, &length );
|
list = __history_get_element_list(fd, &length);
|
||||||
|
|
||||||
// Close file, if fails let user know on stderr.
|
// Close file, if fails let user know on stderr.
|
||||||
if ( fclose ( fd ) != 0 ) {
|
if (fclose(fd) != 0) {
|
||||||
g_warning ( "Failed to close history file: %s", g_strerror ( errno ) );
|
g_warning("Failed to close history file: %s", g_strerror(errno));
|
||||||
}
|
}
|
||||||
// Find entry.
|
// Find entry.
|
||||||
for ( unsigned int iter = 0; !found && iter < length; iter++ ) {
|
for (unsigned int iter = 0; !found && iter < length; iter++) {
|
||||||
if ( strcmp ( list[iter]->name, entry ) == 0 ) {
|
if (strcmp(list[iter]->name, entry) == 0) {
|
||||||
curr = iter;
|
curr = iter;
|
||||||
found = 1;
|
found = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If found, remove it and write out new file.
|
// If found, remove it and write out new file.
|
||||||
if ( found ) {
|
if (found) {
|
||||||
// Remove the entry.
|
// Remove the entry.
|
||||||
g_free ( list[curr]->name );
|
g_free(list[curr]->name);
|
||||||
g_free ( list[curr] );
|
g_free(list[curr]);
|
||||||
// Swap last to here (if list is size 1, we just swap empty sets).
|
// Swap last to here (if list is size 1, we just swap empty sets).
|
||||||
list[curr] = list[length - 1];
|
list[curr] = list[length - 1];
|
||||||
// Empty last.
|
// Empty last.
|
||||||
list[length - 1] = NULL;
|
list[length - 1] = NULL;
|
||||||
length--;
|
length--;
|
||||||
|
|
||||||
fd = g_fopen ( filename, "w" );
|
fd = g_fopen(filename, "w");
|
||||||
// Clear list.
|
// Clear list.
|
||||||
if ( fd != NULL ) {
|
if (fd != NULL) {
|
||||||
// Write list.
|
// 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.
|
// Close file, if fails let user know on stderr.
|
||||||
if ( fclose ( fd ) != 0 ) {
|
if (fclose(fd) != 0) {
|
||||||
g_warning ( "Failed to close history file: %s", g_strerror ( errno ) );
|
g_warning("Failed to close history file: %s", g_strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else{
|
g_warning("Failed to open file: %s", g_strerror(errno));
|
||||||
g_warning ( "Failed to open file: %s", g_strerror ( errno ) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free the list.
|
// Free the list.
|
||||||
for ( unsigned int iter = 0; iter < length; iter++ ) {
|
for (unsigned int iter = 0; iter < length; iter++) {
|
||||||
g_free ( list[iter]->name );
|
g_free(list[iter]->name);
|
||||||
g_free ( list[iter] );
|
g_free(list[iter]);
|
||||||
}
|
}
|
||||||
if ( list != NULL ) {
|
if (list != NULL) {
|
||||||
g_free ( list );
|
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;
|
*length = 0;
|
||||||
|
|
||||||
if ( config.disable_history ) {
|
if (config.disable_history) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
char **retv = NULL;
|
char **retv = NULL;
|
||||||
// Open file.
|
// Open file.
|
||||||
FILE *fd = g_fopen ( filename, "r" );
|
FILE *fd = g_fopen(filename, "r");
|
||||||
if ( fd == NULL ) {
|
if (fd == NULL) {
|
||||||
// File that does not exists is not an error, so ignore it.
|
// File that does not exists is not an error, so ignore it.
|
||||||
// Everything else? panic.
|
// Everything else? panic.
|
||||||
if ( errno != ENOENT ) {
|
if (errno != ENOENT) {
|
||||||
g_warning ( "Failed to open file: %s", g_strerror ( errno ) );
|
g_warning("Failed to open file: %s", g_strerror(errno));
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
// Get list.
|
// 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.
|
// Close file, if fails let user know on stderr.
|
||||||
if ( fclose ( fd ) != 0 ) {
|
if (fclose(fd) != 0) {
|
||||||
g_warning ( "Failed to close history file: %s", g_strerror ( errno ) );
|
g_warning("Failed to close history file: %s", g_strerror(errno));
|
||||||
}
|
}
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
|
@@ -25,7 +25,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include "config.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "rofi.h"
|
#include "rofi.h"
|
||||||
#include "nkutils-bindings.h"
|
#include "nkutils-bindings.h"
|
||||||
|
174
source/mode.c
174
source/mode.c
@@ -25,12 +25,12 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include "mode.h"
|
||||||
#include <glib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "rofi.h"
|
#include "rofi.h"
|
||||||
#include "xrmoptions.h"
|
#include "xrmoptions.h"
|
||||||
#include "mode.h"
|
#include <glib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
// This one should only be in mode implementations.
|
// This one should only be in mode implementations.
|
||||||
#include "mode-private.h"
|
#include "mode-private.h"
|
||||||
@@ -39,152 +39,140 @@
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int mode_init ( Mode *mode )
|
int mode_init(Mode *mode) {
|
||||||
{
|
g_return_val_if_fail(mode != NULL, FALSE);
|
||||||
g_return_val_if_fail ( mode != NULL, FALSE );
|
g_return_val_if_fail(mode->_init != NULL, FALSE);
|
||||||
g_return_val_if_fail ( mode->_init != NULL, FALSE );
|
return mode->_init(mode);
|
||||||
return mode->_init ( mode );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void mode_destroy ( Mode *mode )
|
void mode_destroy(Mode *mode) {
|
||||||
{
|
g_assert(mode != NULL);
|
||||||
g_assert ( mode != NULL );
|
g_assert(mode->_destroy != NULL);
|
||||||
g_assert ( mode->_destroy != NULL );
|
mode->_destroy(mode);
|
||||||
mode->_destroy ( mode );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int mode_get_num_entries ( const Mode *mode )
|
unsigned int mode_get_num_entries(const Mode *mode) {
|
||||||
{
|
g_assert(mode != NULL);
|
||||||
g_assert ( mode != NULL );
|
g_assert(mode->_get_num_entries != NULL);
|
||||||
g_assert ( mode->_get_num_entries != NULL );
|
return mode->_get_num_entries(mode);
|
||||||
return mode->_get_num_entries ( mode );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char * mode_get_display_value ( const Mode *mode, unsigned int selected_line, int *state, GList **attribute_list, int get_entry )
|
char *mode_get_display_value(const Mode *mode, unsigned int selected_line,
|
||||||
{
|
int *state, GList **attribute_list,
|
||||||
g_assert ( mode != NULL );
|
int get_entry) {
|
||||||
g_assert ( state != NULL );
|
g_assert(mode != NULL);
|
||||||
g_assert ( mode->_get_display_value != NULL );
|
g_assert(state != NULL);
|
||||||
|
g_assert(mode->_get_display_value != NULL);
|
||||||
|
|
||||||
return mode->_get_display_value ( mode, selected_line, state, attribute_list, get_entry );
|
return mode->_get_display_value(mode, selected_line, state, attribute_list,
|
||||||
|
get_entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
cairo_surface_t * mode_get_icon ( const Mode *mode, unsigned int selected_line, int height )
|
cairo_surface_t *mode_get_icon(const Mode *mode, unsigned int selected_line,
|
||||||
{
|
int height) {
|
||||||
g_assert ( mode != NULL );
|
g_assert(mode != NULL);
|
||||||
|
|
||||||
if ( mode->_get_icon != NULL ) {
|
if (mode->_get_icon != NULL) {
|
||||||
return mode->_get_icon ( mode, selected_line, height );
|
return mode->_get_icon(mode, selected_line, height);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char * mode_get_completion ( const Mode *mode, unsigned int selected_line )
|
char *mode_get_completion(const Mode *mode, unsigned int selected_line) {
|
||||||
{
|
g_assert(mode != NULL);
|
||||||
g_assert ( mode != NULL );
|
if (mode->_get_completion != NULL) {
|
||||||
if ( mode->_get_completion != NULL ) {
|
return mode->_get_completion(mode, selected_line);
|
||||||
return mode->_get_completion ( mode, selected_line );
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
int state;
|
int state;
|
||||||
g_assert ( mode->_get_display_value != NULL );
|
g_assert(mode->_get_display_value != NULL);
|
||||||
return mode->_get_display_value ( mode, selected_line, &state, NULL, TRUE );
|
return mode->_get_display_value(mode, selected_line, &state, NULL, TRUE);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ModeMode mode_result ( Mode *mode, int menu_retv, char **input, unsigned int selected_line )
|
ModeMode mode_result(Mode *mode, int menu_retv, char **input,
|
||||||
{
|
unsigned int selected_line) {
|
||||||
if ( menu_retv & MENU_NEXT ) {
|
if (menu_retv & MENU_NEXT) {
|
||||||
return NEXT_DIALOG;
|
return NEXT_DIALOG;
|
||||||
}
|
}
|
||||||
else if ( menu_retv & MENU_PREVIOUS ) {
|
if (menu_retv & MENU_PREVIOUS) {
|
||||||
return PREVIOUS_DIALOG;
|
return PREVIOUS_DIALOG;
|
||||||
}
|
}
|
||||||
else if ( menu_retv & MENU_QUICK_SWITCH ) {
|
if (menu_retv & MENU_QUICK_SWITCH) {
|
||||||
return menu_retv & MENU_LOWER_MASK;
|
return menu_retv & MENU_LOWER_MASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_assert ( mode != NULL );
|
g_assert(mode != NULL);
|
||||||
g_assert ( mode->_result != NULL );
|
g_assert(mode->_result != NULL);
|
||||||
g_assert ( input != NULL );
|
g_assert(input != NULL);
|
||||||
|
|
||||||
return mode->_result ( mode, menu_retv, input, selected_line );
|
return mode->_result(mode, menu_retv, input, selected_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
int mode_token_match ( const Mode *mode, rofi_int_matcher **tokens, unsigned int selected_line )
|
int mode_token_match(const Mode *mode, rofi_int_matcher **tokens,
|
||||||
{
|
unsigned int selected_line) {
|
||||||
g_assert ( mode != NULL );
|
g_assert(mode != NULL);
|
||||||
g_assert ( mode->_token_match != NULL );
|
g_assert(mode->_token_match != NULL);
|
||||||
return mode->_token_match ( mode, tokens, selected_line );
|
return mode->_token_match(mode, tokens, selected_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *mode_get_name ( const Mode *mode )
|
const char *mode_get_name(const Mode *mode) {
|
||||||
{
|
g_assert(mode != NULL);
|
||||||
g_assert ( mode != NULL );
|
|
||||||
return mode->name;
|
return mode->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mode_free ( Mode **mode )
|
void mode_free(Mode **mode) {
|
||||||
{
|
g_assert(mode != NULL);
|
||||||
g_assert ( mode != NULL );
|
g_assert((*mode) != NULL);
|
||||||
g_assert ( ( *mode ) != NULL );
|
if ((*mode)->free != NULL) {
|
||||||
if ( ( *mode )->free != NULL ) {
|
(*mode)->free(*mode);
|
||||||
( *mode )->free ( *mode );
|
|
||||||
}
|
}
|
||||||
( *mode ) = NULL;
|
(*mode) = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *mode_get_private_data ( const Mode *mode )
|
void *mode_get_private_data(const Mode *mode) {
|
||||||
{
|
g_assert(mode != NULL);
|
||||||
g_assert ( mode != NULL );
|
|
||||||
return mode->private_data;
|
return mode->private_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mode_set_private_data ( Mode *mode, void *pd )
|
void mode_set_private_data(Mode *mode, void *pd) {
|
||||||
{
|
g_assert(mode != NULL);
|
||||||
g_assert ( mode != NULL );
|
if (pd != NULL) {
|
||||||
if ( pd != NULL ) {
|
g_assert(mode->private_data == NULL);
|
||||||
g_assert ( mode->private_data == NULL );
|
|
||||||
}
|
}
|
||||||
mode->private_data = pd;
|
mode->private_data = pd;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *mode_get_display_name ( const Mode *mode )
|
const char *mode_get_display_name(const Mode *mode) {
|
||||||
{
|
|
||||||
/** Find the widget */
|
/** Find the widget */
|
||||||
ThemeWidget *wid = rofi_config_find_widget ( mode->name, NULL, TRUE );
|
ThemeWidget *wid = rofi_config_find_widget(mode->name, NULL, TRUE);
|
||||||
if ( wid ) {
|
if (wid) {
|
||||||
/** Check string property */
|
/** Check string property */
|
||||||
Property *p = rofi_theme_find_property ( wid, P_STRING, "display-name", TRUE );
|
Property *p = rofi_theme_find_property(wid, P_STRING, "display-name", TRUE);
|
||||||
if ( p != NULL && p->type == P_STRING ) {
|
if (p != NULL && p->type == P_STRING) {
|
||||||
return p->value.s;
|
return p->value.s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( mode->display_name != NULL ) {
|
if (mode->display_name != NULL) {
|
||||||
return mode->display_name;
|
return mode->display_name;
|
||||||
}
|
}
|
||||||
return mode->name;
|
return mode->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mode_set_config ( Mode *mode )
|
void mode_set_config(Mode *mode) {
|
||||||
{
|
snprintf(mode->cfg_name_key, 128, "display-%s", mode->name);
|
||||||
snprintf ( mode->cfg_name_key, 128, "display-%s", mode->name );
|
config_parser_add_option(xrm_String, mode->cfg_name_key,
|
||||||
config_parser_add_option ( xrm_String, mode->cfg_name_key, (void * *) &( mode->display_name ), "The display name of this browser" );
|
(void **)&(mode->display_name),
|
||||||
|
"The display name of this browser");
|
||||||
}
|
}
|
||||||
|
|
||||||
char * mode_preprocess_input ( Mode *mode, const char *input )
|
char *mode_preprocess_input(Mode *mode, const char *input) {
|
||||||
{
|
if (mode->_preprocess_input) {
|
||||||
if ( mode->_preprocess_input ) {
|
return mode->_preprocess_input(mode, input);
|
||||||
return mode->_preprocess_input ( mode, input );
|
|
||||||
}
|
}
|
||||||
return g_strdup ( input );
|
return g_strdup(input);
|
||||||
}
|
}
|
||||||
char *mode_get_message ( const Mode *mode )
|
char *mode_get_message(const Mode *mode) {
|
||||||
{
|
if (mode->_get_message) {
|
||||||
if ( mode->_get_message ) {
|
return mode->_get_message(mode);
|
||||||
return mode->_get_message ( mode );
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
/** The log domain of this Helper. */
|
/** The log domain of this Helper. */
|
||||||
#define G_LOG_DOMAIN "Helpers.IconFetcher"
|
#define G_LOG_DOMAIN "Helpers.IconFetcher"
|
||||||
|
|
||||||
#include <config.h>
|
#include "config.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <xcb/xproto.h>
|
#include <xcb/xproto.h>
|
||||||
|
|
||||||
|
@@ -29,7 +29,7 @@
|
|||||||
/** Log domain */
|
/** Log domain */
|
||||||
#define G_LOG_DOMAIN "Rofi"
|
#define G_LOG_DOMAIN "Rofi"
|
||||||
|
|
||||||
#include <config.h>
|
#include "config.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <gmodule.h>
|
#include <gmodule.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
1728
source/theme.c
1728
source/theme.c
File diff suppressed because it is too large
Load Diff
@@ -28,10 +28,10 @@
|
|||||||
/** Log domain used by timings.*/
|
/** Log domain used by timings.*/
|
||||||
#define G_LOG_DOMAIN "Timings"
|
#define G_LOG_DOMAIN "Timings"
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "rofi.h"
|
|
||||||
#include "timings.h"
|
#include "timings.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include "rofi.h"
|
||||||
|
#include <stdio.h>
|
||||||
/**
|
/**
|
||||||
* Timer used to calculate time stamps.
|
* Timer used to calculate time stamps.
|
||||||
*/
|
*/
|
||||||
@@ -41,24 +41,23 @@ GTimer *global_timer = NULL;
|
|||||||
*/
|
*/
|
||||||
double global_timer_last = 0.0;
|
double global_timer_last = 0.0;
|
||||||
|
|
||||||
void rofi_timings_init ( void )
|
void rofi_timings_init(void) {
|
||||||
{
|
global_timer = g_timer_new();
|
||||||
global_timer = g_timer_new ();
|
double now = g_timer_elapsed(global_timer, NULL);
|
||||||
double now = g_timer_elapsed ( global_timer, NULL );
|
g_debug("%4.6f (%2.6f): Started", now, 0.0);
|
||||||
g_debug ( "%4.6f (%2.6f): Started", now, 0.0 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void rofi_timings_tick ( const char *file, char const *str, int line, char const *msg )
|
void rofi_timings_tick(const char *file, char const *str, int line,
|
||||||
{
|
char const *msg) {
|
||||||
double now = g_timer_elapsed ( global_timer, NULL );
|
double now = g_timer_elapsed(global_timer, NULL);
|
||||||
|
|
||||||
g_debug ( "%4.6f (%2.6f): %s:%s:%-3d %s", now, now - global_timer_last, file, str, line, msg );
|
g_debug("%4.6f (%2.6f): %s:%s:%-3d %s", now, now - global_timer_last, file,
|
||||||
|
str, line, msg);
|
||||||
global_timer_last = now;
|
global_timer_last = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rofi_timings_quit ( void )
|
void rofi_timings_quit(void) {
|
||||||
{
|
double now = g_timer_elapsed(global_timer, NULL);
|
||||||
double now = g_timer_elapsed ( global_timer, NULL );
|
g_debug("%4.6f (%2.6f): Stopped", now, 0.0);
|
||||||
g_debug ( "%4.6f (%2.6f): Stopped", now, 0.0 );
|
g_timer_destroy(global_timer);
|
||||||
g_timer_destroy ( global_timer );
|
|
||||||
}
|
}
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
/** The Rofi View log domain */
|
/** The Rofi View log domain */
|
||||||
#define G_LOG_DOMAIN "View"
|
#define G_LOG_DOMAIN "View"
|
||||||
|
|
||||||
#include <config.h>
|
#include "config.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
@@ -28,18 +28,16 @@
|
|||||||
/** The log domain of this widget. */
|
/** The log domain of this widget. */
|
||||||
#define G_LOG_DOMAIN "Widgets.Box"
|
#define G_LOG_DOMAIN "Widgets.Box"
|
||||||
|
|
||||||
#include <config.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "widgets/widget.h"
|
|
||||||
#include "widgets/widget-internal.h"
|
|
||||||
#include "widgets/box.h"
|
#include "widgets/box.h"
|
||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
|
#include "widgets/widget-internal.h"
|
||||||
|
#include "widgets/widget.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
/** Default spacing used in the box*/
|
/** Default spacing used in the box*/
|
||||||
#define DEFAULT_SPACING 2
|
#define DEFAULT_SPACING 2
|
||||||
|
|
||||||
struct _box
|
struct _box {
|
||||||
{
|
|
||||||
widget widget;
|
widget widget;
|
||||||
RofiOrientation type;
|
RofiOrientation type;
|
||||||
int max_size;
|
int max_size;
|
||||||
@@ -49,282 +47,286 @@ struct _box
|
|||||||
GList *children;
|
GList *children;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void box_update ( widget *wid );
|
static void box_update(widget *wid);
|
||||||
|
|
||||||
static int box_get_desired_width ( widget *wid )
|
static int box_get_desired_width(widget *wid) {
|
||||||
{
|
box *b = (box *)wid;
|
||||||
box *b = (box *) wid;
|
int spacing = distance_get_pixel(b->spacing, b->type);
|
||||||
int spacing = distance_get_pixel ( b->spacing, b->type );
|
|
||||||
int width = 0;
|
int width = 0;
|
||||||
|
|
||||||
// Allow user to override.
|
// Allow user to override.
|
||||||
RofiDistance w = rofi_theme_get_distance ( wid, "width", 0 );
|
RofiDistance w = rofi_theme_get_distance(wid, "width", 0);
|
||||||
width = distance_get_pixel ( w, ROFI_ORIENTATION_HORIZONTAL );
|
width = distance_get_pixel(w, ROFI_ORIENTATION_HORIZONTAL);
|
||||||
if ( width > 0 ) {
|
if (width > 0) {
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( b->type == ROFI_ORIENTATION_HORIZONTAL ) {
|
if (b->type == ROFI_ORIENTATION_HORIZONTAL) {
|
||||||
int active_widgets = 0;
|
int active_widgets = 0;
|
||||||
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
for (GList *iter = g_list_first(b->children); iter != NULL;
|
||||||
widget * child = (widget *) iter->data;
|
iter = g_list_next(iter)) {
|
||||||
if ( !child->enabled ) {
|
widget *child = (widget *)iter->data;
|
||||||
|
if (!child->enabled) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
active_widgets++;
|
active_widgets++;
|
||||||
if ( child->expand == TRUE ) {
|
if (child->expand == TRUE) {
|
||||||
width += widget_get_desired_width ( child );
|
width += widget_get_desired_width(child);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
width += widget_get_desired_width ( child );
|
width += widget_get_desired_width(child);
|
||||||
}
|
}
|
||||||
if ( active_widgets > 0 ) {
|
if (active_widgets > 0) {
|
||||||
width += ( active_widgets - 1 ) * spacing;
|
width += (active_widgets - 1) * spacing;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
for (GList *iter = g_list_first(b->children); iter != NULL;
|
||||||
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
iter = g_list_next(iter)) {
|
||||||
widget * child = (widget *) iter->data;
|
widget *child = (widget *)iter->data;
|
||||||
if ( !child->enabled ) {
|
if (!child->enabled) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
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;
|
return width;
|
||||||
}
|
}
|
||||||
static int box_get_desired_height ( widget *wid )
|
static int box_get_desired_height(widget *wid) {
|
||||||
{
|
box *b = (box *)wid;
|
||||||
box *b = (box *) wid;
|
int spacing = distance_get_pixel(b->spacing, b->type);
|
||||||
int spacing = distance_get_pixel ( b->spacing, b->type );
|
|
||||||
int height = 0;
|
int height = 0;
|
||||||
if ( b->type == ROFI_ORIENTATION_VERTICAL ) {
|
if (b->type == ROFI_ORIENTATION_VERTICAL) {
|
||||||
int active_widgets = 0;
|
int active_widgets = 0;
|
||||||
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
for (GList *iter = g_list_first(b->children); iter != NULL;
|
||||||
widget * child = (widget *) iter->data;
|
iter = g_list_next(iter)) {
|
||||||
if ( !child->enabled ) {
|
widget *child = (widget *)iter->data;
|
||||||
|
if (!child->enabled) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
active_widgets++;
|
active_widgets++;
|
||||||
height += widget_get_desired_height ( child );
|
height += widget_get_desired_height(child);
|
||||||
}
|
}
|
||||||
if ( active_widgets > 0 ) {
|
if (active_widgets > 0) {
|
||||||
height += ( active_widgets - 1 ) * spacing;
|
height += (active_widgets - 1) * spacing;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
for (GList *iter = g_list_first(b->children); iter != NULL;
|
||||||
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
iter = g_list_next(iter)) {
|
||||||
widget * child = (widget *) iter->data;
|
widget *child = (widget *)iter->data;
|
||||||
if ( !child->enabled ) {
|
if (!child->enabled) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
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;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vert_calculate_size ( box *b )
|
static void vert_calculate_size(box *b) {
|
||||||
{
|
int spacing = distance_get_pixel(b->spacing, ROFI_ORIENTATION_VERTICAL);
|
||||||
int spacing = distance_get_pixel ( b->spacing, ROFI_ORIENTATION_VERTICAL );
|
|
||||||
int expanding_widgets = 0;
|
int expanding_widgets = 0;
|
||||||
int active_widgets = 0;
|
int active_widgets = 0;
|
||||||
int rem_width = widget_padding_get_remaining_width ( WIDGET ( b ) );
|
int rem_width = widget_padding_get_remaining_width(WIDGET(b));
|
||||||
int rem_height = widget_padding_get_remaining_height ( WIDGET ( b ) );
|
int rem_height = widget_padding_get_remaining_height(WIDGET(b));
|
||||||
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
for (GList *iter = g_list_first(b->children); iter != NULL;
|
||||||
widget * child = (widget *) iter->data;
|
iter = g_list_next(iter)) {
|
||||||
if ( child->enabled && child->expand == FALSE ) {
|
widget *child = (widget *)iter->data;
|
||||||
widget_resize ( child, rem_width, widget_get_desired_height ( child ) );
|
if (child->enabled && child->expand == FALSE) {
|
||||||
|
widget_resize(child, rem_width, widget_get_desired_height(child));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b->max_size = 0;
|
b->max_size = 0;
|
||||||
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
for (GList *iter = g_list_first(b->children); iter != NULL;
|
||||||
widget * child = (widget *) iter->data;
|
iter = g_list_next(iter)) {
|
||||||
if ( !child->enabled ) {
|
widget *child = (widget *)iter->data;
|
||||||
|
if (!child->enabled) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
active_widgets++;
|
active_widgets++;
|
||||||
if ( child->expand == TRUE ) {
|
if (child->expand == TRUE) {
|
||||||
expanding_widgets++;
|
expanding_widgets++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ( child->h > 0 ) {
|
if (child->h > 0) {
|
||||||
b->max_size += child->h;
|
b->max_size += child->h;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( active_widgets > 0 ) {
|
if (active_widgets > 0) {
|
||||||
b->max_size += ( active_widgets - 1 ) * spacing;
|
b->max_size += (active_widgets - 1) * spacing;
|
||||||
}
|
}
|
||||||
if ( b->max_size > rem_height ) {
|
if (b->max_size > rem_height) {
|
||||||
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;
|
return;
|
||||||
}
|
}
|
||||||
if ( active_widgets > 0 ) {
|
if (active_widgets > 0) {
|
||||||
int top = widget_padding_get_top ( WIDGET ( b ) );
|
int top = widget_padding_get_top(WIDGET(b));
|
||||||
double rem = rem_height - b->max_size;
|
double rem = rem_height - b->max_size;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
for (GList *iter = g_list_first(b->children); iter != NULL;
|
||||||
widget * child = (widget *) iter->data;
|
iter = g_list_next(iter)) {
|
||||||
if ( child->enabled == FALSE ) {
|
widget *child = (widget *)iter->data;
|
||||||
|
if (child->enabled == FALSE) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ( child->expand == TRUE ) {
|
if (child->expand == TRUE) {
|
||||||
// Re-calculate to avoid round issues leaving one pixel left.
|
// Re-calculate to avoid round issues leaving one pixel left.
|
||||||
int expanding_widgets_size = ( rem ) / ( expanding_widgets - index );
|
int expanding_widgets_size = (rem) / (expanding_widgets - index);
|
||||||
widget_move ( child, widget_padding_get_left ( WIDGET ( b ) ), top );
|
widget_move(child, widget_padding_get_left(WIDGET(b)), top);
|
||||||
top += expanding_widgets_size;
|
top += expanding_widgets_size;
|
||||||
widget_resize ( child, rem_width, expanding_widgets_size );
|
widget_resize(child, rem_width, expanding_widgets_size);
|
||||||
top += spacing;
|
top += spacing;
|
||||||
rem -= expanding_widgets_size;
|
rem -= expanding_widgets_size;
|
||||||
index++;
|
index++;
|
||||||
}
|
} else {
|
||||||
else {
|
widget_move(child, widget_padding_get_left(WIDGET(b)), top);
|
||||||
widget_move ( child, widget_padding_get_left ( WIDGET ( b ) ), top );
|
top += widget_get_height(child);
|
||||||
top += widget_get_height ( child );
|
|
||||||
top += spacing;
|
top += spacing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b->max_size += widget_padding_get_padding_height ( WIDGET ( b ) );
|
b->max_size += widget_padding_get_padding_height(WIDGET(b));
|
||||||
}
|
}
|
||||||
static void hori_calculate_size ( box *b )
|
static void hori_calculate_size(box *b) {
|
||||||
{
|
int spacing = distance_get_pixel(b->spacing, ROFI_ORIENTATION_HORIZONTAL);
|
||||||
int spacing = distance_get_pixel ( b->spacing, ROFI_ORIENTATION_HORIZONTAL );
|
|
||||||
int expanding_widgets = 0;
|
int expanding_widgets = 0;
|
||||||
int active_widgets = 0;
|
int active_widgets = 0;
|
||||||
int rem_width = widget_padding_get_remaining_width ( WIDGET ( b ) );
|
int rem_width = widget_padding_get_remaining_width(WIDGET(b));
|
||||||
int rem_height = widget_padding_get_remaining_height ( WIDGET ( b ) );
|
int rem_height = widget_padding_get_remaining_height(WIDGET(b));
|
||||||
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
for (GList *iter = g_list_first(b->children); iter != NULL;
|
||||||
widget * child = (widget *) iter->data;
|
iter = g_list_next(iter)) {
|
||||||
if ( child->enabled && child->expand == FALSE ) {
|
widget *child = (widget *)iter->data;
|
||||||
widget_resize ( child,
|
if (child->enabled && child->expand == FALSE) {
|
||||||
widget_get_desired_width ( child ), //child->w,
|
widget_resize(child,
|
||||||
rem_height );
|
widget_get_desired_width(child), // child->w,
|
||||||
|
rem_height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b->max_size = 0;
|
b->max_size = 0;
|
||||||
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
for (GList *iter = g_list_first(b->children); iter != NULL;
|
||||||
widget * child = (widget *) iter->data;
|
iter = g_list_next(iter)) {
|
||||||
if ( !child->enabled ) {
|
widget *child = (widget *)iter->data;
|
||||||
|
if (!child->enabled) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
active_widgets++;
|
active_widgets++;
|
||||||
if ( child->expand == TRUE ) {
|
if (child->expand == TRUE) {
|
||||||
expanding_widgets++;
|
expanding_widgets++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Size used by fixed width widgets.
|
// Size used by fixed width widgets.
|
||||||
if ( child->h > 0 ) {
|
if (child->h > 0) {
|
||||||
b->max_size += child->w;
|
b->max_size += child->w;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b->max_size += MAX ( 0, ( ( active_widgets - 1 ) * spacing ) );
|
b->max_size += MAX(0, ((active_widgets - 1) * spacing));
|
||||||
if ( b->max_size > ( rem_width ) ) {
|
if (b->max_size > (rem_width)) {
|
||||||
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 );
|
g_debug("Widgets to large (width) for box: %d %d", b->max_size,
|
||||||
//return;
|
b->widget.w);
|
||||||
|
// return;
|
||||||
}
|
}
|
||||||
if ( active_widgets > 0 ) {
|
if (active_widgets > 0) {
|
||||||
int left = widget_padding_get_left ( WIDGET ( b ) );
|
int left = widget_padding_get_left(WIDGET(b));
|
||||||
double rem = rem_width - b->max_size;
|
double rem = rem_width - b->max_size;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
if ( rem < 0 ) {
|
if (rem < 0) {
|
||||||
rem = 0;
|
rem = 0;
|
||||||
}
|
}
|
||||||
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
for (GList *iter = g_list_first(b->children); iter != NULL;
|
||||||
widget * child = (widget *) iter->data;
|
iter = g_list_next(iter)) {
|
||||||
if ( child->enabled == FALSE ) {
|
widget *child = (widget *)iter->data;
|
||||||
|
if (child->enabled == FALSE) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ( child->expand == TRUE ) {
|
if (child->expand == TRUE) {
|
||||||
// Re-calculate to avoid round issues leaving one pixel left.
|
// Re-calculate to avoid round issues leaving one pixel left.
|
||||||
int expanding_widgets_size = ( rem ) / ( expanding_widgets - index );
|
int expanding_widgets_size = (rem) / (expanding_widgets - index);
|
||||||
widget_move ( child, left, widget_padding_get_top ( WIDGET ( b ) ) );
|
widget_move(child, left, widget_padding_get_top(WIDGET(b)));
|
||||||
left += expanding_widgets_size;
|
left += expanding_widgets_size;
|
||||||
widget_resize ( child, expanding_widgets_size, rem_height );
|
widget_resize(child, expanding_widgets_size, rem_height);
|
||||||
left += spacing;
|
left += spacing;
|
||||||
rem -= expanding_widgets_size;
|
rem -= expanding_widgets_size;
|
||||||
index++;
|
index++;
|
||||||
}
|
} else {
|
||||||
else {
|
widget_move(child, left, widget_padding_get_top(WIDGET(b)));
|
||||||
widget_move ( child, left, widget_padding_get_top ( WIDGET ( b ) ) );
|
left += widget_get_width(child);
|
||||||
left += widget_get_width ( child );
|
|
||||||
left += spacing;
|
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 )
|
static void box_draw(widget *wid, cairo_t *draw) {
|
||||||
{
|
box *b = (box *)wid;
|
||||||
box *b = (box *) wid;
|
for (GList *iter = g_list_first(b->children); iter != NULL;
|
||||||
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
iter = g_list_next(iter)) {
|
||||||
widget * child = (widget *) iter->data;
|
widget *child = (widget *)iter->data;
|
||||||
widget_draw ( child, draw );
|
widget_draw(child, draw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void box_free ( widget *wid )
|
static void box_free(widget *wid) {
|
||||||
{
|
box *b = (box *)wid;
|
||||||
box *b = (box *) wid;
|
|
||||||
|
|
||||||
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
for (GList *iter = g_list_first(b->children); iter != NULL;
|
||||||
widget * child = (widget *) iter->data;
|
iter = g_list_next(iter)) {
|
||||||
widget_free ( child );
|
widget *child = (widget *)iter->data;
|
||||||
|
widget_free(child);
|
||||||
}
|
}
|
||||||
g_list_free ( b->children );
|
g_list_free(b->children);
|
||||||
g_free ( b );
|
g_free(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void box_add ( box *box, widget *child, gboolean expand )
|
void box_add(box *box, widget *child, gboolean expand) {
|
||||||
{
|
if (box == NULL) {
|
||||||
if ( box == NULL ) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Make sure box is width/heigh enough.
|
// Make sure box is width/heigh enough.
|
||||||
if ( box->type == ROFI_ORIENTATION_VERTICAL ) {
|
if (box->type == ROFI_ORIENTATION_VERTICAL) {
|
||||||
int width = box->widget.w;
|
int width = box->widget.w;
|
||||||
width = 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;
|
box->widget.w = width;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
int height = box->widget.h;
|
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;
|
box->widget.h = height;
|
||||||
}
|
}
|
||||||
child->expand = rofi_theme_get_boolean ( child, "expand", expand );
|
child->expand = rofi_theme_get_boolean(child, "expand", expand);
|
||||||
g_assert ( child->parent == WIDGET ( box ) );
|
g_assert(child->parent == WIDGET(box));
|
||||||
box->children = g_list_append ( box->children, (void *) child );
|
box->children = g_list_append(box->children, (void *)child);
|
||||||
widget_update ( WIDGET ( box ) );
|
widget_update(WIDGET(box));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void box_resize ( widget *widget, short w, short h )
|
static void box_resize(widget *widget, short w, short h) {
|
||||||
{
|
box *b = (box *)widget;
|
||||||
box *b = (box *) widget;
|
if (b->widget.w != w || b->widget.h != h) {
|
||||||
if ( b->widget.w != w || b->widget.h != h ) {
|
|
||||||
b->widget.w = w;
|
b->widget.w = w;
|
||||||
b->widget.h = h;
|
b->widget.h = h;
|
||||||
widget_update ( widget );
|
widget_update(widget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static widget *box_find_mouse_target ( widget *wid, WidgetType type, gint x, gint y )
|
static widget *box_find_mouse_target(widget *wid, WidgetType type, gint x,
|
||||||
{
|
gint y) {
|
||||||
box *b = (box *) wid;
|
box *b = (box *)wid;
|
||||||
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
for (GList *iter = g_list_first(b->children); iter != NULL;
|
||||||
widget * child = (widget *) iter->data;
|
iter = g_list_next(iter)) {
|
||||||
if ( !child->enabled ) {
|
widget *child = (widget *)iter->data;
|
||||||
|
if (!child->enabled) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ( widget_intersect ( child, x, y ) ) {
|
if (widget_intersect(child, x, y)) {
|
||||||
gint rx = x - child->x;
|
gint rx = x - child->x;
|
||||||
gint ry = y - child->y;
|
gint ry = y - child->y;
|
||||||
widget *target = widget_find_mouse_target ( child, type, rx, ry );
|
widget *target = widget_find_mouse_target(child, type, rx, ry);
|
||||||
if ( target != NULL ) {
|
if (target != NULL) {
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -332,19 +334,18 @@ static widget *box_find_mouse_target ( widget *wid, WidgetType type, gint x, gin
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void box_set_state ( widget *wid, const char *state )
|
static void box_set_state(widget *wid, const char *state) {
|
||||||
{
|
for (GList *iter = g_list_first(((box *)wid)->children); iter != NULL;
|
||||||
for ( GList *iter = g_list_first ( ( (box *) wid )->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
iter = g_list_next(iter)) {
|
||||||
widget * child = (widget *) iter->data;
|
widget *child = (widget *)iter->data;
|
||||||
widget_set_state ( child, state );
|
widget_set_state(child, state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
box * box_create ( widget *parent, const char *name, RofiOrientation type )
|
box *box_create(widget *parent, const char *name, RofiOrientation type) {
|
||||||
{
|
box *b = g_malloc0(sizeof(box));
|
||||||
box *b = g_malloc0 ( sizeof ( box ) );
|
|
||||||
// Initialize widget.
|
// Initialize widget.
|
||||||
widget_init ( WIDGET ( b ), parent, WIDGET_TYPE_UNKNOWN, name );
|
widget_init(WIDGET(b), parent, WIDGET_TYPE_UNKNOWN, name);
|
||||||
b->type = type;
|
b->type = type;
|
||||||
b->widget.draw = box_draw;
|
b->widget.draw = box_draw;
|
||||||
b->widget.free = box_free;
|
b->widget.free = box_free;
|
||||||
@@ -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.get_desired_width = box_get_desired_width;
|
||||||
b->widget.set_state = box_set_state;
|
b->widget.set_state = box_set_state;
|
||||||
|
|
||||||
b->type = rofi_theme_get_orientation ( WIDGET ( b ), "orientation", b->type );
|
b->type = rofi_theme_get_orientation(WIDGET(b), "orientation", b->type);
|
||||||
|
|
||||||
b->spacing = rofi_theme_get_distance ( WIDGET ( b ), "spacing", DEFAULT_SPACING );
|
b->spacing = rofi_theme_get_distance(WIDGET(b), "spacing", DEFAULT_SPACING);
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void box_update ( widget *wid )
|
static void box_update(widget *wid) {
|
||||||
{
|
box *b = (box *)wid;
|
||||||
box *b = (box *) wid;
|
switch (b->type) {
|
||||||
switch ( b->type )
|
|
||||||
{
|
|
||||||
case ROFI_ORIENTATION_VERTICAL:
|
case ROFI_ORIENTATION_VERTICAL:
|
||||||
vert_calculate_size ( b );
|
vert_calculate_size(b);
|
||||||
break;
|
break;
|
||||||
case ROFI_ORIENTATION_HORIZONTAL:
|
case ROFI_ORIENTATION_HORIZONTAL:
|
||||||
default:
|
default:
|
||||||
hori_calculate_size ( b );
|
hori_calculate_size(b);
|
||||||
}
|
}
|
||||||
if ( wid->parent ) {
|
if (wid->parent) {
|
||||||
widget_update ( wid->parent );
|
widget_update(wid->parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -28,90 +28,81 @@
|
|||||||
/** The log domain of this widget. */
|
/** The log domain of this widget. */
|
||||||
#define G_LOG_DOMAIN "Widgets.Container"
|
#define G_LOG_DOMAIN "Widgets.Container"
|
||||||
|
|
||||||
#include <config.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "widgets/widget.h"
|
|
||||||
#include "widgets/widget-internal.h"
|
|
||||||
#include "widgets/container.h"
|
#include "widgets/container.h"
|
||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
|
#include "widgets/widget-internal.h"
|
||||||
|
#include "widgets/widget.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
struct _container
|
struct _container {
|
||||||
{
|
|
||||||
widget widget;
|
widget widget;
|
||||||
widget *child;
|
widget *child;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void container_update ( widget *wid );
|
static void container_update(widget *wid);
|
||||||
|
|
||||||
static int container_get_desired_height ( widget *widget )
|
static int container_get_desired_height(widget *widget) {
|
||||||
{
|
container *b = (container *)widget;
|
||||||
container *b = (container *) widget;
|
|
||||||
int height = 0;
|
int height = 0;
|
||||||
if ( b->child ) {
|
if (b->child) {
|
||||||
height += widget_get_desired_height ( b->child );
|
height += widget_get_desired_height(b->child);
|
||||||
}
|
}
|
||||||
height += widget_padding_get_padding_height ( widget );
|
height += widget_padding_get_padding_height(widget);
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void container_draw ( widget *wid, cairo_t *draw )
|
static void container_draw(widget *wid, cairo_t *draw) {
|
||||||
{
|
container *b = (container *)wid;
|
||||||
container *b = (container *) wid;
|
|
||||||
|
|
||||||
widget_draw ( b->child, draw );
|
widget_draw(b->child, draw);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void container_free ( widget *wid )
|
static void container_free(widget *wid) {
|
||||||
{
|
container *b = (container *)wid;
|
||||||
container *b = (container *) wid;
|
|
||||||
|
|
||||||
widget_free ( b->child );
|
widget_free(b->child);
|
||||||
g_free ( b );
|
g_free(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void container_add ( container *container, widget *child )
|
void container_add(container *container, widget *child) {
|
||||||
{
|
if (container == NULL) {
|
||||||
if ( container == NULL ) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
container->child = child;
|
container->child = child;
|
||||||
g_assert ( child->parent == WIDGET ( container ) );
|
g_assert(child->parent == WIDGET(container));
|
||||||
widget_update ( WIDGET ( container ) );
|
widget_update(WIDGET(container));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void container_resize ( widget *widget, short w, short h )
|
static void container_resize(widget *widget, short w, short h) {
|
||||||
{
|
container *b = (container *)widget;
|
||||||
container *b = (container *) widget;
|
if (b->widget.w != w || b->widget.h != h) {
|
||||||
if ( b->widget.w != w || b->widget.h != h ) {
|
|
||||||
b->widget.w = w;
|
b->widget.w = w;
|
||||||
b->widget.h = h;
|
b->widget.h = h;
|
||||||
widget_update ( widget );
|
widget_update(widget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static widget *container_find_mouse_target ( widget *wid, WidgetType type, gint x, gint y )
|
static widget *container_find_mouse_target(widget *wid, WidgetType type, gint x,
|
||||||
{
|
gint y) {
|
||||||
container *b = (container *) wid;
|
container *b = (container *)wid;
|
||||||
if ( !widget_intersect ( b->child, x, y ) ) {
|
if (!widget_intersect(b->child, x, y)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
x -= b->child->x;
|
x -= b->child->x;
|
||||||
y -= b->child->y;
|
y -= b->child->y;
|
||||||
return widget_find_mouse_target ( b->child, type, x, y );
|
return widget_find_mouse_target(b->child, type, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void container_set_state ( widget *wid, const char *state )
|
static void container_set_state(widget *wid, const char *state) {
|
||||||
{
|
container *b = (container *)wid;
|
||||||
container *b = (container *) wid;
|
widget_set_state(b->child, state);
|
||||||
widget_set_state ( b->child, state );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
container * container_create ( widget *parent, const char *name )
|
container *container_create(widget *parent, const char *name) {
|
||||||
{
|
container *b = g_malloc0(sizeof(container));
|
||||||
container *b = g_malloc0 ( sizeof ( container ) );
|
|
||||||
// Initialize widget.
|
// Initialize widget.
|
||||||
widget_init ( WIDGET ( b ), parent, WIDGET_TYPE_UNKNOWN, name );
|
widget_init(WIDGET(b), parent, WIDGET_TYPE_UNKNOWN, name);
|
||||||
b->widget.draw = container_draw;
|
b->widget.draw = container_draw;
|
||||||
b->widget.free = container_free;
|
b->widget.free = container_free;
|
||||||
b->widget.resize = container_resize;
|
b->widget.resize = container_resize;
|
||||||
@@ -122,17 +113,13 @@ container * container_create ( widget *parent, const char *name )
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void container_update ( widget *wid )
|
static void container_update(widget *wid) {
|
||||||
{
|
container *b = (container *)wid;
|
||||||
container *b = (container *) wid;
|
if (b->child && b->child->enabled) {
|
||||||
if ( b->child && b->child->enabled ) {
|
widget_resize(WIDGET(b->child),
|
||||||
widget_resize ( WIDGET ( b->child ),
|
widget_padding_get_remaining_width(WIDGET(b)),
|
||||||
widget_padding_get_remaining_width ( WIDGET ( b ) ),
|
widget_padding_get_remaining_height(WIDGET(b)));
|
||||||
widget_padding_get_remaining_height ( WIDGET ( b ) )
|
widget_move(WIDGET(b->child), widget_padding_get_left(WIDGET(b)),
|
||||||
);
|
widget_padding_get_top(WIDGET(b)));
|
||||||
widget_move ( WIDGET ( b->child ),
|
|
||||||
widget_padding_get_left ( WIDGET ( b ) ),
|
|
||||||
widget_padding_get_top ( WIDGET ( b ) )
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -28,17 +28,15 @@
|
|||||||
/** The log domain of this widget. */
|
/** The log domain of this widget. */
|
||||||
#define G_LOG_DOMAIN "Widgets.Icon"
|
#define G_LOG_DOMAIN "Widgets.Icon"
|
||||||
|
|
||||||
#include <config.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "widgets/widget.h"
|
|
||||||
#include "widgets/widget-internal.h"
|
|
||||||
#include "widgets/icon.h"
|
#include "widgets/icon.h"
|
||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
|
#include "widgets/widget-internal.h"
|
||||||
|
#include "widgets/widget.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "rofi-icon-fetcher.h"
|
#include "rofi-icon-fetcher.h"
|
||||||
|
|
||||||
struct _icon
|
struct _icon {
|
||||||
{
|
|
||||||
widget widget;
|
widget widget;
|
||||||
|
|
||||||
// Size of the icon.
|
// Size of the icon.
|
||||||
@@ -54,134 +52,127 @@ struct _icon
|
|||||||
cairo_surface_t *icon;
|
cairo_surface_t *icon;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int icon_get_desired_height ( widget *widget )
|
static int icon_get_desired_height(widget *widget) {
|
||||||
{
|
icon *b = (icon *)widget;
|
||||||
icon *b = (icon *) widget;
|
|
||||||
int height = b->size;
|
int height = b->size;
|
||||||
if ( b->squared == FALSE ) {
|
if (b->squared == FALSE) {
|
||||||
if ( b->icon ) {
|
if (b->icon) {
|
||||||
int iconh = cairo_image_surface_get_height ( b->icon );
|
int iconh = cairo_image_surface_get_height(b->icon);
|
||||||
int iconw = cairo_image_surface_get_width ( b->icon );
|
int iconw = cairo_image_surface_get_width(b->icon);
|
||||||
int icons = MAX ( iconh, iconw );
|
int icons = MAX(iconh, iconw);
|
||||||
double scale = (double) b->size / icons;
|
double scale = (double)b->size / icons;
|
||||||
height = iconh*scale;
|
height = iconh * scale;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
height += widget_padding_get_padding_height ( widget );
|
height += widget_padding_get_padding_height(widget);
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
static int icon_get_desired_width ( widget *widget )
|
static int icon_get_desired_width(widget *widget) {
|
||||||
{
|
icon *b = (icon *)widget;
|
||||||
icon *b = (icon *) widget;
|
|
||||||
int width = b->size;
|
int width = b->size;
|
||||||
if ( b->squared == FALSE ) {
|
if (b->squared == FALSE) {
|
||||||
if ( b->icon ) {
|
if (b->icon) {
|
||||||
int iconh = cairo_image_surface_get_height ( b->icon );
|
int iconh = cairo_image_surface_get_height(b->icon);
|
||||||
int iconw = cairo_image_surface_get_width ( b->icon );
|
int iconw = cairo_image_surface_get_width(b->icon);
|
||||||
int icons = MAX ( iconh, iconw );
|
int icons = MAX(iconh, iconw);
|
||||||
double scale = (double) b->size / icons;
|
double scale = (double)b->size / icons;
|
||||||
width = iconw*scale;
|
width = iconw * scale;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
width += widget_padding_get_padding_width ( widget );
|
width += widget_padding_get_padding_width(widget);
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void icon_draw ( widget *wid, cairo_t *draw )
|
static void icon_draw(widget *wid, cairo_t *draw) {
|
||||||
{
|
icon *b = (icon *)wid;
|
||||||
icon *b = (icon *) wid;
|
|
||||||
// If no icon is loaded. quit.
|
// If no icon is loaded. quit.
|
||||||
if ( b->icon == NULL && b->icon_fetch_id > 0 ) {
|
if (b->icon == NULL && b->icon_fetch_id > 0) {
|
||||||
b->icon = rofi_icon_fetcher_get ( b->icon_fetch_id );
|
b->icon = rofi_icon_fetcher_get(b->icon_fetch_id);
|
||||||
if ( b->icon ) {
|
if (b->icon) {
|
||||||
cairo_surface_reference ( b->icon );
|
cairo_surface_reference(b->icon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( b->icon == NULL ) {
|
if (b->icon == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int iconh = cairo_image_surface_get_height ( b->icon );
|
int iconh = cairo_image_surface_get_height(b->icon);
|
||||||
int iconw = cairo_image_surface_get_width ( b->icon );
|
int iconw = cairo_image_surface_get_width(b->icon);
|
||||||
int icons = MAX ( iconh, iconw );
|
int icons = MAX(iconh, iconw);
|
||||||
double scale = (double) b->size / icons;
|
double scale = (double)b->size / icons;
|
||||||
|
|
||||||
int lpad = widget_padding_get_left ( WIDGET ( b ) );
|
int lpad = widget_padding_get_left(WIDGET(b));
|
||||||
int rpad = widget_padding_get_right ( WIDGET ( b ) );
|
int rpad = widget_padding_get_right(WIDGET(b));
|
||||||
int tpad = widget_padding_get_top ( WIDGET ( b ) );
|
int tpad = widget_padding_get_top(WIDGET(b));
|
||||||
int bpad = widget_padding_get_bottom ( WIDGET ( b ) );
|
int bpad = widget_padding_get_bottom(WIDGET(b));
|
||||||
|
|
||||||
cairo_save ( draw );
|
cairo_save(draw);
|
||||||
|
|
||||||
cairo_translate ( draw,
|
cairo_translate(
|
||||||
lpad + ( b->widget.w - iconw * scale - lpad - rpad ) * b->xalign,
|
draw, lpad + (b->widget.w - iconw * scale - lpad - rpad) * b->xalign,
|
||||||
tpad + ( b->widget.h - iconh * scale - tpad - bpad ) * b->yalign );
|
tpad + (b->widget.h - iconh * scale - tpad - bpad) * b->yalign);
|
||||||
cairo_scale ( draw, scale, scale );
|
cairo_scale(draw, scale, scale);
|
||||||
cairo_set_source_surface ( draw, b->icon, 0, 0 );
|
cairo_set_source_surface(draw, b->icon, 0, 0);
|
||||||
cairo_paint ( draw );
|
cairo_paint(draw);
|
||||||
cairo_restore ( draw );
|
cairo_restore(draw);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void icon_free ( widget *wid )
|
static void icon_free(widget *wid) {
|
||||||
{
|
icon *b = (icon *)wid;
|
||||||
icon *b = (icon *) wid;
|
|
||||||
|
|
||||||
if ( b->icon ) {
|
if (b->icon) {
|
||||||
cairo_surface_destroy ( b->icon );
|
cairo_surface_destroy(b->icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free ( b );
|
g_free(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void icon_resize ( widget *widget, short w, short h )
|
static void icon_resize(widget *widget, short w, short h) {
|
||||||
{
|
icon *b = (icon *)widget;
|
||||||
icon *b = (icon *) widget;
|
if (b->widget.w != w || b->widget.h != h) {
|
||||||
if ( b->widget.w != w || b->widget.h != h ) {
|
|
||||||
b->widget.w = w;
|
b->widget.w = w;
|
||||||
b->widget.h = h;
|
b->widget.h = h;
|
||||||
widget_update ( widget );
|
widget_update(widget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void icon_set_surface ( icon *icon, cairo_surface_t *surf )
|
void icon_set_surface(icon *icon, cairo_surface_t *surf) {
|
||||||
{
|
|
||||||
icon->icon_fetch_id = 0;
|
icon->icon_fetch_id = 0;
|
||||||
if ( icon->icon ) {
|
if (icon->icon) {
|
||||||
cairo_surface_destroy ( icon->icon );
|
cairo_surface_destroy(icon->icon);
|
||||||
icon->icon = NULL;
|
icon->icon = NULL;
|
||||||
}
|
}
|
||||||
if ( surf ) {
|
if (surf) {
|
||||||
cairo_surface_reference ( surf );
|
cairo_surface_reference(surf);
|
||||||
icon->icon = surf;
|
icon->icon = surf;
|
||||||
}
|
}
|
||||||
widget_queue_redraw ( WIDGET ( icon ) );
|
widget_queue_redraw(WIDGET(icon));
|
||||||
}
|
}
|
||||||
|
|
||||||
icon * icon_create ( widget *parent, const char *name )
|
icon *icon_create(widget *parent, const char *name) {
|
||||||
{
|
icon *b = g_malloc0(sizeof(icon));
|
||||||
icon *b = g_malloc0 ( sizeof ( icon ) );
|
|
||||||
|
|
||||||
b->size = 16;
|
b->size = 16;
|
||||||
// Initialize widget.
|
// Initialize widget.
|
||||||
widget_init ( WIDGET ( b ), parent, WIDGET_TYPE_UNKNOWN, name );
|
widget_init(WIDGET(b), parent, WIDGET_TYPE_UNKNOWN, name);
|
||||||
b->widget.draw = icon_draw;
|
b->widget.draw = icon_draw;
|
||||||
b->widget.free = icon_free;
|
b->widget.free = icon_free;
|
||||||
b->widget.resize = icon_resize;
|
b->widget.resize = icon_resize;
|
||||||
b->widget.get_desired_height = icon_get_desired_height;
|
b->widget.get_desired_height = icon_get_desired_height;
|
||||||
b->widget.get_desired_width = icon_get_desired_width;
|
b->widget.get_desired_width = icon_get_desired_width;
|
||||||
|
|
||||||
RofiDistance d = rofi_theme_get_distance ( WIDGET ( b ), "size", b->size );
|
RofiDistance d = rofi_theme_get_distance(WIDGET(b), "size", b->size);
|
||||||
b->size = distance_get_pixel ( d, ROFI_ORIENTATION_VERTICAL );
|
b->size = distance_get_pixel(d, ROFI_ORIENTATION_VERTICAL);
|
||||||
|
|
||||||
b->squared = rofi_theme_get_boolean ( WIDGET ( b ), "squared", TRUE );
|
b->squared = rofi_theme_get_boolean(WIDGET(b), "squared", TRUE);
|
||||||
|
|
||||||
const char * filename = rofi_theme_get_string ( WIDGET ( b ), "filename", NULL );
|
const char *filename = rofi_theme_get_string(WIDGET(b), "filename", NULL);
|
||||||
if ( filename ) {
|
if (filename) {
|
||||||
b->icon_fetch_id = rofi_icon_fetcher_query ( filename, b->size );
|
b->icon_fetch_id = rofi_icon_fetcher_query(filename, b->size);
|
||||||
}
|
}
|
||||||
b->yalign = rofi_theme_get_double ( WIDGET ( b ), "vertical-align", 0.5 );
|
b->yalign = rofi_theme_get_double(WIDGET(b), "vertical-align", 0.5);
|
||||||
b->yalign = MAX ( 0, MIN ( 1.0, b->yalign ) );
|
b->yalign = MAX(0, MIN(1.0, b->yalign));
|
||||||
b->xalign = rofi_theme_get_double ( WIDGET ( b ), "horizontal-align", 0.5 );
|
b->xalign = rofi_theme_get_double(WIDGET(b), "horizontal-align", 0.5);
|
||||||
b->xalign = MAX ( 0, MIN ( 1.0, b->xalign ) );
|
b->xalign = MAX(0, MIN(1.0, b->xalign));
|
||||||
|
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -25,66 +25,65 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include "widgets/scrollbar.h"
|
||||||
#include <xkbcommon/xkbcommon.h>
|
|
||||||
#include <glib.h>
|
|
||||||
#include "widgets/textbox.h"
|
|
||||||
#include "widgets/icon.h"
|
#include "widgets/icon.h"
|
||||||
#include "widgets/listview.h"
|
#include "widgets/listview.h"
|
||||||
#include "widgets/scrollbar.h"
|
#include "widgets/textbox.h"
|
||||||
|
#include <glib.h>
|
||||||
|
#include <xkbcommon/xkbcommon.h>
|
||||||
|
|
||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
|
|
||||||
/** The default width of the scrollbar */
|
/** The default width of the scrollbar */
|
||||||
#define DEFAULT_SCROLLBAR_WIDTH 8
|
#define DEFAULT_SCROLLBAR_WIDTH 8
|
||||||
|
|
||||||
static void scrollbar_draw ( widget *, cairo_t * );
|
static void scrollbar_draw(widget *, cairo_t *);
|
||||||
static void scrollbar_free ( widget * );
|
static void scrollbar_free(widget *);
|
||||||
|
|
||||||
static int scrollbar_get_desired_height ( widget *wid )
|
static int scrollbar_get_desired_height(widget *wid) {
|
||||||
{
|
|
||||||
// Want height we are.
|
// Want height we are.
|
||||||
return wid->h;
|
return wid->h;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
// This should behave more like a real scrollbar.
|
// This should behave more like a real scrollbar.
|
||||||
guint scrollbar_scroll_get_line ( const scrollbar *sb, int y )
|
guint scrollbar_scroll_get_line(const scrollbar *sb, int y) {
|
||||||
{
|
|
||||||
y -= sb->widget.border.top.base.distance;
|
y -= sb->widget.border.top.base.distance;
|
||||||
if ( y < 0 ) {
|
if (y < 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( y > sb->widget.h ) {
|
if (y > sb->widget.h) {
|
||||||
return sb->length - 1;
|
return sb->length - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
short r = ( sb->length * sb->widget.h ) / ( (double) ( sb->length + sb->pos_length ) );
|
short r =
|
||||||
|
(sb->length * sb->widget.h) / ((double)(sb->length + sb->pos_length));
|
||||||
short handle = sb->widget.h - r;
|
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;
|
short half_handle = handle / 2;
|
||||||
y -= half_handle;
|
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 );
|
unsigned int sel = ((y) / sec);
|
||||||
return MIN ( sel, sb->length - 1 );
|
return MIN(sel, sb->length - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void scrollbar_scroll ( scrollbar *sb, int y )
|
static void scrollbar_scroll(scrollbar *sb, int y) {
|
||||||
{
|
listview_set_selected((listview *)sb->widget.parent,
|
||||||
listview_set_selected ( (listview *) sb->widget.parent, scrollbar_scroll_get_line ( sb, y ) );
|
scrollbar_scroll_get_line(sb, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
static WidgetTriggerActionResult scrollbar_trigger_action ( widget *wid, MouseBindingMouseDefaultAction action, G_GNUC_UNUSED gint x, gint y, G_GNUC_UNUSED void *user_data )
|
static WidgetTriggerActionResult
|
||||||
{
|
scrollbar_trigger_action(widget *wid, MouseBindingMouseDefaultAction action,
|
||||||
scrollbar *sb = (scrollbar *) wid;
|
G_GNUC_UNUSED gint x, gint y,
|
||||||
switch ( action )
|
G_GNUC_UNUSED void *user_data) {
|
||||||
{
|
scrollbar *sb = (scrollbar *)wid;
|
||||||
|
switch (action) {
|
||||||
case MOUSE_CLICK_DOWN:
|
case MOUSE_CLICK_DOWN:
|
||||||
return WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_BEGIN;
|
return WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_BEGIN;
|
||||||
case MOUSE_CLICK_UP:
|
case MOUSE_CLICK_UP:
|
||||||
scrollbar_scroll ( sb, y );
|
scrollbar_scroll(sb, y);
|
||||||
return WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_END;
|
return WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_END;
|
||||||
case MOUSE_DCLICK_DOWN:
|
case MOUSE_DCLICK_DOWN:
|
||||||
case MOUSE_DCLICK_UP:
|
case MOUSE_DCLICK_UP:
|
||||||
@@ -93,23 +92,23 @@ static WidgetTriggerActionResult scrollbar_trigger_action ( widget *wid, MouseBi
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean scrollbar_motion_notify ( widget *wid, G_GNUC_UNUSED gint x, gint y )
|
static gboolean scrollbar_motion_notify(widget *wid, G_GNUC_UNUSED gint x,
|
||||||
{
|
gint y) {
|
||||||
scrollbar *sb = (scrollbar *) wid;
|
scrollbar *sb = (scrollbar *)wid;
|
||||||
scrollbar_scroll ( sb, y );
|
scrollbar_scroll(sb, y);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
scrollbar *scrollbar_create ( widget *parent, const char *name )
|
scrollbar *scrollbar_create(widget *parent, const char *name) {
|
||||||
{
|
scrollbar *sb = g_malloc0(sizeof(scrollbar));
|
||||||
scrollbar *sb = g_malloc0 ( sizeof ( scrollbar ) );
|
widget_init(WIDGET(sb), parent, WIDGET_TYPE_SCROLLBAR, name);
|
||||||
widget_init ( WIDGET ( sb ), parent, WIDGET_TYPE_SCROLLBAR, name );
|
|
||||||
sb->widget.x = 0;
|
sb->widget.x = 0;
|
||||||
sb->widget.y = 0;
|
sb->widget.y = 0;
|
||||||
sb->width = rofi_theme_get_distance ( WIDGET ( sb ), "handle-width", DEFAULT_SCROLLBAR_WIDTH );
|
sb->width = rofi_theme_get_distance(WIDGET(sb), "handle-width",
|
||||||
int width = distance_get_pixel ( sb->width, ROFI_ORIENTATION_HORIZONTAL );
|
DEFAULT_SCROLLBAR_WIDTH);
|
||||||
sb->widget.w = widget_padding_get_padding_width ( WIDGET ( sb ) ) + width;
|
int width = distance_get_pixel(sb->width, ROFI_ORIENTATION_HORIZONTAL);
|
||||||
sb->widget.h = widget_padding_get_padding_height ( WIDGET ( sb ) );
|
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.draw = scrollbar_draw;
|
||||||
sb->widget.free = scrollbar_free;
|
sb->widget.free = scrollbar_free;
|
||||||
@@ -124,30 +123,26 @@ scrollbar *scrollbar_create ( widget *parent, const char *name )
|
|||||||
return sb;
|
return sb;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void scrollbar_free ( widget *wid )
|
static void scrollbar_free(widget *wid) {
|
||||||
{
|
scrollbar *sb = (scrollbar *)wid;
|
||||||
scrollbar *sb = (scrollbar *) wid;
|
g_free(sb);
|
||||||
g_free ( sb );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void scrollbar_set_max_value ( scrollbar *sb, unsigned int max )
|
void scrollbar_set_max_value(scrollbar *sb, unsigned int max) {
|
||||||
{
|
if (sb != NULL) {
|
||||||
if ( sb != NULL ) {
|
sb->length = MAX(1u, max);
|
||||||
sb->length = MAX ( 1u, max );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void scrollbar_set_handle ( scrollbar *sb, unsigned int pos )
|
void scrollbar_set_handle(scrollbar *sb, unsigned int pos) {
|
||||||
{
|
if (sb != NULL) {
|
||||||
if ( sb != NULL ) {
|
sb->pos = MIN(sb->length, pos);
|
||||||
sb->pos = MIN ( sb->length, pos );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void scrollbar_set_handle_length ( scrollbar *sb, unsigned int pos_length )
|
void scrollbar_set_handle_length(scrollbar *sb, unsigned int pos_length) {
|
||||||
{
|
if (sb != NULL) {
|
||||||
if ( sb != NULL ) {
|
sb->pos_length = MIN(sb->length, MAX(1u, pos_length));
|
||||||
sb->pos_length = MIN ( sb->length, MAX ( 1u, pos_length ) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,27 +158,24 @@ void scrollbar_set_handle_length ( scrollbar *sb, unsigned int pos_length )
|
|||||||
* r ( num+hl ) = num*h
|
* r ( num+hl ) = num*h
|
||||||
* r = (num*h)/(num+hl)
|
* r = (num*h)/(num+hl)
|
||||||
*/
|
*/
|
||||||
static void scrollbar_draw ( widget *wid, cairo_t *draw )
|
static void scrollbar_draw(widget *wid, cairo_t *draw) {
|
||||||
{
|
scrollbar *sb = (scrollbar *)wid;
|
||||||
scrollbar *sb = (scrollbar *) wid;
|
unsigned int wh = widget_padding_get_remaining_height(wid);
|
||||||
unsigned int wh = widget_padding_get_remaining_height ( wid );
|
|
||||||
// Calculate position and size.
|
// Calculate position and size.
|
||||||
unsigned int r = ( sb->length * wh ) / ( (double) ( sb->length + sb->pos_length ) );
|
unsigned int r = (sb->length * wh) / ((double)(sb->length + sb->pos_length));
|
||||||
unsigned int handle = wid->h - r;
|
unsigned int handle = wid->h - r;
|
||||||
double sec = ( ( r ) / (double) ( sb->length - 1 ) );
|
double sec = ((r) / (double)(sb->length - 1));
|
||||||
unsigned int height = handle;
|
unsigned int height = handle;
|
||||||
unsigned int y = sb->pos * sec;
|
unsigned int y = sb->pos * sec;
|
||||||
// Set max pos.
|
// Set max pos.
|
||||||
y = MIN ( y, wh - handle );
|
y = MIN(y, wh - handle);
|
||||||
// Never go out of bar.
|
// Never go out of bar.
|
||||||
height = MAX ( 2, height );
|
height = MAX(2, height);
|
||||||
// Cap length;
|
// Cap length;
|
||||||
rofi_theme_get_color ( WIDGET ( sb ), "handle-color", draw );
|
rofi_theme_get_color(WIDGET(sb), "handle-color", draw);
|
||||||
|
|
||||||
cairo_rectangle ( draw,
|
cairo_rectangle(draw, widget_padding_get_left(wid),
|
||||||
widget_padding_get_left ( wid ),
|
widget_padding_get_top(wid) + y,
|
||||||
widget_padding_get_top ( wid ) + y,
|
widget_padding_get_remaining_width(wid), height);
|
||||||
widget_padding_get_remaining_width ( wid ),
|
cairo_fill(draw);
|
||||||
height );
|
|
||||||
cairo_fill ( draw );
|
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -25,242 +25,263 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "widgets/widget.h"
|
||||||
|
#include "theme.h"
|
||||||
|
#include "widgets/widget-internal.h"
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "widgets/widget.h"
|
|
||||||
#include "widgets/widget-internal.h"
|
|
||||||
#include "theme.h"
|
|
||||||
|
|
||||||
/** Default padding. */
|
/** Default padding. */
|
||||||
#define WIDGET_DEFAULT_PADDING 0
|
#define WIDGET_DEFAULT_PADDING 0
|
||||||
/** macro for initializing the padding struction. */
|
/** 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->type = type;
|
||||||
wid->parent = parent;
|
wid->parent = parent;
|
||||||
wid->name = g_strdup ( name );
|
wid->name = g_strdup(name);
|
||||||
wid->def_padding = (RofiPadding) { WIDGET_PADDING_INIT, WIDGET_PADDING_INIT, WIDGET_PADDING_INIT, WIDGET_PADDING_INIT };
|
wid->def_padding = (RofiPadding){WIDGET_PADDING_INIT, WIDGET_PADDING_INIT,
|
||||||
wid->def_border = (RofiPadding) { WIDGET_PADDING_INIT, WIDGET_PADDING_INIT, 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_border = (RofiPadding){WIDGET_PADDING_INIT, WIDGET_PADDING_INIT,
|
||||||
wid->def_margin = (RofiPadding) { WIDGET_PADDING_INIT, WIDGET_PADDING_INIT, 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->padding = rofi_theme_get_padding(wid, "padding", wid->def_padding);
|
||||||
wid->border = rofi_theme_get_padding ( wid, "border", wid->def_border );
|
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->border_radius =
|
||||||
wid->margin = rofi_theme_get_padding ( wid, "margin", wid->def_margin );
|
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
|
// 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 )
|
void widget_set_state(widget *widget, const char *state) {
|
||||||
{
|
if (widget == NULL) {
|
||||||
if ( widget == NULL ) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ( g_strcmp0 ( widget->state, state ) ) {
|
if (g_strcmp0(widget->state, state)) {
|
||||||
widget->state = state;
|
widget->state = state;
|
||||||
// Update border.
|
// Update border.
|
||||||
widget->border = rofi_theme_get_padding ( widget, "border", widget->def_border );
|
widget->border =
|
||||||
widget->border_radius = rofi_theme_get_padding ( widget, "border-radius", widget->def_border_radius );
|
rofi_theme_get_padding(widget, "border", widget->def_border);
|
||||||
if ( widget->set_state != NULL ) {
|
widget->border_radius = rofi_theme_get_padding(widget, "border-radius",
|
||||||
widget->set_state ( widget, state );
|
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 )
|
int widget_intersect(const widget *widget, int x, int y) {
|
||||||
{
|
if (widget == NULL) {
|
||||||
if ( widget == NULL ) {
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( x >= ( widget->x ) && x < ( widget->x + widget->w ) &&
|
if (x >= (widget->x) && x < (widget->x + widget->w) && y >= (widget->y) &&
|
||||||
y >= ( widget->y ) && y < ( widget->y + widget->h ) ) {
|
y < (widget->y + widget->h)) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void widget_resize ( widget *widget, short w, short h )
|
void widget_resize(widget *widget, short w, short h) {
|
||||||
{
|
if (widget == NULL) {
|
||||||
if ( widget == NULL ) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ( widget->resize != NULL ) {
|
if (widget->resize != NULL) {
|
||||||
if ( widget->w != w || widget->h != h ) {
|
if (widget->w != w || widget->h != h) {
|
||||||
widget->resize ( widget, w, h );
|
widget->resize(widget, w, h);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
widget->w = w;
|
widget->w = w;
|
||||||
widget->h = h;
|
widget->h = h;
|
||||||
}
|
}
|
||||||
// On a resize we always want to update.
|
// 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 )
|
void widget_move(widget *widget, short x, short y) {
|
||||||
{
|
if (widget == NULL) {
|
||||||
if ( widget == NULL ) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
widget->x = x;
|
widget->x = x;
|
||||||
widget->y = y;
|
widget->y = y;
|
||||||
}
|
}
|
||||||
void widget_set_type ( widget *widget, WidgetType type )
|
void widget_set_type(widget *widget, WidgetType type) {
|
||||||
{
|
if (widget == NULL) {
|
||||||
if ( widget == NULL ) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
widget->type = type;
|
widget->type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
WidgetType widget_type ( widget *widget )
|
WidgetType widget_type(widget *widget) {
|
||||||
{
|
if (widget == NULL) {
|
||||||
if ( widget == NULL ) {
|
|
||||||
return WIDGET_TYPE_UNKNOWN;
|
return WIDGET_TYPE_UNKNOWN;
|
||||||
}
|
}
|
||||||
return widget->type;
|
return widget->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean widget_enabled ( widget *widget )
|
gboolean widget_enabled(widget *widget) {
|
||||||
{
|
if (widget == NULL) {
|
||||||
if ( widget == NULL ) {
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
return widget->enabled;
|
return widget->enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void widget_set_enabled ( widget *widget, gboolean enabled )
|
void widget_set_enabled(widget *widget, gboolean enabled) {
|
||||||
{
|
if (widget == NULL) {
|
||||||
if ( widget == NULL ) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ( widget->enabled != enabled ) {
|
if (widget->enabled != enabled) {
|
||||||
widget->enabled = enabled;
|
widget->enabled = enabled;
|
||||||
widget_update ( widget );
|
widget_update(widget);
|
||||||
widget_update ( widget->parent );
|
widget_update(widget->parent);
|
||||||
widget_queue_redraw ( widget );
|
widget_queue_redraw(widget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void widget_draw ( widget *widget, cairo_t *d )
|
void widget_draw(widget *widget, cairo_t *d) {
|
||||||
{
|
if (widget == NULL) {
|
||||||
if ( widget == NULL ) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Check if enabled and if draw is implemented.
|
// 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.
|
// 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;
|
widget->need_redraw = FALSE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Store current state.
|
// Store current state.
|
||||||
cairo_save ( d );
|
cairo_save(d);
|
||||||
const int margin_left = distance_get_pixel ( widget->margin.left, ROFI_ORIENTATION_HORIZONTAL );
|
const int margin_left =
|
||||||
const int margin_top = distance_get_pixel ( widget->margin.top, ROFI_ORIENTATION_VERTICAL );
|
distance_get_pixel(widget->margin.left, ROFI_ORIENTATION_HORIZONTAL);
|
||||||
const int margin_right = distance_get_pixel ( widget->margin.right, ROFI_ORIENTATION_HORIZONTAL );
|
const int margin_top =
|
||||||
const int margin_bottom = distance_get_pixel ( widget->margin.bottom, ROFI_ORIENTATION_VERTICAL );
|
distance_get_pixel(widget->margin.top, ROFI_ORIENTATION_VERTICAL);
|
||||||
const int left = distance_get_pixel ( widget->border.left, ROFI_ORIENTATION_HORIZONTAL );
|
const int margin_right =
|
||||||
const int right = distance_get_pixel ( widget->border.right, ROFI_ORIENTATION_HORIZONTAL );
|
distance_get_pixel(widget->margin.right, ROFI_ORIENTATION_HORIZONTAL);
|
||||||
const int top = distance_get_pixel ( widget->border.top, ROFI_ORIENTATION_VERTICAL );
|
const int margin_bottom =
|
||||||
const int bottom = distance_get_pixel ( widget->border.bottom, ROFI_ORIENTATION_VERTICAL );
|
distance_get_pixel(widget->margin.bottom, ROFI_ORIENTATION_VERTICAL);
|
||||||
int radius_bl = distance_get_pixel ( widget->border_radius.left, ROFI_ORIENTATION_HORIZONTAL );
|
const int left =
|
||||||
int radius_tr = distance_get_pixel ( widget->border_radius.right, ROFI_ORIENTATION_HORIZONTAL );
|
distance_get_pixel(widget->border.left, ROFI_ORIENTATION_HORIZONTAL);
|
||||||
int radius_tl = distance_get_pixel ( widget->border_radius.top, ROFI_ORIENTATION_VERTICAL );
|
const int right =
|
||||||
int radius_br = distance_get_pixel ( widget->border_radius.bottom, ROFI_ORIENTATION_VERTICAL );
|
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 vspace =
|
||||||
double hspace = widget->w - margin_left - margin_right - left / 2.0 - right / 2.0;
|
widget->h - margin_top - margin_bottom - top / 2.0 - bottom / 2.0;
|
||||||
if ( ( radius_bl + radius_tl ) > ( vspace ) ) {
|
double hspace =
|
||||||
int j = ( ( vspace ) / 2.0 );
|
widget->w - margin_left - margin_right - left / 2.0 - right / 2.0;
|
||||||
radius_bl = MIN ( radius_bl, j );
|
if ((radius_bl + radius_tl) > (vspace)) {
|
||||||
radius_tl = MIN ( radius_tl, j );
|
int j = ((vspace) / 2.0);
|
||||||
|
radius_bl = MIN(radius_bl, j);
|
||||||
|
radius_tl = MIN(radius_tl, j);
|
||||||
}
|
}
|
||||||
if ( ( radius_br + radius_tr ) > ( vspace ) ) {
|
if ((radius_br + radius_tr) > (vspace)) {
|
||||||
int j = ( ( vspace ) / 2.0 );
|
int j = ((vspace) / 2.0);
|
||||||
radius_br = MIN ( radius_br, j );
|
radius_br = MIN(radius_br, j);
|
||||||
radius_tr = MIN ( radius_tr, j );
|
radius_tr = MIN(radius_tr, j);
|
||||||
}
|
}
|
||||||
if ( ( radius_tl + radius_tr ) > ( hspace ) ) {
|
if ((radius_tl + radius_tr) > (hspace)) {
|
||||||
int j = ( ( hspace ) / 2.0 );
|
int j = ((hspace) / 2.0);
|
||||||
radius_tr = MIN ( radius_tr, j );
|
radius_tr = MIN(radius_tr, j);
|
||||||
radius_tl = MIN ( radius_tl, j );
|
radius_tl = MIN(radius_tl, j);
|
||||||
}
|
}
|
||||||
if ( ( radius_bl + radius_br ) > ( hspace ) ) {
|
if ((radius_bl + radius_br) > (hspace)) {
|
||||||
int j = ( ( hspace ) / 2.0 );
|
int j = ((hspace) / 2.0);
|
||||||
radius_br = MIN ( radius_br, j );
|
radius_br = MIN(radius_br, j);
|
||||||
radius_bl = MIN ( radius_bl, j );
|
radius_bl = MIN(radius_bl, j);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Background painting.
|
// Background painting.
|
||||||
// Set new x/y position.
|
// Set new x/y position.
|
||||||
cairo_translate ( d, widget->x, widget->y );
|
cairo_translate(d, widget->x, widget->y);
|
||||||
cairo_set_line_width ( d, 0 );
|
cairo_set_line_width(d, 0);
|
||||||
|
|
||||||
// Outer outline outlines
|
// Outer outline outlines
|
||||||
double x1, y1, x2, y2;
|
double x1, y1, x2, y2;
|
||||||
x1 = margin_left + left / 2.0,
|
x1 = margin_left + left / 2.0, y1 = margin_top + top / 2.0,
|
||||||
y1 = margin_top + top / 2.0,
|
|
||||||
x2 = widget->w - margin_right - right / 2.0,
|
x2 = widget->w - margin_right - right / 2.0,
|
||||||
y2 = widget->h - margin_bottom - bottom / 2.0;
|
y2 = widget->h - margin_bottom - bottom / 2.0;
|
||||||
|
|
||||||
if ( radius_tl > 0 ) {
|
if (radius_tl > 0) {
|
||||||
cairo_move_to ( d, x1, y1 + radius_tl );
|
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 );
|
cairo_arc(d, x1 + radius_tl, y1 + radius_tl, radius_tl, -1.0 * G_PI,
|
||||||
|
-G_PI_2);
|
||||||
} else {
|
} else {
|
||||||
cairo_move_to ( d, x1, y1 );
|
cairo_move_to(d, x1, y1);
|
||||||
}
|
}
|
||||||
if ( radius_tr > 0 ) {
|
if (radius_tr > 0) {
|
||||||
cairo_line_to ( d, x2 - radius_tr, y1 );
|
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 );
|
cairo_arc(d, x2 - radius_tr, y1 + radius_tr, radius_tr, -G_PI_2,
|
||||||
|
0 * G_PI);
|
||||||
} else {
|
} else {
|
||||||
cairo_line_to ( d, x2, y1 );
|
cairo_line_to(d, x2, y1);
|
||||||
}
|
}
|
||||||
if ( radius_br > 0 ) {
|
if (radius_br > 0) {
|
||||||
cairo_line_to ( d, x2, y2 - radius_br );
|
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 );
|
cairo_arc(d, x2 - radius_br, y2 - radius_br, radius_br, 0.0 * G_PI,
|
||||||
|
G_PI_2);
|
||||||
} else {
|
} else {
|
||||||
cairo_line_to ( d, x2, y2 );
|
cairo_line_to(d, x2, y2);
|
||||||
}
|
}
|
||||||
if ( radius_bl > 0 ) {
|
if (radius_bl > 0) {
|
||||||
cairo_line_to ( d, x1 + radius_bl, y2 );
|
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 );
|
cairo_arc(d, x1 + radius_bl, y2 - radius_bl, radius_bl, G_PI_2,
|
||||||
|
1.0 * G_PI);
|
||||||
} else {
|
} 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 );
|
cairo_set_source_rgba(d, 1.0, 1.0, 1.0, 1.0);
|
||||||
rofi_theme_get_color ( widget, "background-color", d );
|
rofi_theme_get_color(widget, "background-color", d);
|
||||||
cairo_fill_preserve ( d );
|
cairo_fill_preserve(d);
|
||||||
if ( rofi_theme_get_image ( widget, "background-image", d ) ) {
|
if (rofi_theme_get_image(widget, "background-image", d)) {
|
||||||
cairo_fill_preserve ( d );
|
cairo_fill_preserve(d);
|
||||||
}
|
}
|
||||||
cairo_clip ( d );
|
cairo_clip(d);
|
||||||
|
|
||||||
widget->draw ( widget, d );
|
widget->draw(widget, d);
|
||||||
widget->need_redraw = FALSE;
|
widget->need_redraw = FALSE;
|
||||||
|
|
||||||
cairo_restore ( d );
|
cairo_restore(d);
|
||||||
|
|
||||||
if ( left != 0 || top != 0 || right != 0 || bottom != 0 ) {
|
if (left != 0 || top != 0 || right != 0 || bottom != 0) {
|
||||||
cairo_save ( d );
|
cairo_save(d);
|
||||||
cairo_translate ( d, widget->x, widget->y );
|
cairo_translate(d, widget->x, widget->y);
|
||||||
cairo_new_path ( d );
|
cairo_new_path(d);
|
||||||
rofi_theme_get_color ( widget, "border-color", d );
|
rofi_theme_get_color(widget, "border-color", d);
|
||||||
|
|
||||||
// Calculate the different offsets for the corners.
|
// Calculate the different offsets for the corners.
|
||||||
double minof_tr = MIN ( right / 2.0, top / 2.0 );
|
double minof_tr = MIN(right / 2.0, top / 2.0);
|
||||||
double minof_tl = MIN ( left / 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_br = MIN(right / 2.0, bottom / 2.0);
|
||||||
double minof_bl = MIN ( left / 2.0, bottom / 2.0 );
|
double minof_bl = MIN(left / 2.0, bottom / 2.0);
|
||||||
// Inner radius
|
// Inner radius
|
||||||
double radius_inner_tl = radius_tl - minof_tl;
|
double radius_inner_tl = radius_tl - minof_tl;
|
||||||
double radius_inner_tr = radius_tr - minof_tr;
|
double radius_inner_tr = radius_tr - minof_tr;
|
||||||
@@ -280,376 +301,387 @@ void widget_draw ( widget *widget, cairo_t *d )
|
|||||||
// bbl bbr
|
// bbl bbr
|
||||||
// | |
|
// | |
|
||||||
//
|
//
|
||||||
// The left and right part ($) start at thinkness top bottom when no radius
|
// The left and right part ($) start at thinkness top bottom when no
|
||||||
double offset_ltl = ( radius_inner_tl > 0 ) ? ( left ) + radius_inner_tl : left;
|
// radius
|
||||||
double offset_rtr = ( radius_inner_tr > 0 ) ? ( right ) + radius_inner_tr : right;
|
double offset_ltl =
|
||||||
double offset_lbl = ( radius_inner_bl > 0 ) ? ( left ) + radius_inner_bl : left;
|
(radius_inner_tl > 0) ? (left) + radius_inner_tl : left;
|
||||||
double offset_rbr = ( radius_inner_br > 0 ) ? ( right ) + radius_inner_br : right;
|
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
|
// 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_ttl = (radius_inner_tl > 0) ? (top) + radius_inner_tl
|
||||||
double offset_ttr = ( radius_inner_tr > 0 ) ? ( top ) + radius_inner_tr : ( radius_tr > 0 ) ? top : 0;
|
: (radius_tl > 0) ? top
|
||||||
double offset_bbl = ( radius_inner_bl > 0 ) ? ( bottom ) + radius_inner_bl : ( radius_bl > 0 ) ? bottom : 0;
|
: 0;
|
||||||
double offset_bbr = ( radius_inner_br > 0 ) ? ( bottom ) + radius_inner_br : ( radius_br > 0 ) ? bottom : 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 ) {
|
if (left > 0) {
|
||||||
cairo_set_line_width ( d, left );
|
cairo_set_line_width(d, left);
|
||||||
distance_get_linestyle ( widget->border.left, d );
|
distance_get_linestyle(widget->border.left, d);
|
||||||
cairo_move_to ( d, x1, margin_top + offset_ttl );
|
cairo_move_to(d, x1, margin_top + offset_ttl);
|
||||||
cairo_line_to ( d, x1, widget->h - margin_bottom - offset_bbl );
|
cairo_line_to(d, x1, widget->h - margin_bottom - offset_bbl);
|
||||||
cairo_stroke ( d );
|
cairo_stroke(d);
|
||||||
}
|
}
|
||||||
if ( right > 0 ) {
|
if (right > 0) {
|
||||||
cairo_set_line_width ( d, right );
|
cairo_set_line_width(d, right);
|
||||||
distance_get_linestyle ( widget->border.right, d );
|
distance_get_linestyle(widget->border.right, d);
|
||||||
cairo_move_to ( d, x2, margin_top + offset_ttr );
|
cairo_move_to(d, x2, margin_top + offset_ttr);
|
||||||
cairo_line_to ( d, x2, widget->h - margin_bottom - offset_bbr );
|
cairo_line_to(d, x2, widget->h - margin_bottom - offset_bbr);
|
||||||
cairo_stroke ( d );
|
cairo_stroke(d);
|
||||||
}
|
}
|
||||||
if ( top > 0 ) {
|
if (top > 0) {
|
||||||
cairo_set_line_width ( d, top );
|
cairo_set_line_width(d, top);
|
||||||
distance_get_linestyle ( widget->border.top, d );
|
distance_get_linestyle(widget->border.top, d);
|
||||||
cairo_move_to ( d, margin_left + offset_ltl, y1 );
|
cairo_move_to(d, margin_left + offset_ltl, y1);
|
||||||
cairo_line_to ( d, widget->w - margin_right - offset_rtr, y1 );
|
cairo_line_to(d, widget->w - margin_right - offset_rtr, y1);
|
||||||
cairo_stroke ( d );
|
cairo_stroke(d);
|
||||||
}
|
}
|
||||||
if ( bottom > 0 ) {
|
if (bottom > 0) {
|
||||||
cairo_set_line_width ( d, bottom );
|
cairo_set_line_width(d, bottom);
|
||||||
distance_get_linestyle ( widget->border.bottom, d );
|
distance_get_linestyle(widget->border.bottom, d);
|
||||||
cairo_move_to ( d, margin_left + offset_lbl, y2 );
|
cairo_move_to(d, margin_left + offset_lbl, y2);
|
||||||
cairo_line_to ( d, widget->w - margin_right - offset_rbr, y2 );
|
cairo_line_to(d, widget->w - margin_right - offset_rbr, y2);
|
||||||
cairo_stroke ( d );
|
cairo_stroke(d);
|
||||||
}
|
}
|
||||||
if ( radius_tl > 0 ) {
|
if (radius_tl > 0) {
|
||||||
distance_get_linestyle ( widget->border.left, d );
|
distance_get_linestyle(widget->border.left, d);
|
||||||
cairo_set_line_width ( d, 0 );
|
cairo_set_line_width(d, 0);
|
||||||
double radius_outer = radius_tl + minof_tl;
|
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_arc(d, margin_left + radius_outer, margin_top + radius_outer,
|
||||||
cairo_line_to ( d, margin_left + offset_ltl, margin_top );
|
radius_outer, -G_PI, -G_PI_2);
|
||||||
cairo_line_to ( d, margin_left + offset_ltl, margin_top + top );
|
cairo_line_to(d, margin_left + offset_ltl, margin_top);
|
||||||
if ( radius_inner_tl > 0 ) {
|
cairo_line_to(d, margin_left + offset_ltl, margin_top + top);
|
||||||
cairo_arc_negative ( d,
|
if (radius_inner_tl > 0) {
|
||||||
margin_left + left + radius_inner_tl,
|
cairo_arc_negative(d, margin_left + left + radius_inner_tl,
|
||||||
margin_top + top + radius_inner_tl,
|
margin_top + top + radius_inner_tl,
|
||||||
radius_inner_tl, -G_PI_2, G_PI );
|
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 + left, margin_top + offset_ttl);
|
||||||
}
|
}
|
||||||
cairo_line_to ( d, margin_left, margin_top + offset_ttl );
|
cairo_line_to(d, margin_left, margin_top + offset_ttl);
|
||||||
cairo_close_path ( d );
|
cairo_close_path(d);
|
||||||
cairo_fill ( d );
|
cairo_fill(d);
|
||||||
}
|
}
|
||||||
if ( radius_tr > 0 ) {
|
if (radius_tr > 0) {
|
||||||
distance_get_linestyle ( widget->border.right, d );
|
distance_get_linestyle(widget->border.right, d);
|
||||||
cairo_set_line_width ( d, 0 );
|
cairo_set_line_width(d, 0);
|
||||||
double radius_outer = radius_tr + minof_tr;
|
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_arc(d, widget->w - margin_right - radius_outer,
|
||||||
cairo_line_to ( d, widget->w - margin_right, margin_top + offset_ttr );
|
margin_top + radius_outer, radius_outer, -G_PI_2, 0);
|
||||||
cairo_line_to ( d, widget->w - margin_right - right, margin_top + offset_ttr );
|
cairo_line_to(d, widget->w - margin_right, margin_top + offset_ttr);
|
||||||
if ( radius_inner_tr > 0 ) {
|
cairo_line_to(d, widget->w - margin_right - right,
|
||||||
cairo_arc_negative ( d, widget->w - margin_right - right - radius_inner_tr,
|
margin_top + offset_ttr);
|
||||||
margin_top + top + radius_inner_tr,
|
if (radius_inner_tr > 0) {
|
||||||
radius_inner_tr, 0, -G_PI_2 );
|
cairo_arc_negative(
|
||||||
cairo_line_to ( d, widget->w - margin_right - offset_rtr, margin_top + top );
|
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_line_to(d, widget->w - margin_right - offset_rtr, margin_top);
|
||||||
cairo_close_path ( d );
|
cairo_close_path(d);
|
||||||
cairo_fill ( d );
|
cairo_fill(d);
|
||||||
}
|
}
|
||||||
if ( radius_br > 0 ) {
|
if (radius_br > 0) {
|
||||||
distance_get_linestyle ( widget->border.right, d );
|
distance_get_linestyle(widget->border.right, d);
|
||||||
cairo_set_line_width ( d, 1 );
|
cairo_set_line_width(d, 1);
|
||||||
double radius_outer = radius_br + minof_br;
|
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_arc(d, widget->w - margin_right - radius_outer,
|
||||||
cairo_line_to ( d, widget->w - margin_right - offset_rbr, widget->h - margin_bottom );
|
widget->h - margin_bottom - radius_outer, radius_outer, 0.0,
|
||||||
cairo_line_to ( d, widget->w - margin_right - offset_rbr, widget->h - margin_bottom - bottom );
|
G_PI_2);
|
||||||
if ( radius_inner_br > 0 ) {
|
cairo_line_to(d, widget->w - margin_right - offset_rbr,
|
||||||
cairo_arc_negative ( d, widget->w - margin_right - right - radius_inner_br,
|
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,
|
widget->h - margin_bottom - bottom - radius_inner_br,
|
||||||
radius_inner_br, G_PI_2, 0.0 );
|
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 - right,
|
||||||
|
widget->h - margin_bottom - offset_bbr);
|
||||||
}
|
}
|
||||||
cairo_line_to ( d, widget->w - margin_right, widget->h - margin_bottom - offset_bbr );
|
cairo_line_to(d, widget->w - margin_right,
|
||||||
cairo_close_path ( d );
|
widget->h - margin_bottom - offset_bbr);
|
||||||
cairo_fill ( d );
|
cairo_close_path(d);
|
||||||
|
cairo_fill(d);
|
||||||
}
|
}
|
||||||
if ( radius_bl > 0 ) {
|
if (radius_bl > 0) {
|
||||||
distance_get_linestyle ( widget->border.left, d );
|
distance_get_linestyle(widget->border.left, d);
|
||||||
cairo_set_line_width ( d, 1.0 );
|
cairo_set_line_width(d, 1.0);
|
||||||
double radius_outer = radius_bl + minof_bl;
|
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_arc(d, margin_left + radius_outer,
|
||||||
cairo_line_to ( d, margin_left, widget->h - margin_bottom - offset_bbl );
|
widget->h - margin_bottom - radius_outer, radius_outer,
|
||||||
cairo_line_to ( d, margin_left + left, widget->h - margin_bottom - offset_bbl );
|
G_PI_2, G_PI);
|
||||||
if ( radius_inner_bl > 0 ) {
|
cairo_line_to(d, margin_left, widget->h - margin_bottom - offset_bbl);
|
||||||
cairo_arc_negative ( d, margin_left + left + radius_inner_bl,
|
cairo_line_to(d, margin_left + left,
|
||||||
widget->h - margin_bottom - bottom - radius_inner_bl,
|
widget->h - margin_bottom - offset_bbl);
|
||||||
radius_inner_bl, G_PI, G_PI_2 );
|
if (radius_inner_bl > 0) {
|
||||||
cairo_line_to ( d, margin_left + offset_lbl, widget->h - margin_bottom - bottom );
|
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_line_to(d, margin_left + offset_lbl, widget->h - margin_bottom);
|
||||||
cairo_close_path ( d );
|
cairo_close_path(d);
|
||||||
|
|
||||||
cairo_fill ( d );
|
cairo_fill(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
cairo_restore ( d );
|
cairo_restore(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void widget_free ( widget *wid )
|
void widget_free(widget *wid) {
|
||||||
{
|
if (wid == NULL) {
|
||||||
if ( wid == NULL ) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ( wid->name != NULL ) {
|
if (wid->name != NULL) {
|
||||||
g_free ( wid->name );
|
g_free(wid->name);
|
||||||
}
|
}
|
||||||
if ( wid->free != NULL ) {
|
if (wid->free != NULL) {
|
||||||
wid->free ( wid );
|
wid->free(wid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int widget_get_height ( widget *widget )
|
int widget_get_height(widget *widget) {
|
||||||
{
|
if (widget == NULL) {
|
||||||
if ( widget == NULL ) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if ( widget->get_height == NULL ) {
|
if (widget->get_height == NULL) {
|
||||||
return widget->h;
|
return widget->h;
|
||||||
}
|
}
|
||||||
return widget->get_height ( widget );
|
return widget->get_height(widget);
|
||||||
}
|
}
|
||||||
int widget_get_width ( widget *widget )
|
int widget_get_width(widget *widget) {
|
||||||
{
|
if (widget == NULL) {
|
||||||
if ( widget == NULL ) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if ( widget->get_width == NULL ) {
|
if (widget->get_width == NULL) {
|
||||||
return widget->w;
|
return widget->w;
|
||||||
}
|
}
|
||||||
return widget->get_width ( widget );
|
return widget->get_width(widget);
|
||||||
}
|
}
|
||||||
int widget_get_x_pos ( widget *widget )
|
int widget_get_x_pos(widget *widget) {
|
||||||
{
|
if (widget == NULL) {
|
||||||
if ( widget == NULL ) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return widget->x;
|
return widget->x;
|
||||||
}
|
}
|
||||||
int widget_get_y_pos ( widget *widget )
|
int widget_get_y_pos(widget *widget) {
|
||||||
{
|
if (widget == NULL) {
|
||||||
if ( widget == NULL ) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return widget->y;
|
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;
|
*x -= widget->x;
|
||||||
*y -= widget->y;
|
*y -= widget->y;
|
||||||
if ( widget->parent == NULL ) {
|
if (widget->parent == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
widget_xy_to_relative ( widget->parent, x, y );
|
widget_xy_to_relative(widget->parent, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void widget_update ( widget *widget )
|
void widget_update(widget *widget) {
|
||||||
{
|
if (widget == NULL) {
|
||||||
if ( widget == NULL ) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// When (desired )size of widget changes.
|
// When (desired )size of widget changes.
|
||||||
if ( widget->update != NULL ) {
|
if (widget->update != NULL) {
|
||||||
widget->update ( widget );
|
widget->update(widget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void widget_queue_redraw ( widget *wid )
|
void widget_queue_redraw(widget *wid) {
|
||||||
{
|
if (wid == NULL) {
|
||||||
if ( wid == NULL ) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
widget *iter = wid;
|
widget *iter = wid;
|
||||||
// Find toplevel widget.
|
// Find toplevel widget.
|
||||||
while ( iter->parent != NULL ) {
|
while (iter->parent != NULL) {
|
||||||
iter->need_redraw = TRUE;
|
iter->need_redraw = TRUE;
|
||||||
iter = iter->parent;
|
iter = iter->parent;
|
||||||
}
|
}
|
||||||
iter->need_redraw = TRUE;
|
iter->need_redraw = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean widget_need_redraw ( widget *wid )
|
gboolean widget_need_redraw(widget *wid) {
|
||||||
{
|
if (wid == NULL) {
|
||||||
if ( wid == NULL ) {
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if ( !wid->enabled ) {
|
if (!wid->enabled) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
return wid->need_redraw;
|
return wid->need_redraw;
|
||||||
}
|
}
|
||||||
|
|
||||||
widget *widget_find_mouse_target ( widget *wid, WidgetType type, gint x, gint y )
|
widget *widget_find_mouse_target(widget *wid, WidgetType type, gint x, gint y) {
|
||||||
{
|
if (wid == NULL) {
|
||||||
if ( wid == NULL ) {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( wid->find_mouse_target != NULL ) {
|
if (wid->find_mouse_target != NULL) {
|
||||||
widget *target = wid->find_mouse_target ( wid, type, x, y );
|
widget *target = wid->find_mouse_target(wid, type, x, y);
|
||||||
if ( target != NULL ) {
|
if (target != NULL) {
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( wid->type == type || type == WIDGET_TYPE_UNKNOWN ) {
|
if (wid->type == type || type == WIDGET_TYPE_UNKNOWN) {
|
||||||
return wid;
|
return wid;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
WidgetTriggerActionResult widget_trigger_action ( widget *wid, guint action, gint x, gint y )
|
WidgetTriggerActionResult widget_trigger_action(widget *wid, guint action,
|
||||||
{
|
gint x, gint y) {
|
||||||
if ( wid == NULL ) {
|
if (wid == NULL) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if ( wid->trigger_action == NULL ) {
|
if (wid->trigger_action == NULL) {
|
||||||
return FALSE;
|
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 )
|
void widget_set_trigger_action_handler(widget *wid, widget_trigger_action_cb cb,
|
||||||
{
|
void *cb_data) {
|
||||||
if ( wid == NULL ) {
|
if (wid == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
wid->trigger_action = cb;
|
wid->trigger_action = cb;
|
||||||
wid->trigger_action_cb_data = cb_data;
|
wid->trigger_action_cb_data = cb_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean widget_motion_notify ( widget *wid, gint x, gint y )
|
gboolean widget_motion_notify(widget *wid, gint x, gint y) {
|
||||||
{
|
if (wid == NULL) {
|
||||||
if ( wid == NULL ) {
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if ( wid->motion_notify == NULL ) {
|
if (wid->motion_notify == NULL) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
return wid->motion_notify ( wid, x, y );
|
return wid->motion_notify(wid, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
int widget_padding_get_left ( const widget *wid )
|
int widget_padding_get_left(const widget *wid) {
|
||||||
{
|
if (wid == NULL) {
|
||||||
if ( wid == NULL ) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int distance = distance_get_pixel ( wid->padding.left, ROFI_ORIENTATION_HORIZONTAL );
|
int distance =
|
||||||
distance += distance_get_pixel ( wid->border.left, ROFI_ORIENTATION_HORIZONTAL );
|
distance_get_pixel(wid->padding.left, ROFI_ORIENTATION_HORIZONTAL);
|
||||||
distance += distance_get_pixel ( wid->margin.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;
|
return distance;
|
||||||
}
|
}
|
||||||
int widget_padding_get_right ( const widget *wid )
|
int widget_padding_get_right(const widget *wid) {
|
||||||
{
|
if (wid == NULL) {
|
||||||
if ( wid == NULL ) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int distance = distance_get_pixel ( wid->padding.right, ROFI_ORIENTATION_HORIZONTAL );
|
int distance =
|
||||||
distance += distance_get_pixel ( wid->border.right, ROFI_ORIENTATION_HORIZONTAL );
|
distance_get_pixel(wid->padding.right, ROFI_ORIENTATION_HORIZONTAL);
|
||||||
distance += distance_get_pixel ( wid->margin.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;
|
return distance;
|
||||||
}
|
}
|
||||||
int widget_padding_get_top ( const widget *wid )
|
int widget_padding_get_top(const widget *wid) {
|
||||||
{
|
if (wid == NULL) {
|
||||||
if ( wid == NULL ) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int distance = distance_get_pixel ( wid->padding.top, ROFI_ORIENTATION_VERTICAL );
|
int distance =
|
||||||
distance += distance_get_pixel ( wid->border.top, ROFI_ORIENTATION_VERTICAL );
|
distance_get_pixel(wid->padding.top, ROFI_ORIENTATION_VERTICAL);
|
||||||
distance += distance_get_pixel ( wid->margin.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;
|
return distance;
|
||||||
}
|
}
|
||||||
int widget_padding_get_bottom ( const widget *wid )
|
int widget_padding_get_bottom(const widget *wid) {
|
||||||
{
|
if (wid == NULL) {
|
||||||
if ( wid == NULL ) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int distance = distance_get_pixel ( wid->padding.bottom, ROFI_ORIENTATION_VERTICAL );
|
int distance =
|
||||||
distance += distance_get_pixel ( wid->border.bottom, ROFI_ORIENTATION_VERTICAL );
|
distance_get_pixel(wid->padding.bottom, ROFI_ORIENTATION_VERTICAL);
|
||||||
distance += distance_get_pixel ( wid->margin.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;
|
return distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
int widget_padding_get_remaining_width ( const widget *wid )
|
int widget_padding_get_remaining_width(const widget *wid) {
|
||||||
{
|
|
||||||
int width = wid->w;
|
int width = wid->w;
|
||||||
width -= widget_padding_get_left ( wid );
|
width -= widget_padding_get_left(wid);
|
||||||
width -= widget_padding_get_right ( wid );
|
width -= widget_padding_get_right(wid);
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
int widget_padding_get_remaining_height ( const widget *wid )
|
int widget_padding_get_remaining_height(const widget *wid) {
|
||||||
{
|
|
||||||
int height = wid->h;
|
int height = wid->h;
|
||||||
height -= widget_padding_get_top ( wid );
|
height -= widget_padding_get_top(wid);
|
||||||
height -= widget_padding_get_bottom ( wid );
|
height -= widget_padding_get_bottom(wid);
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
int widget_padding_get_padding_height ( const widget *wid )
|
int widget_padding_get_padding_height(const widget *wid) {
|
||||||
{
|
|
||||||
int height = 0;
|
int height = 0;
|
||||||
height += widget_padding_get_top ( wid );
|
height += widget_padding_get_top(wid);
|
||||||
height += widget_padding_get_bottom ( wid );
|
height += widget_padding_get_bottom(wid);
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
int widget_padding_get_padding_width ( const widget *wid )
|
int widget_padding_get_padding_width(const widget *wid) {
|
||||||
{
|
|
||||||
int width = 0;
|
int width = 0;
|
||||||
width += widget_padding_get_left ( wid );
|
width += widget_padding_get_left(wid);
|
||||||
width += widget_padding_get_right ( wid );
|
width += widget_padding_get_right(wid);
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
int widget_get_desired_height ( widget *wid )
|
int widget_get_desired_height(widget *wid) {
|
||||||
{
|
if (wid == NULL) {
|
||||||
if ( wid == NULL ) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if ( wid->get_desired_height == NULL ) {
|
if (wid->get_desired_height == NULL) {
|
||||||
return wid->h;
|
return wid->h;
|
||||||
}
|
}
|
||||||
return wid->get_desired_height ( wid );
|
return wid->get_desired_height(wid);
|
||||||
}
|
}
|
||||||
int widget_get_desired_width ( widget *wid )
|
int widget_get_desired_width(widget *wid) {
|
||||||
{
|
if (wid == NULL) {
|
||||||
if ( wid == NULL ) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if ( wid->get_desired_width == NULL ) {
|
if (wid->get_desired_width == NULL) {
|
||||||
return wid->w;
|
return wid->w;
|
||||||
}
|
}
|
||||||
return wid->get_desired_width ( wid );
|
return wid->get_desired_width(wid);
|
||||||
}
|
}
|
||||||
|
|
||||||
int widget_get_absolute_xpos ( widget *wid )
|
int widget_get_absolute_xpos(widget *wid) {
|
||||||
{
|
if (wid == NULL) {
|
||||||
if ( wid == NULL ) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int retv = wid->x;
|
int retv = wid->x;
|
||||||
if ( wid->parent != NULL ) {
|
if (wid->parent != NULL) {
|
||||||
retv += widget_get_absolute_xpos ( wid->parent );
|
retv += widget_get_absolute_xpos(wid->parent);
|
||||||
}
|
}
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
int widget_get_absolute_ypos ( widget *wid )
|
int widget_get_absolute_ypos(widget *wid) {
|
||||||
{
|
if (wid == NULL) {
|
||||||
if ( wid == NULL ) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int retv = wid->y;
|
int retv = wid->y;
|
||||||
if ( wid->parent != NULL ) {
|
if (wid->parent != NULL) {
|
||||||
retv += widget_get_absolute_ypos ( wid->parent );
|
retv += widget_get_absolute_ypos(wid->parent);
|
||||||
}
|
}
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
|
1541
source/xcb.c
1541
source/xcb.c
File diff suppressed because it is too large
Load Diff
1102
source/xrmoptions.c
1102
source/xrmoptions.c
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user