From 831bddc68b79c58044dbfeb2be62f77948e1726b Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Thu, 15 Feb 2024 09:13:37 +0100 Subject: [PATCH 01/19] [Box] When estimating height, set correct width on children Issue: #1943 --- source/widgets/box.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/widgets/box.c b/source/widgets/box.c index 3a5c49d49..e0425b8e3 100644 --- a/source/widgets/box.c +++ b/source/widgets/box.c @@ -96,6 +96,7 @@ static int box_get_desired_height(widget *wid, const int width) { box *b = (box *)wid; int spacing = distance_get_pixel(b->spacing, b->type); int height = 0; + int nw = width - widget_padding_get_padding_width(wid); if (b->type == ROFI_ORIENTATION_VERTICAL) { int active_widgets = 0; for (GList *iter = g_list_first(b->children); iter != NULL; @@ -105,7 +106,7 @@ static int box_get_desired_height(widget *wid, const int width) { continue; } active_widgets++; - height += widget_get_desired_height(child, width); + height += widget_get_desired_height(child, nw); } if (active_widgets > 0) { height += (active_widgets - 1) * spacing; @@ -117,7 +118,7 @@ static int box_get_desired_height(widget *wid, const int width) { if (!child->enabled) { continue; } - height = MAX(widget_get_desired_height(child, width), height); + height = MAX(widget_get_desired_height(child, nw), height); } } height += widget_padding_get_padding_height(wid); From 3a5f95d69e0a3d2bd20a247882ba4c30cdf0b845 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Fri, 16 Feb 2024 13:36:21 +0100 Subject: [PATCH 02/19] [View] Don't use xcb surface to render to png, but create surface. --- source/view.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/source/view.c b/source/view.c index 29ca23073..fe438daee 100644 --- a/source/view.c +++ b/source/view.c @@ -217,13 +217,13 @@ static int lev_sort(const void *p1, const void *p2, void *arg) { /** * Stores a screenshot of Rofi at that point in time. */ -void rofi_capture_screenshot(void) { - const char *outp = g_getenv("ROFI_PNG_OUTPUT"); - if (CacheState.edit_surf == NULL) { - // Nothing to store. - g_warning("There is no rofi surface to store"); +void rofi_capture_screenshot() { + RofiViewState *state = current_active_menu; + if (state == NULL || state->main_window == NULL) { + g_warning("Nothing to screenshot."); return; } + const char *outp = g_getenv("ROFI_PNG_OUTPUT"); const char *xdg_pict_dir = g_get_user_special_dir(G_USER_DIRECTORY_PICTURES); if (outp == NULL && xdg_pict_dir == NULL) { g_warning("XDG user picture directory or ROFI_PNG_OUTPUT is not set. " @@ -254,12 +254,30 @@ void rofi_capture_screenshot(void) { fpath = g_strdup(outp); } fprintf(stderr, color_green "Storing screenshot %s\n" color_reset, fpath); - cairo_status_t status = - cairo_surface_write_to_png(CacheState.edit_surf, fpath); + cairo_surface_t *surf = cairo_image_surface_create( + CAIRO_FORMAT_ARGB32, state->width, state->height); + cairo_status_t status = cairo_surface_status(surf); if (status != CAIRO_STATUS_SUCCESS) { g_warning("Failed to produce screenshot '%s', got error: '%s'", fpath, cairo_status_to_string(status)); + } else { + cairo_t *draw = cairo_create(surf); + status = cairo_status(draw); + if (status != CAIRO_STATUS_SUCCESS) { + g_warning("Failed to produce screenshot '%s', got error: '%s'", fpath, + cairo_status_to_string(status)); + } else { + widget_draw(WIDGET(state->main_window), draw); + status = cairo_surface_write_to_png(surf, fpath); + if (status != CAIRO_STATUS_SUCCESS) { + g_warning("Failed to produce screenshot '%s', got error: '%s'", fpath, + cairo_status_to_string(status)); + } + } + cairo_destroy(draw); } + // Cleanup + cairo_surface_destroy(surf); g_free(fpath); g_free(filename); g_free(timestmp); From f539a082228aef10861ea8742f92938c4c8dd162 Mon Sep 17 00:00:00 2001 From: lbonn Date: Fri, 16 Feb 2024 18:41:07 +0100 Subject: [PATCH 03/19] [Build] Reduce amount of warnings (#1944) * one unused parameter in recursivebrowser.c * overlength strings are overly pedantic, modern compilers support large strings * __FUNCTION__ creeped back in after #288 --- configure.ac | 2 +- meson.build | 1 + source/modes/recursivebrowser.c | 2 +- source/rofi-icon-fetcher.c | 2 +- source/xcb.c | 10 +++++----- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index 908b2f809..bc5563ce4 100644 --- a/configure.ac +++ b/configure.ac @@ -74,7 +74,7 @@ AM_PROG_AR dnl --------------------------------------------------------------------- dnl Base CFLAGS dnl --------------------------------------------------------------------- -AM_CFLAGS="-Wall -Wextra -Wparentheses -Winline -pedantic -Wunreachable-code" +AM_CFLAGS="-Wall -Wextra -Wparentheses -Winline -pedantic -Wno-overlength-strings -Wunreachable-code" dnl --------------------------------------------------------------------- dnl Enable source code coverage reporting for GCC diff --git a/meson.build b/meson.build index ff5fb2b35..1018becdd 100644 --- a/meson.build +++ b/meson.build @@ -22,6 +22,7 @@ flags = [ '-Winline', '-Wunreachable-code', '-Werror=missing-prototypes', + '-Wno-overlength-strings', '-Wno-inline' # A bit too noisy with Bison… ] foreach f : flags diff --git a/source/modes/recursivebrowser.c b/source/modes/recursivebrowser.c index 3e010b418..206fdf854 100644 --- a/source/modes/recursivebrowser.c +++ b/source/modes/recursivebrowser.c @@ -335,7 +335,7 @@ static unsigned int recursive_browser_mode_get_num_entries(const Mode *sw) { return pd->array_length; } -static ModeMode recursive_browser_mode_result(Mode *sw, int mretv, char **input, +static ModeMode recursive_browser_mode_result(Mode *sw, int mretv, G_GNUC_UNUSED char **input, unsigned int selected_line) { ModeMode retv = MODE_EXIT; FileBrowserModePrivateData *pd = diff --git a/source/rofi-icon-fetcher.c b/source/rofi-icon-fetcher.c index c2bb0f1f4..e3d6f4dd0 100644 --- a/source/rofi-icon-fetcher.c +++ b/source/rofi-icon-fetcher.c @@ -361,7 +361,7 @@ static void rofi_icon_fetcher_worker(thread_state *sdata, icon_path, sentry->wsize, sentry->hsize, TRUE, &error); if (error != NULL) { g_warning("Failed to load image: |%s| %d %d %s (%p)", icon_path, - sentry->wsize, sentry->hsize, error->message, pb); + sentry->wsize, sentry->hsize, error->message, (void*)pb); g_error_free(error); if (pb) { g_object_unref(pb); diff --git a/source/xcb.c b/source/xcb.c index 4e1039790..db8da2eac 100644 --- a/source/xcb.c +++ b/source/xcb.c @@ -775,7 +775,7 @@ static int monitor_get_dimension(int monitor_id, workarea *mon) { // find the dimensions of the monitor displaying point x,y static void monitor_dimensions(int x, int y, workarea *mon) { if (mon == NULL) { - g_error("%s: mon == NULL", __FUNCTION__); + g_error("%s: mon == NULL", __func__); return; } memset(mon, 0, sizeof(workarea)); @@ -818,7 +818,7 @@ static int pointer_get(xcb_window_t root, int *x, int *y) { static int monitor_active_from_winid(xcb_drawable_t id, workarea *mon) { if (mon == NULL) { - g_error("%s: mon == NULL", __FUNCTION__); + g_error("%s: mon == NULL", __func__); return FALSE; } xcb_window_t root = xcb->screen->root; @@ -851,7 +851,7 @@ static int monitor_active_from_id_focused(int mon_id, workarea *mon) { xcb_window_t active_window; xcb_get_property_cookie_t awc; if (mon == NULL) { - g_error("%s: mon == NULL", __FUNCTION__); + g_error("%s: mon == NULL", __func__); return retv; } awc = xcb_ewmh_get_active_window(&xcb->ewmh, xcb->screen_nbr); @@ -920,7 +920,7 @@ static int monitor_active_from_id(int mon_id, workarea *mon) { xcb_window_t root = xcb->screen->root; int x, y; if (mon == NULL) { - g_error("%s: mon == NULL", __FUNCTION__); + g_error("%s: mon == NULL", __func__); return FALSE; } g_debug("Monitor id: %d", mon_id); @@ -1000,7 +1000,7 @@ workarea mon_cache = { }; int monitor_active(workarea *mon) { if (mon == NULL) { - g_error("%s: mon == NULL", __FUNCTION__); + g_error("%s: mon == NULL", __func__); return FALSE; } g_debug("Monitor active"); From 1c8159c4c893ff558b28345a82270a142da3fc5d Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Sun, 18 Feb 2024 11:35:39 +0100 Subject: [PATCH 04/19] [DRun] Drun read url field from cache. --- source/modes/drun.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/modes/drun.c b/source/modes/drun.c index b05ce48e4..444b87da3 100644 --- a/source/modes/drun.c +++ b/source/modes/drun.c @@ -1010,6 +1010,7 @@ static gboolean drun_read_cache(DRunModePrivateData *pd, drun_read_stringv(fd, &(entry->keywords)); drun_read_string(fd, &(entry->comment)); + drun_read_string(fd, &(entry->url)); int32_t type = 0; drun_read_integer(fd, &(type)); entry->type = type; From 83ecbfe127aebb2462de1ab626406d62cab80cdf Mon Sep 17 00:00:00 2001 From: Qball Cow Date: Thu, 22 Feb 2024 08:43:26 +0100 Subject: [PATCH 05/19] [config] By default escape run command. --- config/config.c | 6 +- doc/rofi.1 | 688 +++++++++++++++++--------------------------- doc/rofi.1.markdown | 6 +- 3 files changed, 266 insertions(+), 434 deletions(-) diff --git a/config/config.c b/config/config.c index 7bde97035..1c7c6d39b 100644 --- a/config/config.c +++ b/config/config.c @@ -50,13 +50,13 @@ Settings config = { .terminal_emulator = "rofi-sensible-terminal", .ssh_client = "ssh", /** Command when executing ssh. */ - .ssh_command = "{terminal} -e {ssh-client} {host} [-p {port}]", + .ssh_command = "{terminal} -e '{ssh-client}' '{host}' [-p {port}]", /** Command when running */ - .run_command = "{cmd}", + .run_command = "'{cmd}'", /** Command used to list executable commands. empty -> internal */ .run_list_command = "", /** Command executed when running application in terminal */ - .run_shell_command = "{terminal} -e {cmd}", + .run_shell_command = "{terminal} -e '{cmd}'", /** Command executed on accep-entry-custom for window modus */ .window_command = "wmctrl -i -R {window}", /** No default icon theme, we search Adwaita and gnome as fallback */ diff --git a/doc/rofi.1 b/doc/rofi.1 index 6d4c10e93..3bbf720a7 100644 --- a/doc/rofi.1 +++ b/doc/rofi.1 @@ -19,37 +19,29 @@ keyboard and mouse navigation, type to filter, tokenized search and more. .PP \fBrofi\fP\&'s main functionality is to assist in your workflow, allowing you to quickly switch between windows, start applications or log into a remote machine -via \fB\fCssh\fR\&. There are different \fImodes\fP for different types of actions. \fBrofi\fP +via \fBssh\fR\&. There are different \fImodes\fP for different types of actions. \fBrofi\fP is a standalone application and should not be integrated into scripts. For integration into scripts it has a special mode that functions as a (drop-in) replacement for \fBdmenu(1)\fP\&. See emulating dmenu below. .SS Running rofi .PP -To launch \fBrofi\fP directly in a certain mode, specify a mode with \fB\fCrofi -show -\fR\&. To show the \fB\fCdrun\fR dialog: +To launch \fBrofi\fP directly in a certain mode, specify a mode with \fBrofi -show +\fR\&. To show the \fBdrun\fR dialog: -.PP -.RS - -.nf +.EX rofi -show drun -.fi -.RE +.EE .PP -A useful setup in minimalistic window managers is to combine \fB\fCdrun\fR, \fB\fCrun\fR -with \fB\fCwindow\fR mode: +A useful setup in minimalistic window managers is to combine \fBdrun\fR, \fBrun\fR +with \fBwindow\fR mode: -.PP -.RS - -.nf +.EX rofi -show combi -modes combi -combi-modes "window,drun,run" -.fi -.RE +.EE .PP In this setup it first list all open applications, then all installed @@ -59,7 +51,7 @@ running firefox, or launch it when it is not running. .SS Emulating dmenu .PP \fBrofi\fP can emulate \fBdmenu(1)\fP (a dynamic menu for X11) when launched with -the \fB\fC-dmenu\fR flag. +the \fB-dmenu\fR flag. .PP For more information see \fBrofi-dmenu(5)\fP\&. @@ -68,14 +60,10 @@ For more information see \fBrofi-dmenu(5)\fP\&. .PP \fBrofi\fP error dialog can also be called from the command line. -.PP -.RS - -.nf +.EX rofi -e "my message" -.fi -.RE +.EE .PP Markup support can be enabled, see CONFIGURATION options. @@ -87,8 +75,8 @@ in order below): .RS .IP \(bu 2 -System configuration file (for example \fB\fC/etc/rofi.rasi\fR). It first checks -\fB\fCXDG_CONFIG_DIRS\fR, and then \fB\fCSYSCONFDIR\fR (that is passed at compile time). +System configuration file (for example \fB/etc/rofi.rasi\fR). It first checks +\fBXDG_CONFIG_DIRS\fR, and then \fBSYSCONFDIR\fR (that is passed at compile time). It loads the first config file it finds, it does not merge multiple system configuration files. .IP \(bu 2 @@ -100,14 +88,14 @@ Command-line options: Arguments passed to \fBrofi\fP\&. .RE .PP -To get a template config file, run: \fB\fCrofi -dump-config > config.rasi\fR +To get a template config file, run: \fBrofi -dump-config > config.rasi\fR .PP This will contain (commented) all current configuration options, modified options are uncommented. .PP -To get a template config file that sets the icon-theme run: \fB\fCrofi -icon-theme +To get a template config file that sets the icon-theme run: \fBrofi -icon-theme hicolor -dump-config\fR\&. .PP @@ -117,34 +105,26 @@ configuration. .PP An empty configuration section in the config file looks like: -.PP -.RS - -.nf +.EX configuration { // set config options here } -.fi -.RE +.EE .PP -Most of the configuration options mentioned below (beside options like \fB\fC-show\fR, -\fB\fC-dump-config\fR that apply to a single run) can be set here. +Most of the configuration options mentioned below (beside options like \fB-show\fR, +\fB-dump-config\fR that apply to a single run) can be set here. .PP For example to set the dpi value to 72: -.PP -.RS - -.nf +.EX configuration { dpi: 72; } -.fi -.RE +.EE .PP The configuration system supports the following types: @@ -170,72 +150,64 @@ For the syntax of these options, see the \fBrofi-theme(5)\fP manpage. For use on the command line, Boolean options have a non-default command-line syntax. Example to enable option X: -.PP -.RS - -.nf +.EX -X -.fi -.RE +.EE .PP To disable option X: -.PP -.RS - -.nf +.EX -no-X -.fi -.RE +.EE .PP Below is a list of the most important options: .SS General .PP -\fB\fC-help\fR +\fB-help\fR .PP The help option shows the full list of command-line options and the current set values. These include dynamic (run-time generated) options. .PP -\fB\fC-version\fR +\fB-version\fR .PP Show the \fBrofi\fP version and exit. .PP -\fB\fC-dump-config\fR +\fB-dump-config\fR .PP Dump the current active configuration, in rasi format, to stdout and exit. Information about the rasi format can be found in the \fBrofi-theme(5)\fP manpage. .PP -\fB\fC-dump-theme\fR +\fB-dump-theme\fR .PP Dump the current active theme, in rasi format, to stdout and exit. .PP -\fB\fC-rasi-validate\fR \fIfilename\fP +\fB-rasi-validate\fR \fIfilename\fP .PP Try to parse the file and return 0 when successful, non-zero when failed. .PP -\fB\fC-list-keybindings\fR +\fB-list-keybindings\fR .PP List all known keybindings without trying to parse them. This can be used to look for duplicate bindings. .PP -\fB\fC-threads\fR \fInum\fP +\fB-threads\fR \fInum\fP .PP Specify the number of threads \fBrofi\fP should use: @@ -254,225 +226,197 @@ Specify the number of threads \fBrofi\fP should use: Default: Autodetect .PP -\fB\fC-display\fR \fIdisplay\fP +\fB-display\fR \fIdisplay\fP .PP -The X server to contact. Default is \fB\fC$DISPLAY\fR\&. +The X server to contact. Default is \fB$DISPLAY\fR\&. .PP -\fB\fC-dmenu\fR +\fB-dmenu\fR .PP Run \fBrofi\fP in dmenu mode. This allows for interactive scripts. -In \fB\fCdmenu\fR mode, \fBrofi\fP reads from STDIN, and output to STDOUT. +In \fBdmenu\fR mode, \fBrofi\fP reads from STDIN, and output to STDOUT. A simple example, displaying three pre-defined options: -.PP -.RS - -.nf +.EX echo -e "Option #1\\nOption #2\\nOption #3" | rofi -dmenu -.fi -.RE +.EE .PP Or get the options from a script: -.PP -.RS - -.nf +.EX ~/my_script.sh | rofi -dmenu -.fi -.RE +.EE .PP See the \fBrofi-dmenu(5)\fP manpage for more information. .PP -\fB\fC-show\fR \fImode\fP +\fB-show\fR \fImode\fP .PP -Open \fBrofi\fP in a certain mode. Available modes are \fB\fCwindow\fR, \fB\fCrun\fR, \fB\fCdrun\fR, -\fB\fCssh\fR, \fB\fCcombi\fR\&. The special argument \fB\fCkeys\fR can be used to open a searchable +Open \fBrofi\fP in a certain mode. Available modes are \fBwindow\fR, \fBrun\fR, \fBdrun\fR, +\fBssh\fR, \fBcombi\fR\&. The special argument \fBkeys\fR can be used to open a searchable list of supported key bindings (see the \fBrofi-keys(5)\fP manpage) .PP To show the run-dialog: -.PP -.RS - -.nf +.EX rofi -show run -.fi -.RE +.EE .PP -If \fB\fC-show\fR is the last option passed to rofi, the first enabled modes is shown. +If \fB-show\fR is the last option passed to rofi, the first enabled modes is shown. .PP -\fB\fC-modes\fR \fImode1,mode2\fP +\fB-modes\fR \fImode1,mode2\fP .PP Specify an ordered, comma-separated list of modes to enable. -Enabled modes can be changed at runtime. Default key is \fB\fCCtrl+Tab\fR\&. +Enabled modes can be changed at runtime. Default key is \fBCtrl+Tab\fR\&. If no modes are specified, all configured modes will be enabled. -To only show the \fB\fCrun\fR and \fB\fCssh\fR launcher: - -.PP -.RS +To only show the \fBrun\fR and \fBssh\fR launcher: -.nf +.EX rofi -modes "run,ssh" -show run -.fi -.RE +.EE .PP -Custom modes can be added using the internal \fB\fCscript\fR mode. Each such mode has +Custom modes can be added using the internal \fBscript\fR mode. Each such mode has two parameters: -.PP -.RS - -.nf +.EX :