2014-02-03 15:46:44 -05:00
|
|
|
/**
|
2014-03-01 11:27:52 -05:00
|
|
|
* rofi
|
2014-02-03 15:46:44 -05:00
|
|
|
*
|
|
|
|
* MIT/X11 License
|
2015-12-31 18:27:00 -05:00
|
|
|
* Copyright 2013-2016 Qball Cow <qball@gmpclient.org>
|
2014-02-03 15:46:44 -05:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
2014-08-22 03:26:46 -04:00
|
|
|
#include <config.h>
|
2014-02-02 04:54:01 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2015-10-16 02:42:01 -04:00
|
|
|
#include <unistd.h>
|
2016-02-27 19:08:12 -05:00
|
|
|
#include <xcb/xcb.h>
|
|
|
|
#include <xcb/xkb.h>
|
2016-06-25 08:01:41 -04:00
|
|
|
#include <xcb/xcb_xrm.h>
|
2016-02-27 19:08:12 -05:00
|
|
|
#include <xkbcommon/xkbcommon.h>
|
|
|
|
#include <xkbcommon/xkbcommon-compose.h>
|
|
|
|
#include <xkbcommon/xkbcommon-x11.h>
|
2016-06-25 08:01:41 -04:00
|
|
|
#include <glib.h>
|
2016-03-01 12:11:55 -05:00
|
|
|
#include "xcb.h"
|
2016-06-25 08:01:41 -04:00
|
|
|
#include "xcb-internal.h"
|
2016-02-27 19:08:12 -05:00
|
|
|
#include "x11-helper.h"
|
2014-03-12 03:41:38 -04:00
|
|
|
#include "rofi.h"
|
2014-02-02 04:54:01 -05:00
|
|
|
#include "xrmoptions.h"
|
2016-01-07 10:01:56 -05:00
|
|
|
#include "settings.h"
|
2015-02-17 04:31:59 -05:00
|
|
|
#include "helper.h"
|
2014-02-02 04:54:01 -05:00
|
|
|
|
2016-10-16 13:38:33 -04:00
|
|
|
/** Different sources of configuration. */
|
2016-08-04 14:22:59 -04:00
|
|
|
const char * const ConfigSourceStr[] = {
|
|
|
|
"Default",
|
|
|
|
"XResources",
|
|
|
|
"File",
|
|
|
|
"Commandline",
|
|
|
|
};
|
2016-10-16 13:38:33 -04:00
|
|
|
/** Enumerator of different sources of configuration. */
|
2016-08-04 14:22:59 -04:00
|
|
|
enum ConfigSource
|
|
|
|
{
|
|
|
|
CONFIG_DEFAULT = 0,
|
|
|
|
CONFIG_XRESOURCES = 1,
|
|
|
|
CONFIG_FILE = 2,
|
|
|
|
CONFIG_CMDLINE = 3
|
|
|
|
};
|
|
|
|
|
2014-03-22 16:04:19 -04:00
|
|
|
typedef struct
|
|
|
|
{
|
2015-02-15 15:15:16 -05:00
|
|
|
int type;
|
|
|
|
const char * name;
|
2014-03-22 16:04:19 -04:00
|
|
|
union
|
|
|
|
{
|
2014-02-02 04:54:01 -05:00
|
|
|
unsigned int * num;
|
2014-08-21 13:03:21 -04:00
|
|
|
int * snum;
|
2014-03-22 16:04:19 -04:00
|
|
|
char ** str;
|
2015-02-15 15:15:16 -05:00
|
|
|
void *pointer;
|
2015-02-17 04:31:59 -05:00
|
|
|
char * charc;
|
2016-08-04 14:22:59 -04:00
|
|
|
} value;
|
|
|
|
char *mem;
|
|
|
|
const char *comment;
|
|
|
|
enum ConfigSource source;
|
2014-02-02 04:54:01 -05:00
|
|
|
} XrmOption;
|
2014-05-19 11:54:53 -04:00
|
|
|
/**
|
2015-02-17 04:31:59 -05:00
|
|
|
* Map X resource and commandline options to internal options
|
|
|
|
* Currently supports string, boolean and number (signed and unsigned).
|
2014-05-19 11:54:53 -04:00
|
|
|
*/
|
2014-05-17 17:06:45 -04:00
|
|
|
static XrmOption xrmOptions[] = {
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_String, "switchers", { .str = &config.modi }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_String, "modi", { .str = &config.modi }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Enabled modi", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_SNumber, "width", { .snum = &config.menu_width }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Window width", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_Number, "lines", { .num = &config.menu_lines }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Number of lines", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_Number, "columns", { .num = &config.menu_columns }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Number of columns", CONFIG_DEFAULT },
|
2015-11-11 18:18:43 -05:00
|
|
|
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_String, "font", { .str = &config.menu_font }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Font to use", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_String, "color-normal", { .str = &config.color_normal }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Color scheme for normal row", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_String, "color-urgent", { .str = &config.color_urgent }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Color scheme for urgent row", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_String, "color-active", { .str = &config.color_active }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Color scheme for active row", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_String, "color-window", { .str = &config.color_window }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Color scheme window", CONFIG_DEFAULT },
|
2015-11-11 18:18:43 -05:00
|
|
|
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_Number, "borderwidth", { .num = &config.menu_bw }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_Number, "bw", { .num = &config.menu_bw }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Border width", CONFIG_DEFAULT },
|
2015-11-11 18:18:43 -05:00
|
|
|
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_Number, "location", { .num = &config.location }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Location on screen", CONFIG_DEFAULT },
|
2015-11-11 18:18:43 -05:00
|
|
|
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_Number, "padding", { .num = &config.padding }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Padding", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_SNumber, "yoffset", { .snum = &config.y_offset }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Y-offset relative to location", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_SNumber, "xoffset", { .snum = &config.x_offset }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"X-offset relative to location", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_Boolean, "fixed-num-lines", { .num = &config.fixed_num_lines }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Always show number of lines", CONFIG_DEFAULT },
|
2015-11-11 18:18:43 -05:00
|
|
|
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_String, "terminal", { .str = &config.terminal_emulator }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Terminal to use", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_String, "ssh-client", { .str = &config.ssh_client }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Ssh client to use", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_String, "ssh-command", { .str = &config.ssh_command }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Ssh command to execute", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_String, "run-command", { .str = &config.run_command }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Run command to execute", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_String, "run-list-command", { .str = &config.run_list_command }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Command to get extra run targets", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_String, "run-shell-command", { .str = &config.run_shell_command }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Run command to execute that runs in shell", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_String, "window-command", { .str = &config.window_command }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Command executed on accep-entry-custom for window modus", CONFIG_DEFAULT },
|
2015-11-11 18:18:43 -05:00
|
|
|
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_Boolean, "disable-history", { .num = &config.disable_history }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Disable history in run/ssh", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_Boolean, "levenshtein-sort", { .num = &config.levenshtein_sort }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Use levenshtein sorting", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_Boolean, "case-sensitive", { .num = &config.case_sensitive }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Set case-sensitivity", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_Boolean, "cycle", { .num = &config.cycle }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Cycle through the results list", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_Boolean, "sidebar-mode", { .num = &config.sidebar_mode }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Enable sidebar-mode", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_SNumber, "eh", { .snum = &config.element_height }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Row height (in chars)", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_Boolean, "auto-select", { .num = &config.auto_select }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Enable auto select mode", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_Boolean, "parse-hosts", { .num = &config.parse_hosts }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Parse hosts file for ssh mode", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_Boolean, "parse-known-hosts", { .num = &config.parse_known_hosts }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Parse known_hosts file for ssh mode", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_String, "combi-modi", { .str = &config.combi_modi }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Set the modi to combine in combi mode", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_String, "matching", { .str = &config.matching }, NULL,
|
|
|
|
"Set the matching algorithm. (normal, regex, glob, fuzzy)", CONFIG_DEFAULT },
|
|
|
|
{ xrm_Boolean, "tokenize", { .num = &config.tokenize }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Tokenize input string", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_String, "monitor", { .str = &config.monitor }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"", CONFIG_DEFAULT },
|
2015-08-02 09:45:52 -04:00
|
|
|
/* Alias for dmenu compatibility. */
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_String, "m", { .str = &config.monitor }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Monitor id to show on", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_Number, "line-margin", { .num = &config.line_margin }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Margin between rows", CONFIG_DEFAULT },
|
2016-08-30 12:07:34 -04:00
|
|
|
{ xrm_Number, "line-padding", { .num = &config.line_padding }, NULL,
|
|
|
|
"Padding within rows", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_String, "filter", { .str = &config.filter }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Pre-set filter", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_String, "separator-style", { .str = &config.separator_style }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Separator style (none, dash, solid)", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_Boolean, "hide-scrollbar", { .num = &config.hide_scrollbar }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Hide scroll-bar", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_Boolean, "fullscreen", { .num = &config.fullscreen }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Fullscreen", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_Boolean, "fake-transparency", { .num = &config.fake_transparency }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Fake transparency", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_SNumber, "dpi", { .snum = &config.dpi }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"DPI", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_Number, "threads", { .num = &config.threads }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Threads to use for string matching", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_Number, "scrollbar-width", { .num = &config.scrollbar_width }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Scrollbar width", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_Number, "scroll-method", { .num = &config.scroll_method }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Scrolling method. (0: Page, 1: Centered)", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_String, "fake-background", { .str = &config.fake_background }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Background to use for fake transparency. (background or screenshot)", CONFIG_DEFAULT },
|
2016-08-25 02:43:40 -04:00
|
|
|
{ xrm_String, "window-format", { .str = &config.window_format }, NULL,
|
2016-08-04 14:22:59 -04:00
|
|
|
"Window Format. w (desktop name), t (title), n (name), r (role), c (class)", CONFIG_DEFAULT },
|
2016-09-27 02:51:17 -04:00
|
|
|
{ xrm_Boolean, "click-to-exit", { .snum = &config.click_to_exit }, NULL,
|
2016-09-08 16:42:41 -04:00
|
|
|
"Click outside the window to exit", CONFIG_DEFAULT },
|
2016-10-24 15:46:39 -04:00
|
|
|
{ xrm_Boolean, "show-match", { .snum = &config.show_match }, NULL,
|
|
|
|
"Indicate how it match by underlining it.", CONFIG_DEFAULT },
|
2014-02-02 04:54:01 -05:00
|
|
|
};
|
|
|
|
|
2016-10-16 13:38:33 -04:00
|
|
|
/** Dynamic array of extra options */
|
2016-10-18 07:49:24 -04:00
|
|
|
XrmOption *extra_options = NULL;
|
2016-10-16 13:38:33 -04:00
|
|
|
/** Number of entries in extra options array */
|
2015-02-15 15:15:16 -05:00
|
|
|
unsigned int num_extra_options = 0;
|
|
|
|
|
2015-10-16 02:42:01 -04:00
|
|
|
void config_parser_add_option ( XrmOptionType type, const char *key, void **value, const char *comment )
|
2015-02-15 15:15:16 -05:00
|
|
|
{
|
|
|
|
extra_options = g_realloc ( extra_options, ( num_extra_options + 1 ) * sizeof ( XrmOption ) );
|
|
|
|
|
2015-03-07 11:22:25 -05:00
|
|
|
extra_options[num_extra_options].type = type;
|
|
|
|
extra_options[num_extra_options].name = key;
|
2015-03-03 18:43:51 -05:00
|
|
|
extra_options[num_extra_options].value.pointer = value;
|
2015-10-16 02:42:01 -04:00
|
|
|
extra_options[num_extra_options].comment = comment;
|
2016-08-04 14:22:59 -04:00
|
|
|
extra_options[num_extra_options].source = CONFIG_DEFAULT;
|
2015-02-15 15:15:16 -05:00
|
|
|
if ( type == xrm_String ) {
|
|
|
|
extra_options[num_extra_options].mem = ( (char *) ( *value ) );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
extra_options[num_extra_options].mem = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
num_extra_options++;
|
|
|
|
}
|
|
|
|
|
2016-08-04 14:22:59 -04:00
|
|
|
static void config_parser_set ( XrmOption *option, char *xrmValue, enum ConfigSource source )
|
2015-02-15 15:15:16 -05:00
|
|
|
{
|
|
|
|
if ( option->type == xrm_String ) {
|
|
|
|
if ( ( option )->mem != NULL ) {
|
|
|
|
g_free ( option->mem );
|
|
|
|
option->mem = NULL;
|
|
|
|
}
|
2016-11-26 11:29:42 -05:00
|
|
|
*( option->value.str ) = g_strchomp ( g_strdup ( xrmValue ) );
|
2015-02-15 15:15:16 -05:00
|
|
|
|
|
|
|
// Memory
|
2015-03-03 18:43:51 -05:00
|
|
|
( option )->mem = *( option->value.str );
|
2015-02-15 15:15:16 -05:00
|
|
|
}
|
|
|
|
else if ( option->type == xrm_Number ) {
|
2016-06-25 08:01:41 -04:00
|
|
|
*( option->value.num ) = (unsigned int) g_ascii_strtoull ( xrmValue, NULL, 10 );
|
2015-02-15 15:15:16 -05:00
|
|
|
}
|
|
|
|
else if ( option->type == xrm_SNumber ) {
|
2016-06-25 08:01:41 -04:00
|
|
|
*( option->value.snum ) = (int) g_ascii_strtoll ( xrmValue, NULL, 10 );
|
2015-02-15 15:15:16 -05:00
|
|
|
}
|
|
|
|
else if ( option->type == xrm_Boolean ) {
|
2016-06-25 08:01:41 -04:00
|
|
|
if ( strlen ( xrmValue ) > 0 &&
|
|
|
|
g_ascii_strcasecmp ( xrmValue, "true" ) == 0 ) {
|
2015-03-03 18:43:51 -05:00
|
|
|
*( option->value.num ) = TRUE;
|
2015-02-15 15:15:16 -05:00
|
|
|
}
|
|
|
|
else{
|
2015-03-03 18:43:51 -05:00
|
|
|
*( option->value.num ) = FALSE;
|
2015-02-15 15:15:16 -05:00
|
|
|
}
|
|
|
|
}
|
2015-02-17 04:31:59 -05:00
|
|
|
else if ( option->type == xrm_Char ) {
|
2016-06-25 08:01:41 -04:00
|
|
|
*( option->value.charc ) = helper_parse_char ( xrmValue );
|
2015-02-17 04:31:59 -05:00
|
|
|
}
|
2016-08-04 14:22:59 -04:00
|
|
|
option->source = source;
|
2015-02-15 15:15:16 -05:00
|
|
|
}
|
2014-02-02 04:54:01 -05:00
|
|
|
|
2016-08-04 14:22:59 -04:00
|
|
|
static void __config_parse_xresource_options ( xcb_xrm_database_t *xDB, enum ConfigSource source )
|
2014-02-02 04:54:01 -05:00
|
|
|
{
|
2016-06-27 14:43:09 -04:00
|
|
|
const char * namePrefix = "rofi";
|
2014-02-02 04:54:01 -05:00
|
|
|
|
2015-02-15 15:15:16 -05:00
|
|
|
for ( unsigned int i = 0; i < sizeof ( xrmOptions ) / sizeof ( XrmOption ); ++i ) {
|
2016-06-27 14:43:09 -04:00
|
|
|
char *name = g_strdup_printf ( "%s.%s", namePrefix, xrmOptions[i].name );
|
2014-08-09 05:40:42 -04:00
|
|
|
|
2016-06-25 08:01:41 -04:00
|
|
|
char *xrmValue = NULL;
|
2016-06-27 02:26:09 -04:00
|
|
|
if ( xcb_xrm_resource_get_string ( xDB, name, NULL, &xrmValue ) == 0 ) {
|
2016-08-04 14:22:59 -04:00
|
|
|
config_parser_set ( &( xrmOptions[i] ), xrmValue, source );
|
2016-06-25 08:01:41 -04:00
|
|
|
}
|
|
|
|
if ( xrmValue ) {
|
|
|
|
free ( xrmValue );
|
2015-02-15 15:15:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free ( name );
|
|
|
|
}
|
2016-01-03 07:30:43 -05:00
|
|
|
}
|
2016-03-01 12:11:55 -05:00
|
|
|
void config_parse_xresource_options ( xcb_stuff *xcb )
|
2016-01-03 07:30:43 -05:00
|
|
|
{
|
2016-06-25 08:01:41 -04:00
|
|
|
xcb_xrm_database_t *xDB = xcb_xrm_database_from_default ( xcb->connection );
|
|
|
|
if ( xDB ) {
|
2016-08-04 14:22:59 -04:00
|
|
|
__config_parse_xresource_options ( xDB, CONFIG_XRESOURCES );
|
2016-06-25 08:01:41 -04:00
|
|
|
xcb_xrm_database_free ( xDB );
|
2016-01-03 07:30:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void config_parse_xresource_options_file ( const char *filename )
|
|
|
|
{
|
|
|
|
if ( !filename ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Map Xresource entries to rofi config options.
|
2016-06-25 08:01:41 -04:00
|
|
|
xcb_xrm_database_t *xDB = xcb_xrm_database_from_file ( filename );
|
2016-01-03 07:30:43 -05:00
|
|
|
if ( xDB == NULL ) {
|
|
|
|
return;
|
|
|
|
}
|
2016-08-04 14:22:59 -04:00
|
|
|
__config_parse_xresource_options ( xDB, CONFIG_FILE );
|
2016-06-25 08:01:41 -04:00
|
|
|
xcb_xrm_database_free ( xDB );
|
2015-02-15 15:15:16 -05:00
|
|
|
}
|
|
|
|
|
2015-02-17 04:31:59 -05:00
|
|
|
/**
|
|
|
|
* Parse an option from the commandline vector.
|
|
|
|
*/
|
2015-03-11 13:32:37 -04:00
|
|
|
static void config_parse_cmd_option ( XrmOption *option )
|
2015-02-17 04:31:59 -05:00
|
|
|
{
|
|
|
|
// Prepend a - to the option name.
|
|
|
|
char *key = g_strdup_printf ( "-%s", option->name );
|
|
|
|
switch ( option->type )
|
|
|
|
{
|
|
|
|
case xrm_Number:
|
2016-08-04 14:22:59 -04:00
|
|
|
if ( find_arg_uint ( key, option->value.num ) == TRUE ) {
|
|
|
|
option->source = CONFIG_CMDLINE;
|
|
|
|
}
|
2015-02-17 04:31:59 -05:00
|
|
|
break;
|
|
|
|
case xrm_SNumber:
|
2016-08-04 14:22:59 -04:00
|
|
|
if ( find_arg_int ( key, option->value.snum ) == TRUE ) {
|
|
|
|
option->source = CONFIG_CMDLINE;
|
|
|
|
}
|
2015-02-17 04:31:59 -05:00
|
|
|
break;
|
|
|
|
case xrm_String:
|
2015-03-11 13:32:37 -04:00
|
|
|
if ( find_arg_str ( key, option->value.str ) == TRUE ) {
|
2015-02-17 04:31:59 -05:00
|
|
|
if ( option->mem != NULL ) {
|
|
|
|
g_free ( option->mem );
|
|
|
|
option->mem = NULL;
|
|
|
|
}
|
2016-08-04 14:22:59 -04:00
|
|
|
option->source = CONFIG_CMDLINE;
|
2015-02-17 04:31:59 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case xrm_Boolean:
|
2015-03-11 13:32:37 -04:00
|
|
|
if ( find_arg ( key ) >= 0 ) {
|
2015-03-03 18:43:51 -05:00
|
|
|
*( option->value.num ) = TRUE;
|
2016-08-04 14:22:59 -04:00
|
|
|
option->source = CONFIG_CMDLINE;
|
2015-02-17 04:31:59 -05:00
|
|
|
}
|
2015-04-19 07:19:20 -04:00
|
|
|
else {
|
|
|
|
g_free ( key );
|
|
|
|
key = g_strdup_printf ( "-no-%s", option->name );
|
|
|
|
if ( find_arg ( key ) >= 0 ) {
|
|
|
|
*( option->value.num ) = FALSE;
|
2016-08-04 14:22:59 -04:00
|
|
|
option->source = CONFIG_CMDLINE;
|
2015-04-19 07:19:20 -04:00
|
|
|
}
|
|
|
|
}
|
2015-02-17 04:31:59 -05:00
|
|
|
break;
|
|
|
|
case xrm_Char:
|
2016-08-04 14:22:59 -04:00
|
|
|
if ( find_arg_char ( key, option->value.charc ) == TRUE ) {
|
|
|
|
option->source = CONFIG_CMDLINE;
|
|
|
|
}
|
2015-02-17 04:31:59 -05:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_free ( key );
|
|
|
|
}
|
|
|
|
|
2015-03-11 13:32:37 -04:00
|
|
|
void config_parse_cmd_options ( void )
|
2015-02-17 04:31:59 -05:00
|
|
|
{
|
|
|
|
for ( unsigned int i = 0; i < sizeof ( xrmOptions ) / sizeof ( XrmOption ); ++i ) {
|
|
|
|
XrmOption *op = &( xrmOptions[i] );
|
2015-03-11 13:32:37 -04:00
|
|
|
config_parse_cmd_option ( op );
|
2015-02-17 04:31:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-11 13:32:37 -04:00
|
|
|
void config_parse_cmd_options_dynamic ( void )
|
2015-02-17 04:31:59 -05:00
|
|
|
{
|
|
|
|
for ( unsigned int i = 0; i < num_extra_options; ++i ) {
|
|
|
|
XrmOption *op = &( extra_options[i] );
|
2015-03-11 13:32:37 -04:00
|
|
|
config_parse_cmd_option ( op );
|
2015-02-17 04:31:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-04 14:22:59 -04:00
|
|
|
static void __config_parse_xresource_options_dynamic ( xcb_xrm_database_t *xDB, enum ConfigSource source )
|
2015-02-15 15:15:16 -05:00
|
|
|
{
|
2016-06-27 14:43:09 -04:00
|
|
|
const char * namePrefix = "rofi";
|
2015-02-15 15:15:16 -05:00
|
|
|
|
|
|
|
for ( unsigned int i = 0; i < num_extra_options; ++i ) {
|
2016-06-27 02:26:09 -04:00
|
|
|
char *name;
|
2015-02-15 15:15:16 -05:00
|
|
|
|
2016-06-27 14:43:09 -04:00
|
|
|
name = g_strdup_printf ( "%s.%s", namePrefix, extra_options[i].name );
|
2016-06-25 08:01:41 -04:00
|
|
|
char *xrmValue = NULL;
|
2016-06-27 02:26:09 -04:00
|
|
|
if ( xcb_xrm_resource_get_string ( xDB, name, NULL, &xrmValue ) == 0 ) {
|
2016-08-04 14:22:59 -04:00
|
|
|
config_parser_set ( &( extra_options[i] ), xrmValue, source );
|
2016-06-25 08:01:41 -04:00
|
|
|
}
|
|
|
|
if ( xrmValue ) {
|
|
|
|
free ( xrmValue );
|
2014-02-02 04:54:01 -05:00
|
|
|
}
|
2014-08-09 05:40:42 -04:00
|
|
|
|
|
|
|
g_free ( name );
|
2014-02-02 04:54:01 -05:00
|
|
|
}
|
2016-01-03 07:30:43 -05:00
|
|
|
}
|
|
|
|
|
2016-03-01 12:11:55 -05:00
|
|
|
void config_parse_xresource_options_dynamic ( xcb_stuff *xcb )
|
2016-01-03 07:30:43 -05:00
|
|
|
{
|
2016-03-05 05:08:32 -05:00
|
|
|
char *name = window_get_text_prop ( xcb_stuff_get_root_window ( xcb ), XCB_ATOM_RESOURCE_MANAGER );
|
2016-03-04 13:41:32 -05:00
|
|
|
if ( name ) {
|
2016-06-25 08:01:41 -04:00
|
|
|
xcb_xrm_database_t *xDB = xcb_xrm_database_from_string ( name );
|
2016-08-04 14:22:59 -04:00
|
|
|
__config_parse_xresource_options_dynamic ( xDB, CONFIG_XRESOURCES );
|
2016-06-25 08:01:41 -04:00
|
|
|
xcb_xrm_database_free ( xDB );
|
2016-03-04 13:41:32 -05:00
|
|
|
g_free ( name );
|
|
|
|
}
|
2016-01-03 07:30:43 -05:00
|
|
|
}
|
|
|
|
void config_parse_xresource_options_dynamic_file ( const char *filename )
|
|
|
|
{
|
|
|
|
if ( !filename ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Map Xresource entries to rofi config options.
|
2016-06-25 08:01:41 -04:00
|
|
|
xcb_xrm_database_t *xDB = xcb_xrm_database_from_file ( filename );
|
2016-01-03 07:30:43 -05:00
|
|
|
if ( xDB == NULL ) {
|
|
|
|
return;
|
|
|
|
}
|
2016-08-04 14:22:59 -04:00
|
|
|
__config_parse_xresource_options_dynamic ( xDB, CONFIG_FILE );
|
2016-06-25 08:01:41 -04:00
|
|
|
xcb_xrm_database_free ( xDB );
|
2014-05-19 15:58:13 -04:00
|
|
|
}
|
|
|
|
|
2015-02-03 02:21:59 -05:00
|
|
|
void config_xresource_free ( void )
|
2014-05-19 15:58:13 -04:00
|
|
|
{
|
2015-02-15 15:15:16 -05:00
|
|
|
for ( unsigned int i = 0; i < ( sizeof ( xrmOptions ) / sizeof ( *xrmOptions ) ); ++i ) {
|
2014-06-04 15:29:23 -04:00
|
|
|
if ( xrmOptions[i].mem != NULL ) {
|
2014-08-09 05:40:42 -04:00
|
|
|
g_free ( xrmOptions[i].mem );
|
2014-05-19 15:58:13 -04:00
|
|
|
xrmOptions[i].mem = NULL;
|
|
|
|
}
|
|
|
|
}
|
2015-02-15 15:15:16 -05:00
|
|
|
for ( unsigned int i = 0; i < num_extra_options; ++i ) {
|
|
|
|
if ( extra_options[i].mem != NULL ) {
|
|
|
|
g_free ( extra_options[i].mem );
|
|
|
|
extra_options[i].mem = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( extra_options != NULL ) {
|
|
|
|
g_free ( extra_options );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-18 02:53:38 -05:00
|
|
|
static void xresource_dump_entry ( const char *namePrefix, XrmOption *option )
|
2015-02-15 15:15:16 -05:00
|
|
|
{
|
2016-08-04 14:22:59 -04:00
|
|
|
printf ( "! \"%s\" ", option->comment );
|
|
|
|
printf ( "Set from: %s\n", ConfigSourceStr[option->source] );
|
|
|
|
if ( option->source == CONFIG_DEFAULT ) {
|
|
|
|
printf ( "! " );
|
|
|
|
}
|
2015-02-15 15:15:16 -05:00
|
|
|
printf ( "%s.%s: %*s", namePrefix, option->name,
|
2015-05-02 06:08:50 -04:00
|
|
|
(int) ( 30 - strlen ( option->name ) ), "" );
|
2015-02-15 15:15:16 -05:00
|
|
|
switch ( option->type )
|
|
|
|
{
|
|
|
|
case xrm_Number:
|
2015-03-03 18:43:51 -05:00
|
|
|
printf ( "%u", *( option->value.num ) );
|
2015-02-15 15:15:16 -05:00
|
|
|
break;
|
|
|
|
case xrm_SNumber:
|
2015-03-03 18:43:51 -05:00
|
|
|
printf ( "%i", *( option->value.snum ) );
|
2015-02-15 15:15:16 -05:00
|
|
|
break;
|
|
|
|
case xrm_String:
|
2015-03-03 18:43:51 -05:00
|
|
|
if ( ( *( option->value.str ) ) != NULL ) {
|
|
|
|
printf ( "%s", *( option->value.str ) );
|
2015-02-15 15:15:16 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case xrm_Boolean:
|
2015-03-03 18:43:51 -05:00
|
|
|
printf ( "%s", ( *( option->value.num ) == TRUE ) ? "true" : "false" );
|
2015-02-15 15:15:16 -05:00
|
|
|
break;
|
2015-02-17 04:31:59 -05:00
|
|
|
case xrm_Char:
|
2015-03-03 18:43:51 -05:00
|
|
|
if ( *( option->value.charc ) > 32 && *( option->value.charc ) < 127 ) {
|
|
|
|
printf ( "%c", *( option->value.charc ) );
|
2015-02-17 04:31:59 -05:00
|
|
|
}
|
|
|
|
else {
|
2015-03-03 18:43:51 -05:00
|
|
|
printf ( "\\x%02X", *( option->value.charc ) );
|
2015-02-17 04:31:59 -05:00
|
|
|
}
|
|
|
|
break;
|
2015-02-15 15:15:16 -05:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
printf ( "\n" );
|
2014-02-02 04:54:01 -05:00
|
|
|
}
|
2014-05-22 15:56:57 -04:00
|
|
|
|
2016-01-07 07:32:33 -05:00
|
|
|
void config_parse_xresource_dump ( void )
|
2014-05-22 15:56:57 -04:00
|
|
|
{
|
2014-05-24 10:23:01 -04:00
|
|
|
const char * namePrefix = "rofi";
|
|
|
|
unsigned int entries = sizeof ( xrmOptions ) / sizeof ( *xrmOptions );
|
2014-06-04 15:29:23 -04:00
|
|
|
for ( unsigned int i = 0; i < entries; ++i ) {
|
2014-05-22 15:56:57 -04:00
|
|
|
// Skip duplicates.
|
2014-06-04 15:29:23 -04:00
|
|
|
if ( ( i + 1 ) < entries ) {
|
2015-03-03 18:43:51 -05:00
|
|
|
if ( xrmOptions[i].value.str == xrmOptions[i + 1].value.str ) {
|
2014-05-22 15:56:57 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2015-02-15 15:15:16 -05:00
|
|
|
xresource_dump_entry ( namePrefix, &( xrmOptions[i] ) );
|
|
|
|
}
|
|
|
|
for ( unsigned int i = 0; i < num_extra_options; i++ ) {
|
|
|
|
xresource_dump_entry ( namePrefix, &( extra_options[i] ) );
|
2014-05-22 15:56:57 -04:00
|
|
|
}
|
|
|
|
}
|
2015-10-15 16:33:44 -04:00
|
|
|
|
2015-10-16 02:42:01 -04:00
|
|
|
static void print_option_string ( XrmOption *xo, int is_term )
|
2015-10-15 16:33:44 -04:00
|
|
|
{
|
2015-10-16 02:42:01 -04:00
|
|
|
int l = strlen ( xo->name );
|
|
|
|
if ( is_term ) {
|
|
|
|
printf ( "\t"color_bold "-%s"color_reset " [string]%-*c%s\n", xo->name, 30 - l, ' ', xo->comment );
|
2016-08-04 14:22:59 -04:00
|
|
|
printf ( "\t"color_italic "%s"color_reset, ( *( xo->value.str ) == NULL ) ? "(unset)" : ( *( xo->value.str ) ) );
|
|
|
|
printf ( " "color_green "(%s)"color_reset "\n", ConfigSourceStr[xo->source] );
|
2015-10-16 02:42:01 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf ( "\t-%s [string]%-*c%s\n", xo->name, 30 - l, ' ', xo->comment );
|
2016-08-04 14:22:59 -04:00
|
|
|
printf ( "\t\t%s", ( *( xo->value.str ) == NULL ) ? "(unset)" : ( *( xo->value.str ) ) );
|
|
|
|
printf ( " (%s)\n", ConfigSourceStr[xo->source] );
|
2015-10-16 02:42:01 -04:00
|
|
|
}
|
2015-10-15 16:33:44 -04:00
|
|
|
}
|
2015-10-16 02:42:01 -04:00
|
|
|
static void print_option_number ( XrmOption *xo, int is_term )
|
2015-10-15 16:33:44 -04:00
|
|
|
{
|
2015-10-16 02:42:01 -04:00
|
|
|
int l = strlen ( xo->name );
|
|
|
|
if ( is_term ) {
|
|
|
|
printf ( "\t"color_bold "-%s"color_reset " [number]%-*c%s\n", xo->name, 30 - l, ' ', xo->comment );
|
2016-08-04 14:22:59 -04:00
|
|
|
printf ( "\t"color_italic "%u"color_reset, *( xo->value.num ) );
|
|
|
|
printf ( " "color_green "(%s)"color_reset "\n", ConfigSourceStr[xo->source] );
|
2015-10-16 02:42:01 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf ( "\t-%s [number]%-*c%s\n", xo->name, 30 - l, ' ', xo->comment );
|
2016-08-04 14:22:59 -04:00
|
|
|
printf ( "\t\t%u", *( xo->value.num ) );
|
|
|
|
printf ( " (%s)\n", ConfigSourceStr[xo->source] );
|
2015-10-16 02:42:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
static void print_option_snumber ( XrmOption *xo, int is_term )
|
|
|
|
{
|
|
|
|
int l = strlen ( xo->name );
|
|
|
|
if ( is_term ) {
|
|
|
|
printf ( "\t"color_bold "-%s"color_reset " [number]%-*c%s\n", xo->name, 30 - l, ' ', xo->comment );
|
2016-08-04 14:22:59 -04:00
|
|
|
printf ( "\t"color_italic "%d"color_reset, *( xo->value.snum ) );
|
|
|
|
printf ( " "color_green "(%s)"color_reset "\n", ConfigSourceStr[xo->source] );
|
2015-10-16 02:42:01 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf ( "\t-%s [number]%-*c%s\n", xo->name, 30 - l, ' ', xo->comment );
|
2016-08-04 14:22:59 -04:00
|
|
|
printf ( "\t\t%d", *( xo->value.snum ) );
|
|
|
|
printf ( " (%s)\n", ConfigSourceStr[xo->source] );
|
2015-10-16 02:42:01 -04:00
|
|
|
}
|
2015-10-15 16:33:44 -04:00
|
|
|
}
|
2015-10-16 02:42:01 -04:00
|
|
|
static void print_option_char ( XrmOption *xo, int is_term )
|
2015-10-15 16:33:44 -04:00
|
|
|
{
|
2015-10-16 02:42:01 -04:00
|
|
|
int l = strlen ( xo->name );
|
|
|
|
if ( is_term ) {
|
|
|
|
printf ( "\t"color_bold "-%s"color_reset " [character]%-*c%s\n", xo->name, 30 - l, ' ', xo->comment );
|
2016-08-04 14:22:59 -04:00
|
|
|
printf ( "\t"color_italic "%c"color_reset, *( xo->value.charc ) );
|
|
|
|
printf ( " "color_green "(%s)"color_reset "\n", ConfigSourceStr[xo->source] );
|
2015-10-16 02:42:01 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf ( "\t-%s [character]%-*c%s\n", xo->name, 30 - l, ' ', xo->comment );
|
2016-08-04 14:22:59 -04:00
|
|
|
printf ( "\t\t%c", *( xo->value.charc ) );
|
|
|
|
printf ( " (%s)\n", ConfigSourceStr[xo->source] );
|
2015-10-16 02:42:01 -04:00
|
|
|
}
|
2015-10-15 16:33:44 -04:00
|
|
|
}
|
2015-10-16 02:42:01 -04:00
|
|
|
static void print_option_boolean ( XrmOption *xo, int is_term )
|
2015-10-15 16:33:44 -04:00
|
|
|
{
|
2015-10-16 02:42:01 -04:00
|
|
|
int l = strlen ( xo->name );
|
|
|
|
if ( is_term ) {
|
|
|
|
printf ( "\t"color_bold "-[no-]%s"color_reset " %-*c%s\n", xo->name, 33 - l, ' ', xo->comment );
|
2016-08-04 14:22:59 -04:00
|
|
|
printf ( "\t"color_italic "%s"color_reset, ( *( xo->value.snum ) ) ? "True" : "False" );
|
|
|
|
printf ( " "color_green "(%s)"color_reset "\n", ConfigSourceStr[xo->source] );
|
2015-10-16 02:42:01 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf ( "\t-[no-]%s %-*c%s\n", xo->name, 33 - l, ' ', xo->comment );
|
2016-08-04 14:22:59 -04:00
|
|
|
printf ( "\t\t%s", ( *( xo->value.snum ) ) ? "True" : "False" );
|
|
|
|
printf ( " (%s)\n", ConfigSourceStr[xo->source] );
|
2015-10-16 02:42:01 -04:00
|
|
|
}
|
2015-10-15 16:33:44 -04:00
|
|
|
}
|
|
|
|
|
2015-10-16 02:42:01 -04:00
|
|
|
static void print_option ( XrmOption *xo, int is_term )
|
2015-10-15 16:33:44 -04:00
|
|
|
{
|
|
|
|
switch ( xo->type )
|
|
|
|
{
|
|
|
|
case xrm_String:
|
2015-10-16 02:42:01 -04:00
|
|
|
print_option_string ( xo, is_term );
|
2015-10-15 16:33:44 -04:00
|
|
|
break;
|
|
|
|
case xrm_Number:
|
2015-10-16 02:42:01 -04:00
|
|
|
print_option_number ( xo, is_term );
|
|
|
|
break;
|
2015-10-15 16:33:44 -04:00
|
|
|
case xrm_SNumber:
|
2015-10-16 02:42:01 -04:00
|
|
|
print_option_snumber ( xo, is_term );
|
2015-10-15 16:33:44 -04:00
|
|
|
break;
|
|
|
|
case xrm_Boolean:
|
2015-10-16 02:42:01 -04:00
|
|
|
print_option_boolean ( xo, is_term );
|
2015-10-15 16:33:44 -04:00
|
|
|
break;
|
|
|
|
case xrm_Char:
|
2015-10-16 02:42:01 -04:00
|
|
|
print_option_char ( xo, is_term );
|
2015-10-15 16:33:44 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void print_options ( void )
|
|
|
|
{
|
2015-10-16 02:42:01 -04:00
|
|
|
// Check output filedescriptor
|
|
|
|
int is_term = isatty ( fileno ( stdout ) );
|
2015-10-15 16:33:44 -04:00
|
|
|
unsigned int entries = sizeof ( xrmOptions ) / sizeof ( *xrmOptions );
|
|
|
|
for ( unsigned int i = 0; i < entries; ++i ) {
|
|
|
|
if ( ( i + 1 ) < entries ) {
|
|
|
|
if ( xrmOptions[i].value.str == xrmOptions[i + 1].value.str ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2015-10-16 02:42:01 -04:00
|
|
|
print_option ( &xrmOptions[i], is_term );
|
2015-10-15 16:33:44 -04:00
|
|
|
}
|
|
|
|
for ( unsigned int i = 0; i < num_extra_options; i++ ) {
|
2015-10-16 02:42:01 -04:00
|
|
|
print_option ( &extra_options[i], is_term );
|
2015-10-15 16:33:44 -04:00
|
|
|
}
|
|
|
|
}
|
2015-11-14 13:42:43 -05:00
|
|
|
|
2015-11-14 13:59:56 -05:00
|
|
|
void print_help_msg ( const char *option, const char *type, const char*text, const char *def, int isatty )
|
2015-11-14 13:42:43 -05:00
|
|
|
{
|
2015-11-15 07:12:43 -05:00
|
|
|
int l = 37 - strlen ( option ) - strlen ( type );
|
2015-11-14 13:42:43 -05:00
|
|
|
if ( isatty ) {
|
2015-11-15 07:12:43 -05:00
|
|
|
printf ( "\t%s%s%s %s %-*c%s\n", color_bold, option, color_reset, type, l, ' ', text );
|
2015-11-14 13:42:43 -05:00
|
|
|
if ( def != NULL ) {
|
|
|
|
printf ( "\t\t%s%s%s\n", color_italic, def, color_reset );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2015-11-15 07:12:43 -05:00
|
|
|
printf ( "\t%s %s %-*c%s\n", option, type, l, ' ', text );
|
2015-11-14 13:42:43 -05:00
|
|
|
if ( def != NULL ) {
|
|
|
|
printf ( "\t\t%s\n", def );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-10 12:20:04 -05:00
|
|
|
|
2016-01-07 07:32:33 -05:00
|
|
|
void config_parse_xresources_theme_dump ( void )
|
2015-12-10 12:20:04 -05:00
|
|
|
{
|
2015-12-10 14:57:43 -05:00
|
|
|
printf ( "! ------------------------------------------------------------------------------\n" );
|
|
|
|
printf ( "! ROFI Color theme\n" );
|
2015-12-31 13:04:38 -05:00
|
|
|
printf ( "! User: %s\n", g_get_user_name () );
|
2015-12-10 14:57:43 -05:00
|
|
|
printf ( "! ------------------------------------------------------------------------------\n" );
|
2016-03-20 05:16:55 -04:00
|
|
|
const char * const namePrefix = "rofi";
|
|
|
|
const char colorPrefix[] = "color-";
|
|
|
|
const char separatorStyle[] = "separator-style";
|
|
|
|
unsigned int entries = sizeof ( xrmOptions ) / sizeof ( *xrmOptions );
|
2015-12-10 12:20:04 -05:00
|
|
|
for ( unsigned int i = 0; i < entries; ++i ) {
|
2016-03-20 05:16:55 -04:00
|
|
|
if ( strncmp ( xrmOptions[i].name, colorPrefix, sizeof ( colorPrefix ) - 1 ) == 0 ) {
|
2015-12-10 14:57:43 -05:00
|
|
|
xresource_dump_entry ( namePrefix, &xrmOptions[i] );
|
2015-12-10 12:20:04 -05:00
|
|
|
}
|
2016-03-19 08:29:04 -04:00
|
|
|
else if ( strcmp ( xrmOptions[i].name, separatorStyle ) == 0 ) {
|
2015-12-10 16:00:41 -05:00
|
|
|
xresource_dump_entry ( namePrefix, &xrmOptions[i] );
|
|
|
|
}
|
2015-12-10 12:20:04 -05:00
|
|
|
}
|
|
|
|
}
|
2016-01-04 01:59:30 -05:00
|
|
|
|
2016-05-30 04:25:58 -04:00
|
|
|
static char * config_parser_return_display_help_entry ( XrmOption *option )
|
|
|
|
{
|
|
|
|
switch ( option->type )
|
|
|
|
{
|
|
|
|
case xrm_Number:
|
|
|
|
return g_markup_printf_escaped ( "<b%s</b> (%u) <span style='italic' size='small'>%s</span>",
|
|
|
|
option->name, *( option->value.num ), option->comment );
|
|
|
|
case xrm_SNumber:
|
|
|
|
return g_markup_printf_escaped ( "<b%s</b> (%d) <span style='italic' size='small'>%s</span>",
|
|
|
|
option->name, *( option->value.snum ), option->comment );
|
|
|
|
case xrm_String:
|
|
|
|
return g_markup_printf_escaped ( "<b>%s</b> (%s) <span style='italic' size='small'>%s</span>",
|
|
|
|
option->name,
|
|
|
|
( *( option->value.str ) != NULL ) ? *( option->value.str ) : "null",
|
|
|
|
option->comment
|
|
|
|
);
|
|
|
|
case xrm_Boolean:
|
|
|
|
return g_markup_printf_escaped ( "<b>%s</b> (%s) <span style='italic' size='small'>%s</span>",
|
|
|
|
option->name, ( *( option->value.num ) == TRUE ) ? "true" : "false", option->comment );
|
|
|
|
case xrm_Char:
|
|
|
|
if ( *( option->value.charc ) > 32 && *( option->value.charc ) < 127 ) {
|
|
|
|
return g_markup_printf_escaped ( "<b>%s</b> (%c) <span style='italic' size='small'>%s</span>",
|
|
|
|
option->name, *( option->value.charc ), option->comment );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return g_markup_printf_escaped ( "<b%s</b> (\\x%02X) <span style='italic' size='small'>%s</span>",
|
|
|
|
option->name, *( option->value.charc ), option->comment );
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_strdup ( "failed" );
|
|
|
|
}
|
|
|
|
|
|
|
|
char ** config_parser_return_display_help ( unsigned int *length )
|
|
|
|
{
|
|
|
|
unsigned int entries = sizeof ( xrmOptions ) / sizeof ( *xrmOptions );
|
|
|
|
char **retv = NULL;
|
|
|
|
for ( unsigned int i = 0; i < entries; ++i ) {
|
|
|
|
if ( ( i + 1 ) < entries ) {
|
|
|
|
if ( xrmOptions[i].value.str == xrmOptions[i + 1].value.str ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( strncmp ( xrmOptions[i].name, "kb", 2 ) != 0 ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
retv = g_realloc ( retv, ( ( *length ) + 2 ) * sizeof ( char* ) );
|
|
|
|
|
|
|
|
retv[( *length )] = config_parser_return_display_help_entry ( &xrmOptions[i] );
|
|
|
|
( *length )++;
|
|
|
|
}
|
|
|
|
for ( unsigned int i = 0; i < num_extra_options; i++ ) {
|
|
|
|
if ( strncmp ( extra_options[i].name, "kb", 2 ) != 0 ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
retv = g_realloc ( retv, ( ( *length ) + 2 ) * sizeof ( char* ) );
|
|
|
|
retv[( *length )] = config_parser_return_display_help_entry ( &extra_options[i] );
|
|
|
|
( *length )++;
|
|
|
|
}
|
|
|
|
if ( ( *length ) > 0 ) {
|
|
|
|
retv[( *length )] = NULL;
|
|
|
|
}
|
|
|
|
return retv;
|
|
|
|
}
|