Merge branch 'config'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Closes #3
authored by Daniel Eklöf · committed by Daniel Eklöf · parents 7cfb97e, 2844871 · Browse files · 18 files·+1898 added−512 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
18 files+1898 added−512 removed
- other:+1898 added−512 removed
Provenance
- Commit
9ce5e72- Tree
e8b638b- Author
Daniel Eklöf <daniel@ekloef.se>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent 1
7cfb97e- Parent 2
2844871
18 files changed+1898 added−512 removed
modified:completions/zsh/_fuzzel+1 added
1 #compdef fuzzel2 3 _arguments \4 -s \5+ '--config[path to configuration file (XDG_CONFIG_HOME/fuzzel/fuzzel.ini)]:config:_files' \6 '(-v --version)'{-v,--version}'[show the version number and quit]' \7 '(-h --help)'{-h,--help}'[show help message and quit]' \8 '(-o --output)'{-o,--output}'[output (monitor) to display on (none)]:output:->outputs' \9 '(-f --font)'{-f,--font}'[font name and style in fontconfig format (monospace)]:font:->fonts' \53 unmodified linesadded:doc/fuzzel.1.scd+267 added
1+fuzzel(1)2+3+# NAME4+fuzzel - display XDG applications in a searchable Wayland window5+6+# SYNOPSIS7+*fuzzel* [_OPTIONS_]...8+9+# DESCRIPTION10+11+*fuzzel* lists all available XDG applications in a searchable12+Window. The search box supports Emacs-like key bindings.13+14+The window size, font and colors can be configured with command line15+options:16+17+*--config*=_PATH_18+ Path to configuration file, see *fuzzel.ini*(5) for details.19+20+*-o*,*--output*=_OUTPUT_21+ Specifies the monitor to display the window on. In _Sway_, you can22+ list the available outputs with *swaymsg -t get_outputs*.23+24+ The default is to let the compositor choose output.25+26+*-f*,*--font*=_FONT_[,_FALLBACK1_,_FALLBACK2_,...]27+ Comma separated list of primary font, and fallback fonts, in28+ FontConfig format. See *FONT FORMAT*. Default: _monospace_.29+30+*-D*,*--dpi-aware*=_no|yes|auto_31+ When set to *yes*, fonts are sized using the monitor's DPI, making32+ a font of a given point size have the same physical size,33+ regardless of monitor.34+ 35+ In this mode, the monitor's scaling factor is ignored; doubling36+ the scaling factor will *not* double the font size.37+ 38+ When set to *no*, the monitor's DPI is ignored. The font is39+ instead sized using the monitor's scaling factor; doubling the40+ scaling factor *does* double the font size.41+ 42+ Finally, if set to *auto*, fonts will be sized using the monitor's43+ DPI if _all_ monitors have a scaling factor of 1. If at least one44+ monitor as a scaling factor larger than 1 (regardless of whether45+ the fuzzel window is mapped on that monitor or not), fonts will be46+ scaled using the scaling factor.47+ 48+ Note that this option typically does not work with bitmap fonts,49+ which only contains a pre-defined set of sizes, and cannot be50+ dynamically scaled. Whichever size (of the available ones) that51+ best matches the DPI or scaling factor, will be used.52+ 53+ Also note that if the font size has been specified in pixels54+ (*:pixelsize=*_N_, instead of *:size=*_N_), DPI scaling55+ (*dpi-aware=yes*) will have no effect (the specified pixel size56+ will be used as is). But, if the monitor's scaling factor is used57+ to size the font (*dpi-aware=no*), the font's pixel size will be58+ multiplied with the scaling factor.59+ 60+ Default: _auto_61+62+*-P*,*--prompt*=_PROMPT_63+ Prompt to use. Default: _> _.64+65+*-i*,*--icon-theme*=_NAME_66+ Icon theme to use. Note that this option is case sensitive; the67+ name must match the theme's folder name.68+ 69+ Example: _Adwaita_.70+ 71+ Default: _hicolor_.72+73+*-I*,*--no-icons*74+ Do not render any icons.75+76+*-F*,*--fields*=_FIELDS_77+ Comma separated list of XDG Desktop entry fields to match against:78+ 79+ - *filename*: the .desktop file's filename80+ - *name*: the application's name (title)81+ - *generic*: the application's generic name82+ - *exec*: the applications's executable, as specified in the desktop file. Note: may include command line options as well.83+ - *keywords*: the application's keywords84+ - *categories*: the application's categories85+ - *comment*: the application's comment86+ 87+ Default: _filename,name,generic_88+89+*--password*=[_CHARACTER_]90+ Password input. Render all typed text as _CHARACTER_. If91+ _CHARACTER_ is omitted, a *\** will be used.92+93+*-T*,*--terminal*=_TERMINAL ARGS_94+ Command to launch XDG applications with the property95+ *Terminal=true* (_htop_, for example). Example: _xterm -e_.96+ Default: _not set_.97+98+*-l*,*--lines*=COUNT99+ The (maximum) number of matches to display. This dictates the100+ window height. Default: _15_.101+102+*-w*,*--width*103+ Window width, in characters. Margins and borders not104+ included. Default: _30_.105+106+*-x*,*--horizontal-pad*=_PAD_107+ Horizontal padding between border and icons and text. In pixels,108+ subject to output scaling. Default: _40_.109+110+*-y*,*--vertical-pad*=_PAD_111+ Vertical padding between border and text. In pixels, subject to112+ output scaling. Default: _8_.113+114+*-p*,*--inner-pad*=_PAD_115+ Vertical padding between prompt and match list. In pixels, subject to116+ output scaling. Default: _0_.117+118+*-b*,*--background*=_HEX_119+ Background color. See *COLORS*. Default: _fdf6e3dd_.120+121+*-t*,*--text-color*=_HEX_122+ Text color. See *COLORS*. Default: _657b83ff_.123+124+*-m*,*--match-color*=_HEX_125+ The color of matching substring(s). As you start typing in the search126+ box, the matching part in each application's name is highlighted with127+ this color. See *COLORS*. Default: _cb4b16ff_.128+129+*-s*,*--selection-color*=_HEX_130+ The color to use as background of the currently selected131+ application. See *COLORS*. Default: _eee8d5dd_.132+133+*-S*,*--selection-text-color*=_HEX_134+ The text color of the currently selected application. See135+ *COLORS*. Default: _657b83ff_.136+137+*-B*,*--border-width*=_INT_138+ The width of the surrounding border, in pixels (subject to output139+ scaling). Default: _1_.140+141+*-r*,*--border-radius*=_INT_142+ The corner curvature. Larger means more rounded corners.143+ 0 disables rounded corners. Default: _10_.144+145+*-C*,*--border-color*=_HEX_146+ The color of the border. See *COLORS*. Default: _002b36ff_.147+148+*--show-actions*149+ Include desktop actions in the list. Desktop actions are150+ alternative actions some desktop entries have. Examples include151+ "New Window", "New Document", etc.152+153+*--no-fuzzy*154+ Disables fuzzy matching. When disabled, only exact (case155+ insensitive) substring matches are considered.156+157+*--fuzzy-min-length*=_VALUE_158+ Search strings shorter than this will not by fuzzy159+ matched. Default: _3_.160+161+*--fuzzy-max-length-discrepancy*=_VALUE_162+ Maximum allowed length difference between the search string, and a163+ fuzzy match. Larger values result in more fuzzy matches. Default:164+ _2_.165+166+*--fuzzy-max-distance*=_VALUE_167+ Maximum allowed levenshtein distance between the search string,168+ and a fuzzy match. Larger values result in more fuzzy169+ matches. Default: _1_.170+171+*--line-height*=_HEIGHT_172+ Override line height from font metrics. In points by default, but173+ can be specified as pixels by appending 'px'174+ (i.e. *--line-height=16px*). Default: _not set_.175+176+*--letter-spacing*=_AMOUNT_177+ Additional space between letters. In points by default, but can be178+ specified as pixels by appending 'px'179+ (i.e. *letter-spacing=5px*). Negative values are180+ supported. Default: _0_.181+182+*--launch-prefix*=_COMMAND_183+ Command to launch XDG applications with. Example: _swaymsg exec --_.184+ Default: _not set_.185+186+*-d*,*--dmenu*187+ dmenu compatibility mode. In this mode, the list entries are read188+ from stdin (newline separated). The selected entry is printed to189+ stdout. If the input string does not match any of the entries, the190+ input string is printed as is on stdout.191+ 192+ Alternatively, you can symlink the fuzzel binary to193+ *dmenu*. Fuzzel will then start in dmenu mode, without the194+ *--dmenu* argument.195+196+*--index*197+ Print selected entry's index instead of its text. **dmenu** mode198+ only.199+200+*-R*,*--no-run-if-empty*201+ Exit immediately, without showing the UI, if stdin is202+ empty. **dmenu** mode only.203+204+*--log-level*={*info*,*warning*,*error*,*none*}205+ Log level, used both for log output on stderr as well as206+ syslog. Default: _info_.207+208+*--log-colorize*=[{*never*,*always*,*auto*}]209+ Enables or disables colorization of log output on stderr.210+211+*--log-no-syslog*212+ Disables syslog logging. Logging is only done on stderr.213+214+*-v*,*--version*215+ Show the version number and quit216+217+# CONFIGURATION218+219+fuzzel will search for a configuration file in the following locations,220+in this order:221+222+ - *XDG_CONFIG_HOME/fuzzel/fuzzel.ini* (defaulting to223+ *~/.config/fuzzel/fuzzel.ini* if unset)224+ - *XDG_CONFIG_DIRS/fuzzel/fuzzel.ini* (defaulting to225+ */etc/xdg/fuzzel/fuzzel.ini* if unset)226+227+An example configuration file containing all options with their default value228+commented out will usually be installed to */etc/xdg/fuzzel/fuzzel.ini*.229+230+For more information, see *fuzzel.ini*(5).231+232+# FONT FORMAT233+234+The font is specified in FontConfig syntax. That is, a colon-separated235+list of font name and font options.236+237+_Examples_:238+- Dina:weight=bold:slant=italic239+- Arial:size=12240+241+242+# COLORS243+244+All colors must be specified as a RGBA quadruple, in hex format,245+without a leading '0x'.246+247+_EXAMPLES_:248+- white: *ffffffff* (no transparency)249+- black: *000000ff* (no transparency)250+- black: *00000010* (semi-transparent)251+- red: *ff0000ff* (no transparency)252+253+The default color scheme is _Solarized_.254+255+# FILES256+257+_$XDG_CACHE_HOME/fuzzel_258+ Stores a list of applications and their launch count. This allows259+ fuzzel to sort frequently launched applications at the top.260+261+_$XDG_RUNTIME_DIR/fuzzel-$WAYLAND_DISPLAY.lock_262+ Lock file, used to prevent multiple fuzzel instances from running263+ at the same time.264+265+# SEE ALSO266+267+*fuzzel.ini*(5)added:doc/fuzzel.ini.5.scd+208 added
1+fuzzel.ini(5)2+3+# NAME4+fuzzel.ini - configuration file for *fuzzel*(1)5+6+7+# DESCRIPTION8+9+*fuzzel* uses the standard _unix configuration format_, with section10+based key/value pairs. The default section is usually unnamed,11+i.e. not prefixed with a _[section]_. However it can also be12+explicitly named _[main]_, say if it needs to be reopened after any of13+the other sections.14+15+fuzzel will search for a configuration file in the following locations,16+in this order:17+18+ - *XDG_CONFIG_HOME/fuzzel/fuzzel.ini* (defaulting to19+ *~/.config/fuzzel/fuzzel.ini* if unset)20+ - *XDG_CONFIG_DIRS/fuzzel/fuzzel.ini* (defaulting to21+ */etc/xdg/fuzzel/fuzzel.ini* if unset)22+23+An example configuration file containing all options with their default value24+commented out will usually be installed to */etc/xdg/fuzzel/fuzzel.ini*.25+26+# SECTION: main27+28+*output*29+ Output (monitor) to display on. If unset, the compositor will30+ choose the monitor. Default: _not set_.31+32+*font*33+ Comma separated list of fonts to use, in fontconfig format. That34+ is, a font name followed by a list of colon-separated35+ options. Most noteworthy is *:size=n*, which is used to set the36+ font size. Note that the font size is also affected by the37+ *dpi-aware* option.38+ 39+ Examples:40+ - Dina:weight=bold:slant=italic41+ - Courier New:size=1242+ - Fantasque Sans Mono:fontfeatures=ss0143+ 44+ Default: _monospace_.45+46+*dpi-aware*47+ *auto*, *yes*, or *no*.48+ 49+ When set to *yes*, fonts are sized using the monitor's DPI, making50+ a font of a given size have the same physical size, regardless of51+ monitor.52+ 53+ In this mode, the monitor's scaling factor is ignored; doubling54+ the scaling factor will *not* double the font size.55+ 56+ When set to *no*, the monitor's DPI is ignored. The font is57+ instead sized using the monitor's scaling factor; doubling the58+ scaling factor *does* double the font size.59+ 60+ Finally, if set to *auto*, fonts will be sized using the monitor's61+ DPI if _all_ monitors have a scaling factor of 1. If at least one62+ monitor as a scaling factor larger than 1 (regardless of whether63+ the fuzzel window is mapped on that monitor or not), fonts will be64+ scaled using the scaling factor.65+ 66+ Note that this option typically does not work with bitmap fonts,67+ which only contains a pre-defined set of sizes, and cannot be68+ dynamically scaled. Whichever size (of the available ones) that69+ best matches the DPI or scaling factor, will be used.70+ 71+ Also note that if the font size has been specified in pixels72+ (*:pixelsize=*_N_, instead of *:size=*_N_), DPI scaling73+ (*dpi-aware=yes*) will have no effect (the specified pixel size74+ will be used as is). But, if the monitor's scaling factor is used75+ to size the font (*dpi-aware=no*), the font's pixel size will be76+ multiplied with the scaling factor.77+ 78+ Default: _auto_.79+80+*prompt*=81+ String to use as input prompt. Default: _> _.82+83+*icon-theme*84+ Icon theme. Note that the name is case sensitive. Default:85+ _hicolor_.86+87+*icons-enabled*88+ Boolean. When enabled, application icons (from the selected89+ *icon-theme*) will be rendered. Default: _yes_.90+91+*fields*92+ Comma separated list of XDG Desktop entry fields to match93+ against.94+ 95+ Even though fuzzel only displays the application names,96+ matching can (and by default is) be done against other fields as97+ well. Supported fields are:98+ 99+ - filename100+ - name101+ - generic102+ - exec103+ - categories104+ - keywords105+ - comment106+ 107+ Default: _filename,name,generic_.108+109+*password-character*110+ Default character to use with the command line option111+ *--password*. Note that this can be overridden on the command112+ line, by explicitly specifying the character with113+ *--password=X*. Default: _\*_.114+115+*fuzzy*116+ Boolean. Enables or disables fuzzy matching. Default: _yes_.117+118+*show-actions*119+ Boolean. Some desktop files define "actions", in addition to the120+ application itself. Examples are "new window", "preferences",121+ etc. When this option is enabled, those actions will be listed by122+ fuzzel. Default: _no_.123+124+*terminal*125+ terminal command to use when launching 'terminal' programs,126+ e.g. \"xterm -e\". Default: _not set_.127+128+*launch-prefix*129+ Prefix to add before argv of executed program. Default: _not set_.130+131+*lines*132+ Number of matches to show. Default: _15_.133+134+*width*135+ Window width, in characters. Border and margins are not included136+ in this. Default: _30_.137+138+*horizontal-pad*139+ Horizontal padding, in pixels, between border and140+ content. Default: _40_.141+142+*vertical-pad*143+ Vertical padding, in pixels, between border and content. Default:144+ _8_.145+146+*inner-pad*147+ Vertical padding between prompt and match list, in148+ pixels. Default: _0_.149+150+*line-height*151+ Override line height from font metrics. Default: use font metrics.152+153+*letter-spacing*154+ Additional letter spacing. Negative values are allowed. Default:155+ _0_.156+157+158+# SECTION: colors159+160+All color values are in RGBA.161+162+*background*163+ Background color. Default: _fdf6e3dd_.164+165+*text*166+ Text (foreground) color of unselected entries. Default:167+ _657b83ff_.168+169+*match*170+ Text (foreground) color of the matched substring. Default:171+ _cb4b16ff_.172+173+*selection*174+ Background color of the selected entry. Default: _eee8d5dd_.175+176+*selection-text*177+ Text (foreground) color of the selected entry. Default:178+ _657b83ff_.179+180+*border*181+ Border color. Default: _002b36ff_.182+183+184+# SECTION: border185+186+*width*187+ Width of the border, in pixels. Default: _1_.188+189+*radius*190+ Amount of corner "roundness". Default: _10_.191+192+193+# SECTION: dmenu194+195+*mode*196+ One of *text* or *index*. Determines what fuzzel prints on stdout197+ when an entry is selected: *text* prints the entry itself, *index*198+ prints the index of the selected entry. Default: _text_.199+200+*exit-immediately-if-empty*201+ Boolean. If enabled, fuzzel will not run at all (i.e. it will not202+ open a window, and will not print anything on stdout) if there's203+ nothing on stdin. Default: _no_.204+205+206+# SEE ALSO207+208+*fuzzel*(1)deleted:doc/fuzzel.scd-245 removed
1-fuzzel(1)2-3-# NAME4-fuzzel - display XDG applications in a searchable Wayland window5-6-# SYNOPSIS7-*fuzzel* [_OPTIONS_]...8-9-# DESCRIPTION10-11-*fuzzel* lists all available XDG applications in a searchable12-Window. The search box supports Emacs-like key bindings.13-14-The window size, font and colors can be configured with command line15-options:16-17-*-o*,*--output*=_OUTPUT_18- Specifies the monitor to display the window on. In _Sway_, you can19- list the available outputs with *swaymsg -t get_outputs*.20-21- The default is to let the compositor choose output.22-23-*-f*,*--font*=_FONT_[,_FALLBACK1_,_FALLBACK2_,...]24- Comma separated list of primary font, and fallback fonts, in25- FontConfig format. See *FONT FORMAT*. Default: _monospace_.26-27-*-D*,*--dpi-aware*=_no|yes|auto_28- When set to *yes*, fonts are sized using the monitor's DPI, making29- a font of a given point size have the same physical size,30- regardless of monitor.31- 32- In this mode, the monitor's scaling factor is ignored; doubling33- the scaling factor will *not* double the font size.34- 35- When set to *no*, the monitor's DPI is ignored. The font is36- instead sized using the monitor's scaling factor; doubling the37- scaling factor *does* double the font size.38- 39- Finally, if set to *auto*, fonts will be sized using the monitor's40- DPI if _all_ monitors have a scaling factor of 1. If at least one41- monitor as a scaling factor larger than 1 (regardless of whether42- the fuzzel window is mapped on that monitor or not), fonts will be43- scaled using the scaling factor.44- 45- Note that this option typically does not work with bitmap fonts,46- which only contains a pre-defined set of sizes, and cannot be47- dynamically scaled. Whichever size (of the available ones) that48- best matches the DPI or scaling factor, will be used.49- 50- Also note that if the font size has been specified in pixels51- (*:pixelsize=*_N_, instead of *:size=*_N_), DPI scaling52- (*dpi-aware=yes*) will have no effect (the specified pixel size53- will be used as is). But, if the monitor's scaling factor is used54- to size the font (*dpi-aware=no*), the font's pixel size will be55- multiplied with the scaling factor.56- 57- Default: _auto_58-59-*-P*,*--prompt*=_PROMPT_60- Prompt to use. Default: _> _.61-62-*-i*,*--icon-theme*=_NAME_63- Icon theme to use. Note that this option is case sensitive; the64- name must match the theme's folder name.65- 66- Example: _Adwaita_.67- 68- Default: _hicolor_.69-70-*-I*,*--no-icons*71- Do not render any icons.72-73-*-F*,*--fields*=_FIELDS_74- Comma separated list of XDG Desktop entry fields to match against:75- 76- - *filename*: the .desktop file's filename77- - *name*: the application's name (title)78- - *generic*: the application's generic name79- - *exec*: the applications's executable, as specified in the desktop file. Note: may include command line options as well.80- - *keywords*: the application's keywords81- - *categories*: the application's categories82- - *comment*: the application's comment83- 84- Default: _filename,name,generic_85-86-*--password*=[_CHARACTER_]87- Password input. Render all typed text as _CHARACTER_. If88- _CHARACTER_ is omitted, a *\** will be used.89-90-*-T*,*--terminal*=_TERMINAL ARGS_91- Command to launch XDG applications with the property92- *Terminal=true* (_htop_, for example). Example: _xterm -e_.93- Default: _not set_.94-95-*-l*,*--lines*=COUNT96- The (maximum) number of matches to display. This dictates the97- window height. Default: _15_.98-99-*-w*,*--width*100- Window width, in characters. Margins and borders not101- included. Default: _30_.102-103-*-x*,*--horizontal-pad*=_PAD_104- Horizontal padding between border and icons and text. In pixels,105- subject to output scaling. Default: _40_.106-107-*-y*,*--vertical-pad*=_PAD_108- Vertical padding between border and text. In pixels, subject to109- output scaling. Default: _8_.110-111-*-p*,*--inner-pad*=_PAD_112- Vertical padding between prompt and match list. In pixels, subject to113- output scaling. Default: _0_.114-115-*-b*,*--background*=_HEX_116- Background color. See *COLORS*. Default: _fdf6e3dd_.117-118-*-t*,*--text-color*=_HEX_119- Text color. See *COLORS*. Default: _657b83ff_.120-121-*-m*,*--match-color*=_HEX_122- The color of matching substring(s). As you start typing in the search123- box, the matching part in each application's name is highlighted with124- this color. See *COLORS*. Default: _cb4b16ff_.125-126-*-s*,*--selection-color*=_HEX_127- The color to use as background of the currently selected128- application. See *COLORS*. Default: _eee8d5dd_.129-130-*-S*,*--selection-text-color*=_HEX_131- The text color of the currently selected application. See132- *COLORS*. Default: _0x657b83ff_.133-134-*-B*,*--border-width*=_INT_135- The width of the surrounding border, in pixels (subject to output136- scaling). Default: _1_.137-138-*-r*,*--border-radius*=_INT_139- The corner curvature. Larger means more rounded corners.140- 0 disables rounded corners. Default: _10_.141-142-*-C*,*--border-color*=_HEX_143- The color of the border. See *COLORS*. Default: _002b36ff_.144-145-*--show-actions*146- Include desktop actions in the list. Desktop actions are147- alternative actions some desktop entries have. Examples include148- "New Window", "New Document", etc.149-150-*--no-fuzzy*151- Disables fuzzy matching. When disabled, only exact (case152- insensitive) substring matches are considered.153-154-*--fuzzy-min-length*=_VALUE_155- Search strings shorter than this will not by fuzzy156- matched. Default: _3_.157-158-*--fuzzy-max-length-discrepancy*=_VALUE_159- Maximum allowed length difference between the search string, and a160- fuzzy match. Larger values result in more fuzzy matches. Default:161- _2_.162-163-*--fuzzy-max-distance*=_VALUE_164- Maximum allowed levenshtein distance between the search string,165- and a fuzzy match. Larger values result in more fuzzy166- matches. Default: _1_.167-168-*--line-height*=_HEIGHT_169- Override line height from font metrics. In points by default, but170- can be specified as pixels by appending 'px'171- (i.e. *--line-height=16px*). Default: _not set_.172-173-*--letter-spacing*=_AMOUNT_174- Additional space between letters. In points by default, but can be175- specified as pixels by appending 'px'176- (i.e. *letter-spacing=5px*). Negative values are177- supported. Default: _0_.178-179-*--launch-prefix*=_COMMAND_180- Command to launch XDG applications with. Example: _swaymsg exec --_.181- Default: _not set_.182-183-*-d*,*--dmenu*184- dmenu compatibility mode. In this mode, the list entries are read185- from stdin (newline separated). The selected entry is printed to186- stdout. If the input string does not match any of the entries, the187- input string is printed as is on stdout.188- 189- Alternatively, you can symlink the fuzzel binary to190- *dmenu*. Fuzzel will then start in dmenu mode, without the191- *--dmenu* argument.192-193-*--index*194- Print selected entry's index instead of its text. **dmenu** mode195- only.196-197-*-R*,*--no-run-if-empty*198- Exit immediately, without showing the UI, if stdin is199- empty. **dmenu** mode only.200-201-*--log-level*={*info*,*warning*,*error*,*none*}202- Log level, used both for log output on stderr as well as203- syslog. Default: _info_.204-205-*--log-colorize*=[{*never*,*always*,*auto*}]206- Enables or disables colorization of log output on stderr.207-208-*--log-no-syslog*209- Disables syslog logging. Logging is only done on stderr.210-211-*-v*,*--version*212- Show the version number and quit213-214-# FONT FORMAT215-216-The font is specified in FontConfig syntax. That is, a colon-separated217-list of font name and font options.218-219-_Examples_:220-- Dina:weight=bold:slant=italic221-- Arial:size=12222-223-224-# COLORS225-226-All colors must be specified as a RGBA quadruple, in hex format,227-without a leading '0x'.228-229-_EXAMPLES_:230-- white: *ffffffff* (no transparency)231-- black: *000000ff* (no transparency)232-- black: *00000010* (semi-transparent)233-- red: *ff0000ff* (no transparency)234-235-The default color scheme is _Solarized_.236-237-# FILES238-239-_$XDG_CACHE_HOME/fuzzel_240- Stores a list of applications and their launch count. This allows241- fuzzel to sort frequently launched applications at the top.242-243-_$XDG_RUNTIME_DIR/fuzzel-$WAYLAND_DISPLAY.lock_244- Lock file, used to prevent multiple fuzzel instances from running245- at the same time.modified:doc/meson.build+7 added-5 removed
1 sh = find_program('sh', native: true)2 scdoc = dependency('scdoc', native: true)3 scdoc_prog = find_program(scdoc.get_variable('scdoc'), native: true)4 5-foreach man_src : ['fuzzel.scd']6- base = man_src.split('.')[-2]7- out = '@0@.1'.format(base)5+foreach man_src : [{'name': 'fuzzel', 'section': 1},6+ {'name': 'fuzzel.ini', 'section': 5}]7+ name = man_src['name']8+ section = man_src['section']9+ out = '@0@.@1@'.format(name, section)10 11 custom_target(12 out,13 output: out,12- input: man_src,14+ input: '@0@.@1@.scd'.format(name, section),15 command: [sh, '-c', '@0@ < @INPUT@'.format(scdoc_prog.full_path())],16 capture: true,17 install: true,16- install_dir: join_paths(get_option('mandir'), 'man1'))18+ install_dir: join_paths(get_option('mandir'), 'man@0@'.format(section)))19 endforeachmodified:CHANGELOG.md+2 added
19 unmodified lines20 ## Unreleased21 22 ### Added23 24+* Support for file based configuration25+ (https://codeberg.org/dnkl/fuzzel/issues/3).26 * If `argv[0]` is _dmenu_, fuzzel now starts in dmenu mode27 (https://codeberg.org/dnkl/fuzzel/issues/107).28 * `--password=[CHARACTER]` command line option. Intended to be used29 with “password input”; all typed text is rendered as _CHARACTER_,330 unmodified linesadded:config.c+957 added
1+#include "config.h"2+3+#include <sys/types.h>4+#include <sys/stat.h>5+6+#include <stdio.h>7+#include <assert.h>8+#include <errno.h>9+#include <fcntl.h>10+#include <limits.h>11+#include <pwd.h>12+#include <stdio.h>13+#include <stdlib.h>14+#include <string.h>15+#include <unistd.h>16+#include <ctype.h>17+18+19+#define LOG_MODULE "config"20+#define LOG_ENABLE_DBG 021+#include "log.h"22+23+#define ALEN(v) (sizeof(v) / sizeof((v)[0]))24+25+struct context {26+ struct config *conf;27+ const char *section;28+ const char *key;29+ const char *value;30+31+ const char *path;32+ unsigned lineno;33+34+ bool errors_are_fatal;35+};36+37+#define LOG_CONTEXTUAL_ERR(...) \38+ log_contextual(ctx, LOG_CLASS_ERROR, __FILE__, __LINE__, __VA_ARGS__)39+40+#define LOG_CONTEXTUAL_WARN(...) \41+ log_contextual(ctx, LOG_CLASS_WARNING, __FILE__, __LINE__, __VA_ARGS__)42+43+#define LOG_CONTEXTUAL_ERRNO(...) \44+ log_contextual_errno(ctx, __FILE__, __LINE__, __VA_ARGS__)45+46+47+static void __attribute__((format(printf, 5, 6)))48+log_contextual(struct context *ctx, enum log_class log_class,49+ const char *file, int lineno, const char *fmt, ...)50+{51+ char *formatted_msg = NULL;52+ va_list va;53+ va_start(va, fmt);54+ if (vasprintf(&formatted_msg, fmt, va) < 0) {55+ va_end(va);56+ return;57+ }58+59+ va_end(va);60+61+ bool print_dot = ctx->key != NULL;62+ bool print_colon = ctx->value != NULL;63+64+ if (!print_dot)65+ ctx->key = "";66+67+ if (!print_colon)68+ ctx->value = "";69+70+ log_msg(71+ log_class, LOG_MODULE, file, lineno, "%s:%d: [%s]%s%s%s%s: %s",72+ ctx->path, ctx->lineno, ctx->section, print_dot ? "." : "",73+ ctx->key, print_colon ? ": " : "", ctx->value, formatted_msg);74+ free(formatted_msg);75+}76+77+struct config_file {78+ char *path; /* Full, absolute, path */79+ int fd; /* FD of file, O_RDONLY */80+};81+82+static const char *83+get_user_home_dir(void)84+{85+ const struct passwd *passwd = getpwuid(getuid());86+ if (passwd == NULL)87+ return NULL;88+ return passwd->pw_dir;89+}90+91+static struct config_file92+open_config(void)93+{94+ char *path = NULL;95+ struct config_file ret = {.path = NULL, .fd = -1};96+97+ const char *xdg_config_home = getenv("XDG_CONFIG_HOME");98+ const char *xdg_config_dirs = getenv("XDG_CONFIG_DIRS");99+ const char *home_dir = get_user_home_dir();100+ char *xdg_config_dirs_copy = NULL;101+102+ /* First, check XDG_CONFIG_HOME (or .config, if unset) */103+ if (xdg_config_home != NULL && xdg_config_home[0] != '\0') {104+ if (asprintf(&path, "%s/fuzzel/fuzzel.ini", xdg_config_home) < 0) {105+ LOG_ERRNO("failed to build fuzzel.ini path");106+ goto done;107+ }108+ } else if (home_dir != NULL) {109+ if (asprintf(&path, "%s/.config/fuzzel/fuzzel.ini", home_dir) < 0) {110+ LOG_ERRNO("failed to build fuzzel.ini path");111+ goto done;112+ }113+ }114+115+ if (path != NULL) {116+ int fd = open(path, O_RDONLY | O_CLOEXEC);117+118+ if (fd >= 0) {119+ ret = (struct config_file) {.path = path, .fd = fd};120+ path = NULL;121+ goto done;122+ }123+ }124+125+ xdg_config_dirs_copy = xdg_config_dirs != NULL && xdg_config_dirs[0] != '\0'126+ ? strdup(xdg_config_dirs)127+ : strdup("/etc/xdg");128+129+ if (xdg_config_dirs_copy == NULL || xdg_config_dirs_copy[0] == '\0')130+ goto done;131+132+ for (const char *conf_dir = strtok(xdg_config_dirs_copy, ":");133+ conf_dir != NULL;134+ conf_dir = strtok(NULL, ":"))135+ {136+ free(path);137+ path = NULL;138+139+ if (asprintf(&path, "%s/fuzzel/fuzzel.ini", conf_dir) < 0) {140+ LOG_ERRNO("failed to build fuzzel.ini path");141+ goto done;142+ }143+144+ int fd = open(path, O_RDONLY | O_CLOEXEC);145+ if (fd >= 0) {146+ ret = (struct config_file){.path = path, .fd = fd};147+ path = NULL;148+ goto done;149+ }150+ }151+152+done:153+ free(xdg_config_dirs_copy);154+ free(path);155+ return ret;156+}157+158+static bool159+str_to_ulong(const char *s, int base, unsigned long *res)160+{161+ if (s == NULL)162+ return false;163+164+ errno = 0;165+ char *end = NULL;166+167+ *res = strtoul(s, &end, base);168+ return errno == 0 && *end == '\0';169+}170+171+static bool172+str_to_uint32(const char *s, int base, uint32_t *res)173+{174+ unsigned long v;175+ bool ret = str_to_ulong(s, base, &v);176+ if (!ret)177+ return false;178+ if (v > UINT32_MAX)179+ return false;180+ *res = v;181+ return true;182+}183+184+static bool185+value_to_str(struct context *ctx, char **res)186+{187+ free(*res);188+ *res = strdup(ctx->value);189+ return true;190+}191+192+static bool193+value_to_wchars(struct context *ctx, char32_t **res)194+{195+ char32_t *s = ambstoc32(ctx->value);196+ if (s == NULL) {197+ LOG_CONTEXTUAL_ERR("not a valie string value");198+ return false;199+ }200+201+ free(*res);202+ *res = s;203+ return true;204+}205+206+static bool207+value_to_bool(struct context *ctx, bool *res)208+{209+ static const char *const yes[] = {"on", "true", "yes", "1"};210+ static const char *const no[] = {"off", "false", "no", "0"};211+212+ for (size_t i = 0; i < ALEN(yes); i++) {213+ if (strcasecmp(ctx->value, yes[i]) == 0) {214+ *res = true;215+ return true;216+ }217+ }218+219+ for (size_t i = 0; i < ALEN(no); i++) {220+ if (strcasecmp(ctx->value, no[i]) == 0) {221+ *res = false;222+ return true;223+ }224+ }225+226+ LOG_CONTEXTUAL_ERR("invalid boolean value");227+ return false;228+}229+230+static bool231+value_to_uint32(struct context *ctx, int base, uint32_t *res)232+{233+ if (!str_to_uint32(ctx->value, base, res)){234+ LOG_CONTEXTUAL_ERR(235+ "invalid integer value, or outside range 0-%u", UINT32_MAX);236+ return false;237+ }238+ return true;239+}240+241+static bool242+value_to_color(struct context *ctx, bool allow_alpha, struct rgba *color)243+{244+ if (strlen(ctx->value) != 8) {245+ LOG_CONTEXTUAL_ERR("not a valid color value");246+ return false;247+ }248+249+ uint32_t v;250+ if (!str_to_uint32(ctx->value, 16, &v)) {251+ LOG_CONTEXTUAL_ERR("not a valid color value");252+ return false;253+ }254+255+ if (!allow_alpha && (v & 0x000000ff) != 0) {256+ LOG_CONTEXTUAL_ERR("color value must not have an alpha component");257+ return false;258+ }259+260+ *color = conf_hex_to_rgba(v);261+ return true;262+}263+264+static bool265+value_to_double(struct context *ctx, float *res)266+{267+ const char *s = ctx->value;268+269+ if (s == NULL)270+ return false;271+272+ errno = 0;273+ char *end = NULL;274+275+ *res = strtof(s, &end);276+ if (!(errno == 0 && *end == '\0')) {277+ LOG_CONTEXTUAL_ERR("invalid decimal value");278+ return false;279+ }280+281+ return true;282+}283+284+static bool285+value_to_pt_or_px(struct context *ctx, struct pt_or_px *res)286+{287+ const char *s = ctx->value;288+289+ size_t len = s != NULL ? strlen(s) : 0;290+ if (len >= 2 && s[len - 2] == 'p' && s[len - 1] == 'x') {291+ errno = 0;292+ char *end = NULL;293+294+ long value = strtol(s, &end, 10);295+ if (!(errno == 0 && end == s + len - 2)) {296+ LOG_CONTEXTUAL_ERR("invalid px value (must be on the form 12px)");297+ return false;298+ }299+ res->pt = 0;300+ res->px = value;301+ } else {302+ float value;303+ if (!value_to_double(ctx, &value))304+ return false;305+ res->pt = value;306+ res->px = 0;307+ }308+309+ return true;310+}311+312+static bool313+value_to_enum(struct context *ctx, const char **value_map, int *res)314+{315+ size_t str_len = 0;316+ size_t count = 0;317+318+ for (; value_map[count] != NULL; count++) {319+ if (strcasecmp(value_map[count], ctx->value) == 0) {320+ *res = count;321+ return true;322+ }323+ str_len += strlen(value_map[count]);324+ }325+326+ const size_t size = str_len + count * 4 + 1;327+ char valid_values[512];328+ size_t idx = 0;329+ assert(size < sizeof(valid_values));330+331+ for (size_t i = 0; i < count; i++)332+ idx += snprintf(&valid_values[idx], size - idx, "'%s', ", value_map[i]);333+334+ if (count > 0)335+ valid_values[idx - 2] = '\0';336+337+ LOG_CONTEXTUAL_ERR("not one of %s", valid_values);338+ *res = -1;339+ return false;340+}341+342+343+static bool parse_config_file(344+ FILE *f, struct config *conf, const char *path, bool errors_are_fatal);345+346+static bool347+parse_section_main(struct context *ctx)348+{349+ struct config *conf = ctx->conf;350+ const char *key = ctx->key;351+ const char *value = ctx->value;352+353+ if (strcmp(key, "output") == 0)354+ return value_to_str(ctx, &conf->output);355+356+ else if (strcmp(key, "font") == 0)357+ return value_to_str(ctx, &conf->font);358+359+ else if (strcmp(key, "dpi-aware") == 0) {360+ if (strcmp(value, "auto") == 0)361+ conf->dpi_aware = DPI_AWARE_AUTO;362+ else {363+ bool value;364+ if (!value_to_bool(ctx, &value))365+ return false;366+ conf->dpi_aware = value ? DPI_AWARE_YES : DPI_AWARE_NO;367+ }368+ return true;369+ }370+371+ else if (strcmp(key, "prompt") == 0)372+ return value_to_wchars(ctx, &conf->prompt);373+374+ else if (strcmp(key, "icon-theme") == 0)375+ return value_to_str(ctx, &conf->icon_theme);376+377+ else if (strcmp(key, "icons-enabled") == 0)378+ return value_to_bool(ctx, &conf->icons_enabled);379+380+ else if (strcmp(key, "fields") == 0) {381+ _Static_assert(sizeof(conf->match_fields) == sizeof(int),382+ "enum is not 32-bit");383+384+ return value_to_enum(385+ ctx,386+ (const char *[]){387+ "filename",388+ "name",389+ "generic",390+ "exec",391+ "categories",392+ "keywords",393+ "comment",394+ NULL},395+ (int *)&conf->match_fields);396+ }397+398+ else if (strcmp(key, "password-character") == 0) {399+ char32_t *password_chars = ambstoc32(value);400+ if (password_chars == NULL || c32len(password_chars) != 1) {401+ LOG_CONTEXTUAL_ERR("ivnalid password character");402+ free(password_chars);403+ return false;404+ }405+406+ conf->password = password_chars[0];407+ free(password_chars);408+ return true;409+ }410+411+ else if (strcmp(key, "fuzzy") == 0)412+ return value_to_bool(ctx, &conf->fuzzy.enabled);413+414+ else if (strcmp(key, "show-actions") == 0)415+ return value_to_bool(ctx, &conf->actions_enabled);416+417+ else if (strcmp(key, "terminal") == 0)418+ return value_to_str(ctx, &conf->terminal);419+420+ else if (strcmp(key, "launch-prefix") == 0)421+ return value_to_str(ctx, &conf->launch_prefix);422+423+ else if (strcmp(key, "lines") == 0)424+ return value_to_uint32(ctx, 10, &conf->lines);425+426+ else if (strcmp(key, "width") == 0)427+ return value_to_uint32(ctx, 10, &conf->chars);428+429+ else if (strcmp(key, "horizontal-pad") == 0)430+ return value_to_uint32(ctx, 10, &conf->pad.x);431+432+ else if (strcmp(key, "vertical-pad") == 0)433+ return value_to_uint32(ctx, 10, &conf->pad.y);434+435+ else if (strcmp(key, "inner-pad") == 0)436+ return value_to_uint32(ctx, 10, &conf->pad.inner);437+438+ else if (strcmp(key, "line-height") == 0)439+ return value_to_pt_or_px(ctx, &conf->line_height);440+441+ else if (strcmp(key, "letter-spacing") == 0)442+ return value_to_pt_or_px(ctx, &conf->letter_spacing);443+444+ else445+ LOG_CONTEXTUAL_ERR("not a valid option: %s", key);446+447+ return false;448+}449+450+static bool451+parse_section_colors(struct context *ctx)452+{453+ struct config *conf = ctx->conf;454+ const char *key = ctx->key;455+456+ if (strcmp(key, "background") == 0)457+ return value_to_color(ctx, true, &conf->colors.background);458+459+ else if (strcmp(key, "text") == 0)460+ return value_to_color(ctx, true, &conf->colors.text);461+462+ else if (strcmp(key, "match") == 0)463+ return value_to_color(ctx, true, &conf->colors.match);464+465+ else if (strcmp(key, "selection") == 0)466+ return value_to_color(ctx, true, &conf->colors.selection);467+468+ else if (strcmp(key, "selection-text") == 0)469+ return value_to_color(ctx, true, &conf->colors.selection_text);470+471+ else if (strcmp(key, "border") == 0)472+ return value_to_color(ctx, true, &conf->colors.border);473+474+ else475+ LOG_CONTEXTUAL_ERR("not a valid option: %s", key);476+477+ return false;478+}479+480+static bool481+parse_section_border(struct context *ctx)482+{483+ struct config *conf = ctx->conf;484+ const char *key = ctx->key;485+486+ if (strcmp(key, "width") == 0)487+ return value_to_uint32(ctx, 10, &conf->border.size);488+489+ else if (strcmp(key, "radius") == 0)490+ return value_to_uint32(ctx, 10, &conf->border.radius);491+492+ else493+ LOG_CONTEXTUAL_ERR("not a valid option: %s", key);494+495+ return false;496+}497+498+static bool499+parse_section_dmenu(struct context *ctx)500+{501+ struct config *conf = ctx->conf;502+ const char *key = ctx->key;503+504+ if (strcmp(key, "mode") == 0) {505+ _Static_assert(sizeof(conf->dmenu.mode) == sizeof(int),506+ "enum is not 32-bit");507+508+ return value_to_enum(509+ ctx,510+ (const char *[]){"text", "index", NULL},511+ (int *)&conf->dmenu.mode);512+ }513+514+ else if (strcmp(key, "exit-immediately-if-empty") == 0)515+ return value_to_bool(ctx, &conf->dmenu.exit_immediately_if_empty);516+517+ else518+ LOG_CONTEXTUAL_ERR("not a valid option: %s", key);519+520+ return false;521+}522+523+enum section {524+ SECTION_MAIN,525+ SECTION_COLORS,526+ SECTION_BORDER,527+ SECTION_DMENU,528+ SECTION_COUNT,529+};530+531+/* Function pointer, called for each key/value line */532+typedef bool (*parser_fun_t)(struct context *ctx);533+534+static const struct {535+ parser_fun_t fun;536+ const char *name;537+} section_info[] = {538+ [SECTION_MAIN] = {&parse_section_main, "main"},539+ [SECTION_COLORS] = {&parse_section_colors, "colors"},540+ [SECTION_BORDER] = {&parse_section_border, "border"},541+ [SECTION_DMENU] = {&parse_section_dmenu, "dmenu"},542+};543+544+static enum section545+str_to_section(const char *str)546+{547+ for (enum section section = SECTION_MAIN; section < SECTION_COUNT; ++section) {548+ if (strcmp(str, section_info[section].name) == 0)549+ return section;550+ }551+ return SECTION_COUNT;552+}553+554+static bool555+parse_key_value(char *kv, const char **section, const char **key, const char **value)556+{557+ bool section_is_needed = section != NULL;558+559+ /* Strip leading whitespace */560+ while (isspace(kv[0]))561+ ++kv;562+563+ if (section_is_needed)564+ *section = "main";565+566+ if (kv[0] == '=')567+ return false;568+569+ *key = kv;570+ *value = NULL;571+572+ size_t kvlen = strlen(kv);573+574+ /* Strip trailing whitespace */575+ while (isspace(kv[kvlen - 1]))576+ kvlen--;577+ kv[kvlen] = '\0';578+579+ for (size_t i = 0; i < kvlen; ++i) {580+ if (kv[i] == '.' && section_is_needed) {581+ section_is_needed = false;582+ *section = kv;583+ kv[i] = '\0';584+ if (i == kvlen - 1 || kv[i + 1] == '=') {585+ *key = NULL;586+ return false;587+ }588+ *key = &kv[i + 1];589+ } else if (kv[i] == '=') {590+ kv[i] = '\0';591+ if (i != kvlen - 1)592+ *value = &kv[i + 1];593+ break;594+ }595+ }596+597+ if (*value == NULL)598+ return false;599+600+ /* Strip trailing whitespace from key (leading stripped earlier) */601+ {602+ assert(!isspace(*key[0]));603+604+ char *end = (char *)*key + strlen(*key) - 1;605+ while (isspace(end[0]))606+ end--;607+ end[1] = '\0';608+ }609+610+ /* Strip leading whitespace from value (trailing stripped earlier) */611+ while (isspace(*value[0]))612+ ++*value;613+614+ return true;615+}616+617+static bool618+parse_config_file(FILE *f, struct config *conf, const char *path,619+ bool errors_are_fatal)620+{621+ enum section section = SECTION_MAIN;622+623+ char *_line = NULL;624+ size_t count = 0;625+ bool ret = true;626+627+#define error_or_continue() \628+ { \629+ if (errors_are_fatal) { \630+ ret = false; \631+ goto done; \632+ } else \633+ continue; \634+ }635+636+ char *section_name = strdup("main");637+638+ struct context context = {639+ .conf = conf,640+ .section = section_name,641+ .path = path,642+ .lineno = 0,643+ .errors_are_fatal = errors_are_fatal,644+ };645+ struct context *ctx = &context; /* For LOG_AND_*() */646+647+ errno = 0;648+ ssize_t len;649+650+ while ((len = getline(&_line, &count, f)) != -1) {651+ context.key = NULL;652+ context.value = NULL;653+ context.lineno++;654+655+ char *line = _line;656+657+ /* Strip leading whitespace */658+ while (isspace(line[0])) {659+ line++;660+ len--;661+ }662+663+ /* Empty line, or comment */664+ if (line[0] == '\0' || line[0] == '#')665+ continue;666+667+ /* Strip the trailing newline - may be absent on the last line */668+ if (line[len - 1] == '\n')669+ line[--len] = '\0';670+671+ /* Split up into key/value pair + trailing comment separated by blank */672+ char *key_value = line;673+ char *kv_trailing = &line[len - 1];674+ char *comment = &line[1];675+ while (comment[1] != '\0') {676+ if (isblank(comment[0]) && comment[1] == '#') {677+ comment[1] = '\0'; /* Terminate key/value pair */678+ kv_trailing = comment++;679+ break;680+ }681+ comment++;682+ }683+ comment++;684+685+ /* Strip trailing whitespace */686+ while (isspace(kv_trailing[0]))687+ kv_trailing--;688+ kv_trailing[1] = '\0';689+690+ /* Check for new section */691+ if (key_value[0] == '[') {692+ key_value++;693+694+ if (key_value[0] == ']') {695+ LOG_CONTEXTUAL_ERR("empty section name");696+ section = SECTION_COUNT;697+ error_or_continue();698+ }699+700+ char *end = strchr(key_value, ']');701+702+ if (end == NULL) {703+ context.section = key_value;704+ LOG_CONTEXTUAL_ERR("syntax error: no closing ']'");705+ context.section = section_name;706+ section = SECTION_COUNT;707+ error_or_continue();708+ }709+710+ end[0] = '\0';711+712+ if (end[1] != '\0') {713+ context.section = key_value;714+ LOG_CONTEXTUAL_ERR("section declaration contains trailing "715+ "characters");716+ context.section = section_name;717+ section = SECTION_COUNT;718+ error_or_continue();719+ }720+721+ section = str_to_section(key_value);722+ if (section == SECTION_COUNT) {723+ context.section = key_value;724+ LOG_CONTEXTUAL_ERR("invalid section name: %s", key_value);725+ context.section = section_name;726+ error_or_continue();727+ }728+729+ free(section_name);730+ section_name = strdup(key_value);731+ context.section = section_name;732+733+ /* Process next line */734+ continue;735+ }736+737+ if (section >= SECTION_COUNT) {738+ /* Last section name was invalid; ignore all keys in it */739+ continue;740+ }741+742+ if (!parse_key_value(key_value, NULL, &context.key, &context.value)) {743+ LOG_CONTEXTUAL_ERR("syntax error: key/value pair has no %s",744+ context.key == NULL ? "key" : "value");745+ error_or_continue();746+ }747+748+ LOG_DBG("section=%s, key='%s', value='%s', comment='%s'",749+ section_info[section].name, context.key, context.value, comment);750+751+ assert(section >= 0 && section < SECTION_COUNT);752+753+ parser_fun_t section_parser = section_info[section].fun;754+ assert(section_parser != NULL);755+756+ if (!section_parser(ctx))757+ error_or_continue();758+ }759+760+ if (errno != 0) {761+ LOG_ERRNO("failed to read from configuration");762+ if (errors_are_fatal)763+ ret = false;764+ }765+766+done:767+ free(section_name);768+ free(_line);769+ return ret;770+}771+772+static bool773+overrides_apply(struct config *conf, const config_override_t *overrides,774+ bool errors_are_fatal)775+{776+ if (overrides == NULL)777+ return true;778+779+ struct context context = {780+ .conf = conf,781+ .path = "override",782+ .lineno = 0,783+ .errors_are_fatal = errors_are_fatal,784+ };785+ struct context *ctx = &context;786+787+ tll_foreach(*overrides, it) {788+ context.lineno++;789+790+ if (!parse_key_value(791+ it->item, &context.section, &context.key, &context.value))792+ {793+ LOG_CONTEXTUAL_ERR("syntax error: key/value pair has no %s",794+ context.key == NULL ? "key" : "value");795+ if (errors_are_fatal)796+ return false;797+ continue;798+ }799+800+ if (context.section[0] == '\0') {801+ LOG_CONTEXTUAL_ERR("empty section name");802+ if (errors_are_fatal)803+ return false;804+ continue;805+ }806+807+ enum section section = str_to_section(context.section);808+ if (section == SECTION_COUNT) {809+ LOG_CONTEXTUAL_ERR("invalid section name: %s", context.section);810+ if (errors_are_fatal)811+ return false;812+ continue;813+ }814+ parser_fun_t section_parser = section_info[section].fun;815+ assert(section_parser != NULL);816+817+ if (!section_parser(ctx)) {818+ if (errors_are_fatal)819+ return false;820+ continue;821+ }822+ }823+824+#if 0825+ return826+ resolve_key_binding_collisions(827+ conf, section_info[SECTION_KEY_BINDINGS].name,828+ binding_action_map, &conf->bindings.key, KEY_BINDING) &&829+ resolve_key_binding_collisions(830+ conf, section_info[SECTION_SEARCH_BINDINGS].name,831+ search_binding_action_map, &conf->bindings.search, KEY_BINDING) &&832+ resolve_key_binding_collisions(833+ conf, section_info[SECTION_URL_BINDINGS].name,834+ url_binding_action_map, &conf->bindings.url, KEY_BINDING) &&835+ resolve_key_binding_collisions(836+ conf, section_info[SECTION_MOUSE_BINDINGS].name,837+ binding_action_map, &conf->bindings.mouse, MOUSE_BINDING);838+#endif839+ return true;840+}841+842+bool843+config_load(struct config *conf, const char *conf_path,844+ const config_override_t *overrides, bool errors_are_fatal)845+{846+ bool ret = !errors_are_fatal;847+ *conf = (struct config) {848+ .output = NULL,849+ .prompt = c32dup(U"> "),850+ .password = U'\0',851+ .match_fields = MATCH_FILENAME | MATCH_NAME | MATCH_GENERIC,852+ .terminal = NULL,853+ .launch_prefix = NULL,854+ .font = strdup("monospace"),855+ .dpi_aware = DPI_AWARE_AUTO,856+ .icons_enabled = true,857+ .icon_theme = strdup("hicolor"),858+ .actions_enabled = false,859+ .fuzzy = {860+ .min_length = 3,861+ .max_length_discrepancy = 2,862+ .max_distance = 1,863+ .enabled = true,864+ },865+ .dmenu = {866+ .enabled = false,867+ .mode = DMENU_MODE_TEXT,868+ .exit_immediately_if_empty = false,869+ },870+ .lines = 15,871+ .chars = 30,872+ .pad = {873+ .x = 40,874+ .y = 8,875+ .inner = 0,876+ },877+ .colors = {878+ .background = conf_hex_to_rgba(0xfdf6e3dd),879+ .border = conf_hex_to_rgba(0x002b36ff),880+ .text = conf_hex_to_rgba(0x657b83ff),881+ .match = conf_hex_to_rgba(0xcb4b16ff),882+ .selection = conf_hex_to_rgba(0xeee8d5dd),883+ .selection_text = conf_hex_to_rgba(0x657b83ff),884+ },885+ .border = {886+ .size = 1u,887+ .radius = 10u,888+ },889+ .line_height = {-1, 0.0},890+ .letter_spacing = {0},891+ };892+893+ struct config_file conf_file = {.path = NULL, .fd = -1};894+ if (conf_path != NULL) {895+ int fd = open(conf_path, O_RDONLY);896+ if (fd < 0) {897+ LOG_ERRNO("%s: failed to open", conf_path);898+ goto out;899+ }900+901+ conf_file.path = strdup(conf_path);902+ conf_file.fd = fd;903+ } else {904+ conf_file = open_config();905+ if (conf_file.fd < 0) {906+ LOG_WARN("no configuration found, using defaults");907+ goto out;908+ }909+ }910+911+ LOG_INFO("loading configuration from %s", conf_file.path);912+913+ FILE *f = fdopen(conf_file.fd, "r");914+ if (f == NULL) {915+ LOG_ERRNO("%s: failed to open", conf_file.path);916+ goto out;917+ }918+919+ if (!parse_config_file(f, conf, conf_file.path, errors_are_fatal) ||920+ !overrides_apply(conf, overrides, errors_are_fatal))921+ {922+ ret = !errors_are_fatal;923+ } else924+ ret = true;925+926+ fclose(f);927+928+out:929+930+ free(conf_file.path);931+ if (conf_file.fd >= 0)932+ close(conf_file.fd);933+934+ return ret;935+}936+937+void938+config_free(struct config *conf)939+{940+ free(conf->output);941+ free(conf->prompt);942+ free(conf->terminal);943+ free(conf->launch_prefix);944+ free(conf->font);945+ free(conf->icon_theme);946+}947+948+struct rgba949+conf_hex_to_rgba(uint32_t color)950+{951+ return (struct rgba){952+ .r = (double)((color >> 24) & 0xff) / 255.0,953+ .g = (double)((color >> 16) & 0xff) / 255.0,954+ .b = (double)((color >> 8) & 0xff) / 255.0,955+ .a = (double)((color >> 0) & 0xff) / 255.0,956+ };957+}added:config.h+97 added
1+#pragma once2+3+#include <stdint.h>4+#include <stdbool.h>5+#include <char32.h>6+7+#include <tllist.h>8+9+struct rgba {double r; double g; double b; double a;};10+struct pt_or_px {int px; float pt;};11+12+enum dpi_aware {13+ DPI_AWARE_AUTO,14+ DPI_AWARE_YES,15+ DPI_AWARE_NO,16+};17+18+enum dmenu_mode {19+ DMENU_MODE_TEXT,20+ DMENU_MODE_INDEX,21+};22+23+enum match_fields {24+ MATCH_FILENAME = 0x01,25+ MATCH_NAME = 0x02,26+ MATCH_GENERIC = 0x04,27+ MATCH_EXEC = 0x08,28+ MATCH_CATEGORIES = 0x10,29+ MATCH_KEYWORDS = 0x20,30+ MATCH_COMMENT = 0x40,31+};32+33+struct config {34+ char *output;35+ char32_t *prompt;36+ char32_t password;37+ enum match_fields match_fields;38+39+ char *terminal;40+ char *launch_prefix;41+42+ char *font;43+ enum dpi_aware dpi_aware;44+45+ bool icons_enabled;46+ char *icon_theme;47+48+ bool actions_enabled;49+50+ struct {51+ size_t min_length;52+ size_t max_length_discrepancy;53+ size_t max_distance;54+ bool enabled;55+ } fuzzy;56+57+ struct {58+ bool enabled;59+ enum dmenu_mode mode;60+ bool exit_immediately_if_empty;61+ } dmenu;62+63+ unsigned lines;64+ unsigned chars;65+66+ struct {67+ unsigned x;68+ unsigned y;69+ unsigned inner;70+ } pad;71+72+ struct {73+ struct rgba background;74+ struct rgba border;75+ struct rgba text;76+ struct rgba match;77+ struct rgba selection;78+ struct rgba selection_text;79+ } colors;80+81+ struct {82+ unsigned size;83+ unsigned radius;84+ } border;85+86+ struct pt_or_px line_height;87+ struct pt_or_px letter_spacing;88+};89+90+typedef tll(char *) config_override_t;91+92+bool config_load(93+ struct config *conf, const char *path, const config_override_t *overrides,94+ bool errors_are_fatal);95+void config_free(struct config *conf);96+97+struct rgba conf_hex_to_rgba(uint32_t color);modified:dmenu.c-4 removed
98 unmodified lines99 dmenu_execute(const struct application *app, ssize_t index,100 const struct prompt *prompt, enum dmenu_mode format)101 {102 switch (format) {103- case DMENU_MODE_NONE:104- assert(false);105- return false;106-103 case DMENU_MODE_TEXT: {104 char *text = ac32tombs(app != NULL ? app->title : prompt_text(prompt));105 if (text != NULL)106 printf("%s\n", text);11 unmodified linesmodified:dmenu.h+1 added-2 removed
1 unmodified line2 3 #include <sys/types.h>4 5 #include "application.h"6+#include "config.h"7 #include "prompt.h"8 8-enum dmenu_mode { DMENU_MODE_NONE, DMENU_MODE_TEXT, DMENU_MODE_INDEX };9-9 void dmenu_load_entries(struct application_list *applications, int abort_fd);10 bool dmenu_execute(const struct application *app, ssize_t index,11 const struct prompt *prompt, enum dmenu_mode format);added:fuzzel.ini+37 added
1+# output=<not set>2+# font=monospace3+# dpi-aware=auto4+# prompt=> 5+# icon-theme=hicolor6+# icons-enabled=yes7+# fields=filename,name,generic8+# password-character=*9+# fuzzy=yes10+# show-actions=no11+# terminal=<not set>12+# launch-prefix=<not set>13+14+# lines=1515+# width=3016+# horizontal-pad=4017+# vertical-pad=818+# inner-pad=019+20+# line-height=<use font metrics>21+# letter-spacing=022+23+[colors]24+# background=fdf6e3dd25+# text=657b83ff26+# match=cb4b16ff27+# selection=eee8d5dd28+# selection-text=657b83ff29+# border=002b36ff30+31+[border]32+# width=133+# radius=1034+35+[dmenu]36+# mode=text # text|index37+# exit-immediately-if-empty=nomodified:main.c+243 added-132 removed
23 unmodified lines24 #define LOG_MODULE "fuzzel"25 #define LOG_ENABLE_DBG 026 #include "log.h"27 #include "application.h"28+#include "config.h"29 #include "char32.h"30 #include "dmenu.h"31 #include "fdm.h"32 #include "match.h"3 unmodified lines36 #include "wayland.h"37 #include "xdg.h"38 39 struct context {40+ const struct config *conf;41 struct wayland *wayl;42 struct render *render;43 struct matches *matches;44 struct prompt *prompt;2 unmodified lines47 icon_theme_list_t *themes;48 int icon_size;49 mtx_t *icon_lock;50 51+#if 052+ /* TODO: can we use a struct config ptr instead? */53 struct {54 const char *icon_theme;55 const char *terminal;56 bool icons_enabled;57 bool actions_enabled;58 bool dmenu_mode;59 } options;56-60+#endif61 int event_fd;62 int dmenu_abort_fd;63 };64 61-static struct rgba62-hex_to_rgba(uint32_t color)63-{64- return (struct rgba){65- .r = (double)((color >> 24) & 0xff) / 255.0,66- .g = (double)((color >> 16) & 0xff) / 255.0,67- .b = (double)((color >> 8) & 0xff) / 255.0,68- .a = (double)((color >> 0) & 0xff) / 255.0,69- };70-}71-65 static void66 read_cache(struct application_list *apps)67 {68 const char *path = xdg_cache_dir();126 unmodified lines195 {196 printf("Usage: %s [OPTION]...\n", prog_name);197 printf("\n");198 printf("Options:\n");199+ printf(" --config=PATH load configuration from PATH (XDG_CONFIG_HOME/fuzzel/fuzzel.ini)\n"206- printf(" -o,--output=OUTPUT output (monitor) to display on (none)\n"200+ " -o,--output=OUTPUT output (monitor) to display on (none)\n"201 " -f,--font=FONT font name and style, in FontConfig format\n"202 " (monospace)\n"203+ " -D,--dpi-aware=no|yes|auto enable or disable DPI aware rendering (auto)\n"204 " -i,--icon-theme=NAME icon theme name (\"hicolor\")\n"205 " -I,--no-icons do not render any icons\n"206 " -F,--fields=FIELDS comma separated list of XDG Desktop entry\n"207 " fields to match\n"208+ " -P,--prompt=PROMPT string to use as input prompt (\"> \")\n"209 " --password=[CHARACTER] render all input as CHARACTER ('*' by default)\n"210 " -T,--terminal terminal command to use when launching\n"211 " 'terminal' programs, e.g. \"xterm -e\".\n"212 " Not used in dmenu mode (not set)\n"51 unmodified lines264 265 mtx_lock(ctx->icon_lock);266 {267 ctx->icon_size = font->height;272- if (ctx->options.icons_enabled) {268+ if (ctx->conf->icons_enabled) {269 icon_lookup_application_icons(270 *ctx->themes, ctx->icon_size, ctx->apps);271 }272 }95 unmodified lines368 populate_apps(void *_ctx)369 {370 struct context *ctx = _ctx;371 struct application_list *apps = ctx->apps;376- const char *icon_theme = ctx->options.icon_theme;377- const char *terminal = ctx->options.terminal;378- bool actions_enabled = ctx->options.actions_enabled;379- bool dmenu_mode = ctx->options.dmenu_mode;380- bool icons_enabled = ctx->options.icons_enabled;372+ const char *icon_theme = ctx->conf->icon_theme;373+ const char *terminal = ctx->conf->terminal;374+ bool actions_enabled = ctx->conf->actions_enabled;375+ bool dmenu_enabled = ctx->conf->dmenu.enabled;376+ bool icons_enabled = ctx->conf->icons_enabled;377 382- if (dmenu_mode) {378+ if (dmenu_enabled) {379 dmenu_load_entries(apps, ctx->dmenu_abort_fd);380 return send_event(ctx->event_fd, EVENT_APPS_LOADED);381 }382 88 unmodified lines471 #define OPT_LOG_LEVEL 264472 #define OPT_LOG_COLORIZE 265473 #define OPT_LOG_NO_SYSLOG 266474 #define OPT_PASSWORD 267475+ #define OPT_CONFIG 268476 477 static const struct option longopts[] = {478+ {"config", required_argument, 0, OPT_CONFIG},479 {"output" , required_argument, 0, 'o'},480 {"font", required_argument, 0, 'f'},481 {"dpi-aware", required_argument, 0, 'D'},482 {"icon-theme", required_argument, 0, 'i'},37 unmodified lines520 {"help", no_argument, 0, 'h'},521 {NULL, no_argument, 0, 0},522 };523 526- enum dpi_aware dpi_aware = DPI_AWARE_AUTO;527- const char *output_name = NULL;524+ const char *config_path = NULL;528- const char *font_name = "monospace";529- const char *icon_theme = "hicolor";530- const char *terminal = NULL;531- const char32_t *prompt_content = U"> ";532- char32_t *prompt_allocated = NULL;533- bool icons_enabled = true;534- bool actions_enabled = false;535- bool fuzzy = true;536- size_t fuzzy_min_length = 3;537- size_t fuzzy_max_length_discrepancy = 2;538- size_t fuzzy_max_distance = 1;539- const char *launch_prefix = NULL;540-525 enum log_class log_level = LOG_CLASS_INFO;526 enum log_colorize log_colorize = LOG_COLORIZE_AUTO;527 bool log_syslog = true;528 545- bool dmenu_mode = false;546- enum dmenu_mode dmenu_format = DMENU_MODE_TEXT;547- bool no_run_if_empty = false;529+ struct {530+ struct config conf;531 549- enum match_fields match_fields =550- MATCH_FILENAME | MATCH_NAME | MATCH_GENERIC;532+ bool dpi_aware_set:1;533+ bool match_fields_set:1;534+ bool icons_disabled_set:1;535+ bool lines_set:1;536+ bool chars_set:1;537+ bool pad_x_set:1;538+ bool pad_y_set:1;539+ bool pad_inner_set:1;540+ bool background_color_set:1;541+ bool text_color_set:1;542+ bool match_color_set:1;543+ bool selection_color_set:1;544+ bool selection_text_color_set:1;545+ bool border_color_set:1;546+ bool border_size_set:1;547+ bool border_radius_set:1;548+ bool actions_enabled_set:1;549+ bool fuzzy_set:1;550+ bool fuzzy_min_length_set:1;551+ bool fuzzy_max_length_discrepancy_set:1;552+ bool fuzzy_max_distance_set:1;553+ bool line_height_set:1;554+ bool letter_spacing_set:1;555+ bool dmenu_enabled_set:1;556+ bool dmenu_mode_set:1;557+ bool dmenu_exit_immediately_if_empty_set:1;558+ } cmdline_overrides = {{0}};559 552- struct render_options render_options = {553- .lines = 15,554- .chars = 30,555- .border_size = 1u,556- .border_radius = 10u,557- .pad = {.x = 40, .y = 8, .inner = 0},558- .password = false,559- .background_color = hex_to_rgba(0xfdf6e3dd),560- .border_color = hex_to_rgba(0x002b36ff),561- .text_color = hex_to_rgba(0x657b83ff),562- .match_color = hex_to_rgba(0xcb4b16ff),563- .selection_color = hex_to_rgba(0xeee8d5dd),564- .selection_text_color = hex_to_rgba(0x657b83ff),565- .line_height = {-1, 0.0}, /* Use font metrics */566- .letter_spacing = {0},567- };568-560 setlocale(LC_CTYPE, "");561 562 /* Auto-enable dmenu mode if invoked through a ‘dmenu’ symlink */563 if (argv[0] != NULL) {564 char *copy = strdup(argv[0]);565 if (copy != NULL) {566 const char *name = basename(copy);576- if (name != NULL && strcmp(name, "dmenu") == 0)577- dmenu_mode = true;567+ if (name != NULL && strcmp(name, "dmenu") == 0) {568+ cmdline_overrides.conf.dmenu.enabled = true;569+ cmdline_overrides.dmenu_enabled_set = true;570+ }571 572 free(copy);573 }574 }3 unmodified lines578 if (c == -1)579 break;580 581 switch (c) {582+ case OPT_CONFIG:583+ config_path = optarg;584+ break;585+586 case 'o':590- output_name = optarg;587+ cmdline_overrides.conf.output = optarg;588 break;589 590 case 'f':594- font_name = optarg;591+ cmdline_overrides.conf.font = optarg;592 break;593 594 case 'D':595 if (strcmp(optarg, "auto") == 0)599- dpi_aware = DPI_AWARE_AUTO;596+ cmdline_overrides.conf.dpi_aware = DPI_AWARE_AUTO;597 else if (strcmp(optarg, "no") == 0)601- dpi_aware = DPI_AWARE_NO;598+ cmdline_overrides.conf.dpi_aware = DPI_AWARE_NO;599 else if (strcmp(optarg, "yes") == 0)603- dpi_aware = DPI_AWARE_YES;600+ cmdline_overrides.conf.dpi_aware = DPI_AWARE_YES;601 else {602 fprintf(603 stderr,604 "%s: invalid value for dpi-aware: "605 "must be one of 'auto', 'no', or 'yes'\n",606 optarg);607 return EXIT_FAILURE;608 }609+ cmdline_overrides.dpi_aware_set = true;610 break;611 612 case 'i':615- icon_theme = optarg;613+ cmdline_overrides.conf.icon_theme = optarg;614 break;615 616 case 'I':619- icons_enabled = false;617+ cmdline_overrides.conf.icons_enabled = false;618+ cmdline_overrides.icons_disabled_set = true;619 break;620 621 case 'F': {622 static const struct {8 unmodified lines631 {"keywords", MATCH_KEYWORDS},632 {"comment", MATCH_COMMENT},633 };634 636- match_fields = 0;635+ cmdline_overrides.conf.match_fields = 0;636 for (const char *f = strtok(optarg, ", ");637 f != NULL;638 f = strtok(NULL, ", "))639 {6 unmodified lines646 }647 }648 649 if (field > 0)651- match_fields |= field;650+ cmdline_overrides.conf.match_fields |= field;651 else {652 char valid_names[128] = {0};653 int idx = 0;654 for (size_t i = 0; i < sizeof(map) / sizeof(map[0]); i++) {10 unmodified lines665 f, valid_names);666 return EXIT_FAILURE;667 }668 }669+ cmdline_overrides.match_fields_set = true;670 break;671 }672 673 case OPT_PASSWORD: {10 unmodified lines684 }685 password_char = wide_optarg[0];686 free(wide_optarg);687 }688- render_options.password = password_char;688+ cmdline_overrides.conf.password = password_char;689 break;690 }691 692 case 'T':693- terminal = optarg;693+ cmdline_overrides.conf.terminal = optarg;694 break;695 696 case 'l':697- if (sscanf(optarg, "%u", &render_options.lines) != 1) {697+ if (sscanf(optarg, "%u", &cmdline_overrides.conf.lines) != 1) {698 fprintf(stderr, "%s: invalid line count\n", optarg);699 return EXIT_FAILURE;700 }701+ cmdline_overrides.lines_set = true;702 break;703 704 case 'w':704- if (sscanf(optarg, "%u", &render_options.chars) != 1) {705+ if (sscanf(optarg, "%u", &cmdline_overrides.conf.chars) != 1) {706 fprintf(stderr, "%s: invalid width\n", optarg);707 return EXIT_FAILURE;708 }709+ cmdline_overrides.chars_set = true;710 break;711 712 case 'x':711- if (sscanf(optarg, "%u", &render_options.pad.x) != 1) {713+ if (sscanf(optarg, "%u", &cmdline_overrides.conf.pad.x) != 1) {714 fprintf(stderr, "%s: invalid padding\n", optarg);715 return EXIT_FAILURE;716 }717+ cmdline_overrides.pad_x_set = true;718 break;719 720 case 'y':718- if (sscanf(optarg, "%u", &render_options.pad.y) != 1) {721+ if (sscanf(optarg, "%u", &cmdline_overrides.conf.pad.y) != 1) {722 fprintf(stderr, "%s: invalid padding\n", optarg);723 return EXIT_FAILURE;724 }725+ cmdline_overrides.pad_y_set = true;726 break;727 728 case 'p':725- if (sscanf(optarg, "%u", &render_options.pad.inner) != 1) {729+ if (sscanf(optarg, "%u", &cmdline_overrides.conf.pad.inner) != 1) {730 fprintf(stderr, "%s: invalid padding\n", optarg);731 return EXIT_FAILURE;732 }733+ cmdline_overrides.pad_inner_set = true;734 break;735 736 case 'P':732- free(prompt_allocated);733- prompt_allocated = ambstoc32(optarg);737+ free(cmdline_overrides.conf.prompt);738+ cmdline_overrides.conf.prompt = ambstoc32(optarg);739 735- if (prompt_allocated == NULL) {740+ if (cmdline_overrides.conf.prompt == NULL) {741 fprintf(stderr, "%s: invalid prompt\n", optarg);742 return EXIT_FAILURE;743 }744 740- prompt_content = prompt_allocated;745 break;746 747 case 'b': {748 uint32_t background;749 if (sscanf(optarg, "%08x", &background) != 1) {750 fprintf(stderr, "%s: invalid color\n", optarg);751 return EXIT_FAILURE;752 }749- render_options.background_color = hex_to_rgba(background);753+ cmdline_overrides.conf.colors.background =754+ conf_hex_to_rgba(background);755+ cmdline_overrides.background_color_set = true;756 break;757 }758 759 case 't': {1 unmodified line761 if (sscanf(optarg, "%08x", &text_color) != 1) {762 fprintf(stderr, "%s: invalid color\n", optarg);763 return EXIT_FAILURE;764 }759- render_options.text_color = hex_to_rgba(text_color);765+ cmdline_overrides.conf.colors.text = conf_hex_to_rgba(text_color);766+ cmdline_overrides.text_color_set = true;767 break;768 }769 770 case 'm': {1 unmodified line772 if (sscanf(optarg, "%x", &match_color) != 1) {773 fprintf(stderr, "%s: invalid color\n", optarg);774 return EXIT_FAILURE;775 }769- render_options.match_color = hex_to_rgba(match_color);776+ cmdline_overrides.conf.colors.match =777+ conf_hex_to_rgba(match_color);778+ cmdline_overrides.match_color_set = true;779 break;780 }781 782 case 's': {1 unmodified line784 if (sscanf(optarg, "%x", &selection_color) != 1) {785 fprintf(stderr, "%s: invalid color\n", optarg);786 return EXIT_FAILURE;787 }779- render_options.selection_color = hex_to_rgba(selection_color);788+ cmdline_overrides.conf.colors.selection =789+ conf_hex_to_rgba(selection_color);790+ cmdline_overrides.selection_color_set = true;791 break;792 }793 794 case 'S': {1 unmodified line796 if (sscanf(optarg, "%x", &selection_text_color) != 1) {797 fprintf(stderr, "%s: invalid color\n", optarg);798 return EXIT_FAILURE;799 }789- render_options.selection_text_color = hex_to_rgba(selection_text_color);800+ cmdline_overrides.conf.colors.selection_text =801+ conf_hex_to_rgba(selection_text_color);802+ cmdline_overrides.selection_text_color_set = true;803 break;804 }805 806 case 'B':794- if (sscanf(optarg, "%u", &render_options.border_size) != 1) {807+ if (sscanf(optarg, "%u", &cmdline_overrides.conf.border.size) != 1) {808 fprintf(809 stderr,810 "%s: invalid border width (must be an integer)\n", optarg);811 return EXIT_FAILURE;812 }813+ cmdline_overrides.border_size_set = true;814 break;815 816 case 'r':803- if (sscanf(optarg, "%u", &render_options.border_radius) != 1) {817+ if (sscanf(optarg, "%u", &cmdline_overrides.conf.border.radius) != 1) {818 fprintf(stderr, "%s: invalid border radius (must be an integer)\n",819 optarg);820 return EXIT_FAILURE;821 }822+ cmdline_overrides.border_radius_set = true;823 break;824 825 case 'C': {826 uint32_t border_color;827 if (sscanf(optarg, "%x", &border_color) != 1) {828 fprintf(stderr, "%s: invalid color\n", optarg);829 return EXIT_FAILURE;830 }816- render_options.border_color = hex_to_rgba(border_color);831+ cmdline_overrides.conf.colors.border =832+ conf_hex_to_rgba(border_color);833+ cmdline_overrides.border_color_set = true;834 break;835 }836 837 case OPT_SHOW_ACTIONS:821- actions_enabled = true;838+ cmdline_overrides.conf.actions_enabled = true;839 break;840 841 case OPT_NO_FUZZY:825- fuzzy = false;842+ cmdline_overrides.conf.fuzzy.enabled = false;843+ cmdline_overrides.fuzzy_set = true;844 break;845 846 case OPT_FUZZY_MIN_LENGTH:829- if (sscanf(optarg, "%zu", &fuzzy_min_length) != 1) {847+ if (sscanf(optarg, "%zu", &cmdline_overrides.conf.fuzzy.min_length) != 1) {848 fprintf(849 stderr,850 "%s: invalid fuzzy min length (must be an integer)\n",851 optarg);852 return EXIT_FAILURE;853 }854+ cmdline_overrides.fuzzy_min_length_set = true;855 break;856 857 case OPT_FUZZY_MAX_LENGTH_DISCREPANCY:839- if (sscanf(optarg, "%zu", &fuzzy_max_length_discrepancy) != 1) {858+ if (sscanf(optarg, "%zu", &cmdline_overrides.conf.fuzzy.max_length_discrepancy) != 1) {859 fprintf(860 stderr,861 "%s: invalid fuzzy max length discrepancy "862 "(must be an integer)\n", optarg);863 return EXIT_FAILURE;864 }865+ cmdline_overrides.fuzzy_max_length_discrepancy_set = true;866 break;867 868 case OPT_FUZZY_MAX_DISTANCE:849- if (sscanf(optarg, "%zu", &fuzzy_max_distance) != 1) {869+ if (sscanf(optarg, "%zu", &cmdline_overrides.conf.fuzzy.max_distance) != 1) {870 fprintf(871 stderr,872 "%s: invalid fuzzy max distance (must be an integer)\n",873 optarg);874 return EXIT_FAILURE;875 }876+ cmdline_overrides.fuzzy_max_distance_set = true;877 break;878 879 case 'H': { /* line-height */859- if (!pt_or_px_from_string(optarg, &render_options.line_height))880+ if (!pt_or_px_from_string(optarg, &cmdline_overrides.conf.line_height))881 return EXIT_FAILURE;882+ cmdline_overrides.line_height_set = true;883 break;884 }885 886 case OPT_LETTER_SPACING: {865- if (!pt_or_px_from_string(optarg, &render_options.letter_spacing))887+ if (!pt_or_px_from_string(optarg, &cmdline_overrides.conf.letter_spacing))888 return EXIT_FAILURE;889+ cmdline_overrides.letter_spacing_set = true;890 break;891 }892 893 case OPT_LAUNCH_PREFIX: {871- launch_prefix = optarg;894+ cmdline_overrides.conf.launch_prefix = optarg;895 break;896 }897 898 case 'd':876- dmenu_mode = true;899+ cmdline_overrides.conf.dmenu.enabled = true;900+ cmdline_overrides.dmenu_enabled_set = true;901 break;902 903 case 'R':880- no_run_if_empty = true;904+ cmdline_overrides.conf.dmenu.exit_immediately_if_empty = true;905+ cmdline_overrides.dmenu_exit_immediately_if_empty_set = true;906 break;907 908 case OPT_DMENU_INDEX:884- dmenu_format = DMENU_MODE_INDEX;909+ cmdline_overrides.conf.dmenu.mode = DMENU_MODE_INDEX;910+ cmdline_overrides.dmenu_mode_set = true;911 break;912 913 case OPT_LOG_LEVEL: {914 int lvl = log_level_from_string(optarg);42 unmodified lines957 return EXIT_FAILURE;958 }959 }960 961+ log_init(log_colorize, log_syslog, LOG_FACILITY_USER, log_level);962+963 int ret = EXIT_FAILURE;964 965+ struct config conf = {0};966+ bool conf_successful = config_load(&conf, config_path, NULL, true);967+ if (!conf_successful) {968+ config_free(&conf);969+ return ret;970+ }971+972+ /* Apply command line overrides */973+ if (cmdline_overrides.conf.output != NULL) {974+ free(conf.output);975+ conf.output = strdup(cmdline_overrides.conf.output);976+ }977+ if (cmdline_overrides.conf.prompt != NULL) {978+ free(conf.prompt);979+ conf.prompt = cmdline_overrides.conf.prompt;980+ }981+ if (cmdline_overrides.conf.password != U'\0')982+ conf.password = cmdline_overrides.conf.password;983+ if (cmdline_overrides.conf.terminal != NULL) {984+ free(conf.terminal);985+ conf.terminal = strdup(cmdline_overrides.conf.terminal);986+ }987+ if (cmdline_overrides.conf.launch_prefix != NULL) {988+ free(conf.launch_prefix);989+ conf.launch_prefix = strdup(cmdline_overrides.conf.launch_prefix);990+ }991+ if (cmdline_overrides.conf.font != NULL) {992+ free(conf.font);993+ conf.font = strdup(cmdline_overrides.conf.font);994+ }995+ if (cmdline_overrides.conf.icon_theme != NULL) {996+ free(conf.icon_theme);997+ conf.icon_theme = strdup(cmdline_overrides.conf.icon_theme);998+ }999+ if (cmdline_overrides.dpi_aware_set)1000+ conf.dpi_aware = cmdline_overrides.conf.dpi_aware;1001+ if (cmdline_overrides.match_fields_set)1002+ conf.match_fields = cmdline_overrides.conf.match_fields;1003+ if (cmdline_overrides.icons_disabled_set)1004+ conf.icons_enabled = cmdline_overrides.conf.icons_enabled;1005+ if (cmdline_overrides.lines_set)1006+ conf.lines = cmdline_overrides.conf.lines;1007+ if (cmdline_overrides.chars_set)1008+ conf.chars = cmdline_overrides.conf.chars;1009+ if (cmdline_overrides.pad_x_set)1010+ conf.pad.x = cmdline_overrides.conf.pad.x;1011+ if (cmdline_overrides.pad_y_set)1012+ conf.pad.y = cmdline_overrides.conf.pad.y;1013+ if (cmdline_overrides.pad_inner_set)1014+ conf.pad.inner = cmdline_overrides.conf.pad.inner;1015+ if (cmdline_overrides.background_color_set)1016+ conf.colors.background = cmdline_overrides.conf.colors.background;1017+ if (cmdline_overrides.text_color_set)1018+ conf.colors.text = cmdline_overrides.conf.colors.text;1019+ if (cmdline_overrides.match_color_set)1020+ conf.colors.match = cmdline_overrides.conf.colors.match;1021+ if (cmdline_overrides.selection_color_set)1022+ conf.colors.selection = cmdline_overrides.conf.colors.selection;1023+ if (cmdline_overrides.selection_text_color_set)1024+ conf.colors.selection_text = cmdline_overrides.conf.colors.selection_text;1025+ if (cmdline_overrides.border_color_set)1026+ conf.colors.border = cmdline_overrides.conf.colors.border;1027+ if (cmdline_overrides.border_size_set)1028+ conf.border.size = cmdline_overrides.conf.border.size;1029+ if (cmdline_overrides.border_radius_set)1030+ conf.border.radius = cmdline_overrides.conf.border.radius;1031+ if (cmdline_overrides.actions_enabled_set)1032+ conf.actions_enabled = cmdline_overrides.conf.actions_enabled;1033+ if (cmdline_overrides.fuzzy_set)1034+ conf.fuzzy.enabled = cmdline_overrides.conf.fuzzy.enabled;1035+ if (cmdline_overrides.fuzzy_min_length_set)1036+ conf.fuzzy.min_length = cmdline_overrides.conf.fuzzy.min_length;1037+ if (cmdline_overrides.fuzzy_max_length_discrepancy_set)1038+ conf.fuzzy.max_length_discrepancy = cmdline_overrides.conf.fuzzy.max_length_discrepancy;1039+ if (cmdline_overrides.fuzzy_max_distance_set)1040+ conf.fuzzy.max_distance = cmdline_overrides.conf.fuzzy.max_distance;1041+ if (cmdline_overrides.line_height_set)1042+ conf.line_height = cmdline_overrides.conf.line_height;1043+ if (cmdline_overrides.letter_spacing_set)1044+ conf.letter_spacing = cmdline_overrides.conf.letter_spacing;1045+ if (cmdline_overrides.dmenu_enabled_set)1046+ conf.dmenu.enabled = cmdline_overrides.conf.dmenu.enabled;1047+ if (cmdline_overrides.dmenu_mode_set)1048+ conf.dmenu.mode = cmdline_overrides.conf.dmenu.mode;1049+ if (cmdline_overrides.dmenu_exit_immediately_if_empty_set)1050+ conf.dmenu.exit_immediately_if_empty = cmdline_overrides.conf.dmenu.exit_immediately_if_empty;1051+1052 _Static_assert((int)LOG_CLASS_ERROR == (int)FCFT_LOG_CLASS_ERROR,1053 "fcft log level enum offset");1054 _Static_assert((int)LOG_COLORIZE_ALWAYS == (int)FCFT_LOG_COLORIZE_ALWAYS,1055 "fcft colorize enum mismatch");941-942- log_init(log_colorize, log_syslog, LOG_FACILITY_USER, log_level);1056 fcft_init((enum fcft_log_colorize)log_colorize, log_syslog, (enum fcft_log_class)log_level);1057 1058 #if !defined(FUZZEL_ENABLE_SVG_LIBRSVG)1059 /* Skip fcft cleanup if we’re using the librsvg backend36 unmodified lines1096 1097 if ((fdm = fdm_init()) == NULL)1098 goto out;1099 987- if ((render = render_init(&render_options, &icon_lock)) == NULL)1100+ if ((render = render_init(&conf, &icon_lock)) == NULL)1101 goto out;1102 990- if ((prompt = prompt_init(prompt_content)) == NULL)1103+ if ((prompt = prompt_init(conf.prompt)) == NULL)1104 goto out;1105 1106 if ((matches = matches_init(994- match_fields, fuzzy, fuzzy_min_length,995- fuzzy_max_length_discrepancy, fuzzy_max_distance)) == NULL)1107+ conf.match_fields, conf.fuzzy.enabled, conf.fuzzy.min_length,1108+ conf.fuzzy.max_length_discrepancy,1109+ conf.fuzzy.max_distance)) == NULL)1110 goto out;997- matches_max_matches_per_page_set(matches, render_options.lines);1111+ matches_max_matches_per_page_set(matches, conf.lines);1112 1113 if ((apps = applications_init()) == NULL)1114 goto out;1115 1116+ if (conf.dmenu.enabled) {1002- if (dmenu_mode && no_run_if_empty) {1003- /*1004- * If no_run_if_empty is set, we *must* load the entries1005- * *before displaying the window.1006- */1007- dmenu_load_entries(apps, -1);1008- if (apps->count == 0)1009- goto out;1117+ if (conf.dmenu.exit_immediately_if_empty) {1118+ /*1119+ * If no_run_if_empty is set, we *must* load the entries1120+ * *before displaying the window.1121+ */1122+ dmenu_load_entries(apps, -1);1123+ if (apps->count == 0)1124+ goto out;1125 1011- matches_set_applications(matches, apps);1012- matches_update(matches, prompt);1013- } else if (dmenu_mode) {1014- dmenu_abort_fd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);1015- if (dmenu_abort_fd < 0) {1016- LOG_ERRNO("failed to create event FD for dmenu mode");1017- goto out;1126+ matches_set_applications(matches, apps);1127+ matches_update(matches, prompt);1128 }1129+1130+ else {1131+ dmenu_abort_fd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);1132+ if (dmenu_abort_fd < 0) {1133+ LOG_ERRNO("failed to create event FD for dmenu mode");1134+ goto out;1135+ }1136+ }1137 }1138 1139 struct context ctx = {1140+ .conf = &conf,1141 .render = render,1142 .matches = matches,1143 .prompt = prompt,1144 .apps = apps,1145 .themes = &themes,1146 .icon_lock = &icon_lock,1028- .options = {1029- .icon_theme = icon_theme,1030- .terminal = terminal,1031- .icons_enabled = icons_enabled,1032- .actions_enabled = actions_enabled,1033- .dmenu_mode = dmenu_mode,1034- },1147 .event_fd = -1,1148 .dmenu_abort_fd = dmenu_abort_fd,1149 };1150 1151 if ((wayl = wayl_init(1040- fdm, render, prompt, matches, &render_options,1041- dmenu_mode ? dmenu_format : DMENU_MODE_NONE,1042- launch_prefix, output_name, font_name, dpi_aware,1152+ &conf, fdm, render, prompt, matches,1153 &font_reloaded, &ctx)) == NULL)1154 goto out;1155 1156 ctx.wayl = wayl;1157 1158 /* Create thread that will populate the application list */1049- if (!dmenu_mode || !no_run_if_empty) {1159+ if (!conf.dmenu.enabled || !conf.dmenu.exit_immediately_if_empty) {1160 if (pipe2(event_pipe, O_CLOEXEC | O_NONBLOCK) < 0) {1161 LOG_ERRNO("failed to create event pipe");1162 goto out;1163 }63 unmodified lines1227 prompt_destroy(prompt);1228 fdm_destroy(fdm);1229 applications_destroy(apps);1230 icon_themes_destroy(themes);1121- free(prompt_allocated);1231+ //free(prompt_allocated);1232+ config_free(&conf);1233 1234 #if defined(FUZZEL_ENABLE_CAIRO) && defined(_DEBUG)1235 cairo_debug_reset_static_data();1236 #endif11 unmodified linesmodified:match.h+1 added-10 removed
2 unmodified lines3 #include <stdbool.h>4 #include <unistd.h>5 6 #include "application.h"7+#include "config.h"8 #include "prompt.h"9 10 enum matched_type {11 MATCHED_NONE,7 unmodified lines19 ssize_t start_title;20 size_t index;21 };22 22-enum match_fields {23- MATCH_FILENAME = 0x01,24- MATCH_NAME = 0x02,25- MATCH_GENERIC = 0x04,26- MATCH_EXEC = 0x08,27- MATCH_CATEGORIES = 0x10,28- MATCH_KEYWORDS = 0x20,29- MATCH_COMMENT = 0x40,30-};31-23 struct matches;24 struct matches *matches_init(enum match_fields fields, bool fuzzy,25 size_t fuzzy_min_length,26 size_t fuzzy_max_length_discrepancy,25 unmodified linesmodified:meson.build+4 added
130 unmodified lines131 132 executable(133 'fuzzel',134 'application.c', 'application.h',135+ 'config.c', 'config.h',136 'char32.c', 'char32.h',137 'dmenu.c', 'dmenu.h',138 'fdm.c', 'fdm.h',139 'icon.c', 'icon.h',24 unmodified lines164 fcft],165 install: true)166 167 install_data(168+ 'fuzzel.ini',169+ install_dir: join_paths(get_option('sysconfdir'), 'xdg', 'fuzzel'))170+install_data(171 'LICENSE', 'README.md', 'CHANGELOG.md',172 install_dir: join_paths(get_option('datadir'), 'doc', 'fuzzel'))173 174 subdir('completions')10 unmodified linesmodified:render.c+49 added-43 removed
20 unmodified lines21 #define min(x, y) ((x) < (y) ? (x) : (y))22 #define max(x, y) ((x) > (y) ? (x) : (y))23 24 struct render {25- struct render_options options;25+ const struct config *conf;26 struct fcft_font *font;27 enum fcft_subpixel subpixel;28 29 int scale;30 float dpi;31 bool size_font_by_dpi;32 33+ pixman_color_t pix_background_color;34+ pixman_color_t pix_border_color;35+ pixman_color_t pix_text_color;36+ pixman_color_t pix_match_color;37+ pixman_color_t pix_selection_color;38+ pixman_color_t pix_selection_text_color;39+40 unsigned x_margin;41 unsigned y_margin;42 unsigned inner_pad;43 unsigned border_size;34 unmodified lines78 render_background(const struct render *render, struct buffer *buf)79 {80 bool use_pixman =81 #if defined(FUZZEL_ENABLE_CAIRO)75- render->options.border_radius == 082+ render->conf->border.radius == 083 #else84 true85 #endif86 ;87 88 if (use_pixman) {82- unsigned bw = render->options.border_size;89+ unsigned bw = render->conf->border.size;90 84- pixman_color_t bg = rgba2pixman(render->options.background_color);91+ pixman_color_t bg = rgba2pixman(render->conf->colors.background);92 pixman_image_fill_rectangles(93 PIXMAN_OP_SRC, buf->pix, &bg,94 1, &(pixman_rectangle16_t){95 bw, bw, buf->width - 2 * bw, buf->height - 2 * bw});96 90- pixman_color_t border_color = rgba2pixman(render->options.border_color);97+ pixman_color_t border_color = rgba2pixman(render->conf->colors.border);98 pixman_image_fill_rectangles(99 PIXMAN_OP_SRC, buf->pix, &border_color,100 4, (pixman_rectangle16_t[]){101 {0, 0, buf->width, bw}, /* top */21 unmodified lines123 const double w = max(buf->width - 2 * b, 0.);124 const double h = max(buf->height - 2 * b, 0.);125 126 const double from_degree = M_PI / 180;120- const double radius = render->options.border_radius;127+ const double radius = render->conf->border.radius;128 129 /* Path describing an arc:ed rectangle */130 cairo_new_path(buf->cairo);131 cairo_arc(buf->cairo, b + w - radius, b + h - radius, radius,6 unmodified lines138 270.0 * from_degree, 360.0 * from_degree);139 cairo_close_path(buf->cairo);140 141 /* Border */135- const struct rgba *bc = &render->options.border_color;142+ const struct rgba *bc = &render->conf->colors.border;143 cairo_set_operator(buf->cairo, CAIRO_OPERATOR_SOURCE);144 cairo_set_line_width(buf->cairo, 2 * b);145 cairo_set_source_rgba(buf->cairo, bc->r, bc->g, bc->b, bc->a);146 cairo_stroke_preserve(buf->cairo);147 148 /* Background */142- const struct rgba *bg = &render->options.background_color;149+ const struct rgba *bg = &render->conf->colors.background;150 cairo_set_source_rgba(buf->cairo, bg->r, bg->g, bg->b, bg->a);151 cairo_fill(buf->cairo);152 #else153 assert(false);27 unmodified lines181 {182 struct fcft_font *font = render->font;183 assert(font != NULL);184 178- const struct render_options *opts = &render->options;185+ const struct config *conf = render->conf;186 187 const char32_t *pprompt = prompt_prompt(prompt);188 const size_t prompt_len = c32len(pprompt);189 190 const char32_t *ptext = prompt_text(prompt);191 const size_t text_len = c32len(ptext);192 193 const enum fcft_subpixel subpixel =187- (render->options.background_color.a == 1. &&188- render->options.selection_color.a == 1.)194+ (render->conf->colors.background.a == 1. &&195+ render->conf->colors.selection.a == 1.)196 ? render->subpixel : FCFT_SUBPIXEL_NONE;197 198 int x = render->border_size + render->x_margin;199 int y = render->border_size + render->y_margin + font->ascent;2 unmodified lines202 203 for (size_t i = 0; i < prompt_len + text_len; i++) {204 char32_t wc = i < prompt_len205 ? pprompt[i]199- : (opts->password != 0200- ? opts->password206+ : (conf->password != 0207+ ? conf->password208 : ptext[i - prompt_len]);209 210 const struct fcft_glyph *glyph = fcft_rasterize_char_utf32(211 font, wc, subpixel);6 unmodified lines218 long x_kern;219 fcft_kerning(font, prev, wc, &x_kern, NULL);220 221 x += x_kern;215- render_glyph(buf->pix, glyph, x, y, &render->options.pix_text_color);222+ render_glyph(buf->pix, glyph, x, y, &render->pix_text_color);223 x += glyph->advance.x;224 if (i >= prompt_len)218- x += pt_or_px_as_pixels(render, &render->options.letter_spacing);225+ x += pt_or_px_as_pixels(render, &render->conf->letter_spacing);226 227 /* Cursor */228 if (prompt_cursor(prompt) + prompt_len - 1 == i) {229 pixman_image_fill_rectangles(223- PIXMAN_OP_SRC, buf->pix, &render->options.pix_text_color,230+ PIXMAN_OP_SRC, buf->pix, &render->pix_text_color,231 1, &(pixman_rectangle16_t){232 x, y - font->ascent,233 font->underline.thickness, font->ascent + font->descent});234 }314 unmodified lines549 const int border_size = render->border_size;550 const size_t match_count = matches_get_count(matches);551 const size_t selected = matches_get_match_index(matches);552 const enum fcft_subpixel subpixel =546- (render->options.background_color.a == 1. &&547- render->options.selection_color.a == 1.)553+ (render->conf->colors.background.a == 1. &&554+ render->conf->colors.selection.a == 1.)555 ? render->subpixel : FCFT_SUBPIXEL_NONE;556 const struct fcft_glyph *ellipses =557 fcft_rasterize_char_utf32(font, U'…', subpixel);558 36 unmodified lines595 {596 render_svg(&match->application->icon, img_x, img_y, size, buf);597 }598 592- pixman_color_t sc = rgba2pixman(render->options.selection_color);599+ pixman_color_t sc = rgba2pixman(render->conf->colors.selection);600 pixman_image_fill_rectangles(601 PIXMAN_OP_SRC, buf->pix, &sc, 1,602 &(pixman_rectangle16_t){603 x_margin - sel_margin,6 unmodified lines610 double cur_x = border_size + x_margin;611 double max_x = buf->width - border_size - x_margin;612 613 #if 0 /* Render the icon+text bounding box */607- pixman_color_t sc = rgba2pixman(render->options.match_color);614+ pixman_color_t sc = rgba2pixman(render->conf->match_color);615 pixman_image_fill_rectangles(616 PIXMAN_OP_SRC, buf->pix, &sc, 1,617 &(pixman_rectangle16_t){618 cur_x, first_row + i * row_height,25 unmodified lines644 font, U' ', subpixel);645 646 cur_x += row_height +647 (space != NULL ? space->advance.x : font->max_advance.x) +641- pt_or_px_as_pixels(render, &render->options.letter_spacing);648+ pt_or_px_as_pixels(render, &render->conf->letter_spacing);649 650 /* Application title */651 render_match_text(652 buf, &cur_x, y, max_x - (ellipses != NULL ? ellipses->width : 0),653 match->application->title, match->start_title, c32len(prompt_text(prompt)),654 font, subpixel,648- pt_or_px_as_pixels(render, &render->options.letter_spacing),655+ pt_or_px_as_pixels(render, &render->conf->letter_spacing),656 (i == selected650- ? render->options.pix_selection_text_color651- : render->options.pix_text_color),652- render->options.pix_match_color, &match->application->shaped);657+ ? render->pix_selection_text_color658+ : render->pix_text_color),659+ render->pix_match_color, &match->application->shaped);660 661 y += row_height;662 }663 1 unmodified line665 mtx_unlock(render->icon_lock);666 }667 668 struct render *662-render_init(const struct render_options *options, mtx_t *icon_lock)669+render_init(const struct config *conf, mtx_t *icon_lock)670 {671 struct render *render = calloc(1, sizeof(*render));672 *render = (struct render){666- .options = *options,673+ .conf = conf,674 .icon_lock = icon_lock,675 };676 670- /* TODO: the one providing the options should calculate these */671- render->options.pix_background_color = rgba2pixman(render->options.background_color);672- render->options.pix_border_color = rgba2pixman(render->options.border_color);673- render->options.pix_text_color = rgba2pixman(render->options.text_color);674- render->options.pix_match_color = rgba2pixman(render->options.match_color);675- render->options.pix_selection_color = rgba2pixman(render->options.selection_color);676- render->options.pix_selection_text_color = rgba2pixman(render->options.selection_text_color);677+ render->pix_background_color = rgba2pixman(render->conf->colors.background);678+ render->pix_border_color = rgba2pixman(render->conf->colors.border);679+ render->pix_text_color = rgba2pixman(render->conf->colors.text);680+ render->pix_match_color = rgba2pixman(render->conf->colors.match);681+ render->pix_selection_color = rgba2pixman(render->conf->colors.selection);682+ render->pix_selection_text_color = rgba2pixman(render->conf->colors.selection_text);683 return render;684 }685 686 void21 unmodified lines708 709 const struct fcft_glyph *W = fcft_rasterize_char_utf32(710 font, U'W', render->subpixel);711 706- const unsigned x_margin = render->options.pad.x * scale;707- const unsigned y_margin = render->options.pad.y * scale;708- const unsigned inner_pad = render->options.pad.inner * scale;712+ const unsigned x_margin = render->conf->pad.x * scale;713+ const unsigned y_margin = render->conf->pad.y * scale;714+ const unsigned inner_pad = render->conf->pad.inner * scale;715 710- const unsigned border_size = render->options.border_size * scale;716+ const unsigned border_size = render->conf->border.size * scale;717 712- const unsigned row_height = render->options.line_height.px >= 0713- ? pt_or_px_as_pixels(render, &render->options.line_height)718+ const unsigned row_height = render->conf->line_height.px >= 0719+ ? pt_or_px_as_pixels(render, &render->conf->line_height)720 : font->height;721 722 const unsigned icon_height = max(0, row_height - font->descent);723 1 unmodified line725 border_size + /* Top border */726 y_margin +727 row_height + /* The prompt */728 inner_pad + /* Padding between prompt and matches */723- render->options.lines * row_height + /* Matches */729+ render->conf->lines * row_height + /* Matches */730 y_margin +731 border_size; /* Bottom border */732 733 const unsigned width =734 border_size +735 x_margin +736 (max((W->advance.x + pt_or_px_as_pixels(731- render, &render->options.letter_spacing)),737+ render, &render->conf->letter_spacing)),738 0)733- * render->options.chars) +739+ * render->conf->chars) +740 x_margin +741 border_size;742 743 LOG_DBG("x-margin: %d, y-margin: %d, border: %d, row-height: %d, "28 unmodified linesmodified:render.h+3 added-37 removed
3 unmodified lines4 #include <pixman.h>5 6 #include <fcft/fcft.h>7 8-#include "shm.h"8+#include "config.h"9 #include "match.h"10+#include "shm.h"11 #include "tllist.h"12 12-struct rgba {double r; double g; double b; double a;};13-struct pt_or_px {int px; float pt;};14-15-struct render_options {16- unsigned lines;17- unsigned chars;18- unsigned border_size;19- unsigned border_radius;20- struct {21- unsigned x;22- unsigned y;23- unsigned inner;24- } pad;25- char32_t password;26-27- struct rgba background_color;28- struct rgba border_color;29- struct rgba text_color;30- struct rgba match_color;31- struct rgba selection_color;32- struct rgba selection_text_color;33-34- struct pt_or_px line_height;35- struct pt_or_px letter_spacing;36-37- /* Filled in by render, for now */38- pixman_color_t pix_background_color;39- pixman_color_t pix_border_color;40- pixman_color_t pix_text_color;41- pixman_color_t pix_match_color;42- pixman_color_t pix_selection_color;43- pixman_color_t pix_selection_text_color;44-};45-13 struct render;47-struct render *render_init(48- const struct render_options *options, mtx_t *icon_lock);14+struct render *render_init(const struct config *conf, mtx_t *icon_lock);15 void render_destroy(struct render *render);16 17 void render_set_subpixel(struct render *render, enum fcft_subpixel subpixel);18 bool render_set_font(struct render *render, struct fcft_font *font,12 unmodified linesmodified:wayland.c+14 added-27 removed
142 unmodified lines143 } pointer;144 };145 146 struct wayland {147+ const struct config *conf;148 struct fdm *fdm;149 struct render *render;150 struct prompt *prompt;151 struct matches *matches;152 152- const struct render_options *render_options;153-153 struct font_spec *fonts;154 size_t font_count;155 struct {156 font_reloaded_t cb;5 unmodified lines162 int height;163 int scale;164 float dpi;165 enum fcft_subpixel subpixel;167- enum dpi_aware dpi_aware;166 bool font_is_sized_by_dpi;167 168 enum { KEEP_RUNNING, EXIT_UPDATE_CACHE, EXIT} status;169 int exit_code;172- enum dmenu_mode dmenu_mode;173- const char *launch_prefix;170 171 struct wl_callback *frame_cb;172 struct buffer *pending;173 5 unmodified lines179 struct zwlr_layer_surface_v1 *layer_surface;180 struct wl_shm *shm;181 struct zxdg_output_manager_v1 *xdg_output_manager;182 187- char *output_name;183 tll(struct monitor) monitors;184 const struct monitor *monitor;185 186 tll(struct seat) seats;251 unmodified lines438 const struct match *match = matches_get_match(wayl->matches);439 struct application *app = match != NULL ? match->application : NULL;440 ssize_t index = match != NULL ? match->index : -1;441 447- if (wayl->dmenu_mode != DMENU_MODE_NONE) {448- dmenu_execute(app, index, wayl->prompt, wayl->dmenu_mode);442+ if (wayl->conf->dmenu.enabled) {443+ dmenu_execute(app, index, wayl->prompt, wayl->conf->dmenu.mode);444 wayl->exit_code = EXIT_SUCCESS;445 } else {451- bool success = application_execute(app, wayl->prompt, wayl->launch_prefix);446+ bool success = application_execute(447+ app, wayl->prompt, wayl->conf->launch_prefix);448 wayl->exit_code = success ? EXIT_SUCCESS : EXIT_FAILURE;449 450 if (success && match != NULL) {451 wayl->status = EXIT_UPDATE_CACHE;419 unmodified lines871 872 static bool873 size_font_using_dpi(const struct wayland *wayl)874 {879- switch (wayl->dpi_aware) {875+ switch (wayl->conf->dpi_aware) {876 case DPI_AWARE_NO: return false;877 case DPI_AWARE_YES: return true;878 879 case DPI_AWARE_AUTO:263 unmodified lines1143 1144 free(mon->name);1145 mon->name = name != NULL ? strdup(name) : NULL;1146 1151- if (wayl->output_name != NULL &&1147+ if (wayl->conf->output != NULL &&1148 mon->name != NULL &&1153- strcmp(wayl->output_name, mon->name) == 0)1149+ strcmp(wayl->conf->output, mon->name) == 0)1150 {1151 wayl->monitor = mon;1152 }1153 }485 unmodified lines1639 }1640 }1641 1642 struct wayland *1647-wayl_init(struct fdm *fdm,1648- struct render *render, struct prompt *prompt, struct matches *matches,1649- const struct render_options *render_options, enum dmenu_mode dmenu_mode,1650- const char *launch_prefix, const char *output_name,1651- const char *font_spec, enum dpi_aware dpi_aware,1652- font_reloaded_t font_reloaded_cb, void *data)1643+wayl_init(const struct config *conf, struct fdm *fdm,1644+ struct render *render, struct prompt *prompt,1645+ struct matches *matches, font_reloaded_t font_reloaded_cb, void *data)1646 {1647 struct wayland *wayl = malloc(sizeof(*wayl));1648 *wayl = (struct wayland){1649+ .conf = conf,1650 .fdm = fdm,1651 .render = render,1652 .prompt = prompt,1653 .matches = matches,1654 .status = KEEP_RUNNING,1661- .exit_code = (dmenu_mode == DMENU_MODE_NONE1662- ? EXIT_SUCCESS : EXIT_FAILURE),1663- .dmenu_mode = dmenu_mode,1664- .launch_prefix = launch_prefix,1665- .output_name = output_name != NULL ? strdup(output_name) : NULL,1666- .render_options = render_options,1655+ .exit_code = !conf->dmenu.enabled ? EXIT_SUCCESS : EXIT_FAILURE,1656 .font_reloaded = {1657 .cb = font_reloaded_cb,1658 .data = data,1659 },1671- .dpi_aware = dpi_aware,1660 };1661 1674- parse_font_spec(font_spec, &wayl->font_count, &wayl->fonts);1662+ parse_font_spec(conf->font, &wayl->font_count, &wayl->fonts);1663 1664 wayl->display = wl_display_connect(NULL);1665 if (wayl->display == NULL) {1666 LOG_ERR("failed to connect to wayland; no compositor running?");162 unmodified lines1829 for (size_t i = 0; i < wayl->font_count; i++)1830 free(wayl->fonts[i].pattern);1831 free(wayl->fonts);1832 1845- free(wayl->output_name);1833 free(wayl);1834 }1835 1836 void16 unmodified linesmodified:wayland.h+7 added-7 removed
1 #pragma once2 3 #include <fcft/fcft.h>4 5+#include "config.h"6 #include "dmenu.h"7 #include "fdm.h"8 #include "match.h"9 #include "prompt.h"3 unmodified lines13 14 typedef void (*font_reloaded_t)(15 struct wayland *wayl, struct fcft_font *font, void *data);16 16-enum dpi_aware {DPI_AWARE_AUTO, DPI_AWARE_YES, DPI_AWARE_NO};17-17 struct wayland *wayl_init(19- struct fdm *fdm,20- struct render *render, struct prompt *prompt, struct matches *matches,21- const struct render_options *render_options, enum dmenu_mode dmenu_mode,22- const char *launch_prefix, const char *output_name, const char *font_spec,23- enum dpi_aware dpi_aware, font_reloaded_t font_reloaded_cb, void *data);18+ const struct config *conf, struct fdm *fdm, struct render *render,19+ struct prompt *prompt, struct matches *matches,20+ //enum dmenu_mode dmenu_mode, const char *launch_prefix,21+ //const char *output_name, const char *font_spec,22+ //enum dpi_aware dpi_aware,23+ font_reloaded_t font_reloaded_cb, void *data);24 25 void wayl_destroy(struct wayland *wayl);26 27 void wayl_refresh(struct wayland *wayl);6 unmodified lines