diff options
-rw-r--r-- | include/display.h | 10 | ||||
-rw-r--r-- | include/helper.h | 28 | ||||
-rw-r--r-- | source/dialogs/drun.c | 4 | ||||
-rw-r--r-- | source/dialogs/run.c | 2 | ||||
-rw-r--r-- | source/dialogs/ssh.c | 2 | ||||
-rw-r--r-- | source/helper.c | 28 | ||||
-rw-r--r-- | source/xcb.c | 4 | ||||
-rw-r--r-- | test/helper-config-cmdline-parser.c | 5 | ||||
-rw-r--r-- | test/helper-expand.c | 5 | ||||
-rw-r--r-- | test/helper-pidfile.c | 5 | ||||
-rw-r--r-- | test/helper-test.c | 5 | ||||
-rw-r--r-- | test/helper-tokenize.c | 5 | ||||
-rw-r--r-- | test/mode-test.c | 6 | ||||
-rw-r--r-- | test/textbox-test.c | 5 | ||||
-rw-r--r-- | test/theme-parser-test.c | 5 | ||||
-rw-r--r-- | test/widget-test.c | 5 |
16 files changed, 115 insertions, 9 deletions
diff --git a/include/display.h b/include/display.h index b0feb8c7..a6977808 100644 --- a/include/display.h +++ b/include/display.h @@ -29,6 +29,7 @@ #define ROFI_DISPLAY_H #include <glib.h> +#include "helper.h" #include "nkutils-bindings.h" /** @@ -63,4 +64,13 @@ void display_cleanup(void); */ void display_dump_monitor_layout ( void ); +/** + * @param context The startup notification context for the application to launch + * @param child_setup A pointer to return the child setup function + * @param user_data A pointer to return the child setup function user_data + * + * Provides the needed child setup function + */ +void display_startup_notification ( RofiHelperExecuteContext *context, GSpawnChildSetupFunc *child_setup, gpointer *user_data ); + #endif diff --git a/include/helper.h b/include/helper.h index de9419dd..1b75f6c8 100644 --- a/include/helper.h +++ b/include/helper.h @@ -260,26 +260,50 @@ int rofi_scorer_fuzzy_evaluate ( const char *pattern, glong plen, const char *st int utf8_strncmp ( const char *a, const char* b, size_t n ) __attribute__( ( nonnull ( 1, 2 ) ) ); /** + * The startup notification context of the application to launch + */ +typedef struct +{ + /** The name of the application */ + const gchar *name; + /** The binary name of the application */ + const gchar *binary; + /** The description of the launch */ + const gchar *description; + /** The icon name of the application */ + const gchar *icon; + /** The application id (desktop file with the .desktop suffix) */ + const gchar *app_id; + /** The window manager class of the application */ + const gchar *wmclass; + /** The command we run */ + const gchar *command; +} RofiHelperExecuteContext; + +/** * @param args The arguments of the command to exec. * @param error_precmd Prefix to error message command. * @param error_cmd Error message command + * @param context The startup notification context, if any * * Executes the command * * @returns TRUE when successful, FALSE when failed. */ -gboolean helper_execute ( const char *wd, char **args, const char *error_precmd, const char *error_cmd ); +gboolean helper_execute ( const char *wd, char **args, const char *error_precmd, const char *error_cmd, RofiHelperExecuteContext *context ); /** * @param wd The work directory (optional) * @param cmd The cmd to execute * @param run_in_term Indicate if command should be run in a terminal + * @param context The startup notification context, if any * * Execute command. + * If needed members of @param context are NULL, they will be filled. * * @returns FALSE On failure, TRUE on success */ -gboolean helper_execute_command ( const char *wd, const char *cmd, int run_in_term ); +gboolean helper_execute_command ( const char *wd, const char *cmd, gboolean run_in_term, RofiHelperExecuteContext *context ); /** * @param file The file path diff --git a/source/dialogs/drun.c b/source/dialogs/drun.c index b4834c4f..f9686b99 100644 --- a/source/dialogs/drun.c +++ b/source/dialogs/drun.c @@ -185,7 +185,7 @@ static void exec_cmd_entry ( DRunModeEntry *e ) // Returns false if not found, if key not found, we don't want run in terminal. gboolean terminal = g_key_file_get_boolean ( e->key_file, "Desktop Entry", "Terminal", NULL ); - if ( helper_execute_command ( exec_path, fp, terminal ) ) { + if ( helper_execute_command ( exec_path, fp, terminal, NULL ) ) { char *path = g_build_filename ( cache_dir, DRUN_CACHE_FILE, NULL ); char *key = g_strdup_printf ( "%s:::%s", e->root, e->path ); history_set ( path, key ); @@ -511,7 +511,7 @@ static ModeMode drun_mode_result ( Mode *sw, int mretv, char **input, unsigned i exec_cmd_entry ( &( rmpd->entry_list[selected_line] ) ); } else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] != '\0' ) { - helper_execute_command ( NULL, *input, run_in_term ); + helper_execute_command ( NULL, *input, run_in_term, NULL ); } else if ( ( mretv & MENU_ENTRY_DELETE ) && selected_line < rmpd->cmd_list_length ) { if ( selected_line < rmpd->history_length ) { diff --git a/source/dialogs/run.c b/source/dialogs/run.c index 9a19d662..0acde0a2 100644 --- a/source/dialogs/run.c +++ b/source/dialogs/run.c @@ -92,7 +92,7 @@ static void exec_cmd ( const char *cmd, int run_in_term ) } char *path = g_build_filename ( cache_dir, RUN_CACHE_FILE, NULL ); - if ( helper_execute_command ( NULL, lf_cmd, run_in_term ) ) { + if ( helper_execute_command ( NULL, lf_cmd, run_in_term, NULL ) ) { /** * This happens in non-critical time (After launching app) * It is allowed to be a bit slower. diff --git a/source/dialogs/ssh.c b/source/dialogs/ssh.c index 66fdc74a..5be70221 100644 --- a/source/dialogs/ssh.c +++ b/source/dialogs/ssh.c @@ -81,7 +81,7 @@ static inline int execshssh ( const char *host ) helper_parse_setup ( config.ssh_command, &args, &argsv, "{host}", host, NULL ); - return helper_execute ( NULL, args, "ssh ", host ); + return helper_execute ( NULL, args, "ssh ", host, NULL ); } /** diff --git a/source/helper.c b/source/helper.c index ebcf783d..2eac638e 100644 --- a/source/helper.c +++ b/source/helper.c @@ -47,6 +47,7 @@ #include <pango/pango-fontmap.h> #include <pango/pangocairo.h> #include <librsvg/rsvg.h> +#include "display.h" #include "xcb.h" #include "helper.h" #include "helper-theme.h" @@ -962,7 +963,7 @@ int utf8_strncmp ( const char* a, const char* b, size_t n ) return r; } -gboolean helper_execute ( const char *wd, char **args, const char *error_precmd, const char *error_cmd ) +gboolean helper_execute ( const char *wd, char **args, const char *error_precmd, const char *error_cmd, RofiHelperExecuteContext *context ) { gboolean retv = TRUE; GError *error = NULL; @@ -970,6 +971,8 @@ gboolean helper_execute ( const char *wd, char **args, const char *error_precmd, GSpawnChildSetupFunc child_setup = NULL; gpointer user_data = NULL; + display_startup_notification ( context, &child_setup, &user_data ); + g_spawn_async ( wd, args, NULL, G_SPAWN_SEARCH_PATH, child_setup, user_data, NULL, &error ); if ( error != NULL ) { char *msg = g_strdup_printf ( "Failed to execute: '%s%s'\nError: '%s'", error_precmd, error_cmd, error->message ); @@ -985,7 +988,7 @@ gboolean helper_execute ( const char *wd, char **args, const char *error_precmd, return retv; } -gboolean helper_execute_command ( const char *wd, const char *cmd, int run_in_term ) +gboolean helper_execute_command ( const char *wd, const char *cmd, gboolean run_in_term, RofiHelperExecuteContext *context ) { char **args = NULL; int argc = 0; @@ -997,7 +1000,26 @@ gboolean helper_execute_command ( const char *wd, const char *cmd, int run_in_te helper_parse_setup ( config.run_command, &args, &argc, "{cmd}", cmd, NULL ); } - return helper_execute ( wd, args, "", cmd ); + if ( context != NULL ) { + if ( context->name == NULL ) { + context->name = args[0]; + } + if ( context->binary == NULL ) { + context->binary = args[0]; + } + if ( context->description == NULL ) { + gsize l = strlen ( "Launching '' via rofi" ) + strlen ( cmd ) + 1; + gchar *description = g_newa ( gchar, l ); + + g_snprintf ( description, l, "Launching '%s' via rofi", cmd ); + context->description = description; + } + if ( context->command == NULL ) { + context->command = cmd; + } + } + + return helper_execute ( wd, args, "", cmd, context ); } char *helper_get_theme_path ( const char *file ) diff --git a/source/xcb.c b/source/xcb.c index 13dbdd6a..57130c5d 100644 --- a/source/xcb.c +++ b/source/xcb.c @@ -359,6 +359,10 @@ void display_dump_monitor_layout ( void ) } } +void display_startup_notification ( RofiHelperExecuteContext *context, GSpawnChildSetupFunc *child_setup, gpointer *user_data ) +{ +} + static int monitor_get_dimension ( int monitor_id, workarea *mon ) { memset ( mon, 0, sizeof ( workarea ) ); diff --git a/test/helper-config-cmdline-parser.c b/test/helper-config-cmdline-parser.c index 741230cb..3e1ddcb5 100644 --- a/test/helper-config-cmdline-parser.c +++ b/test/helper-config-cmdline-parser.c @@ -32,6 +32,7 @@ #include <helper.h> #include <string.h> #include <xcb/xcb_ewmh.h> +#include "display.h" #include "xcb.h" #include "xcb-internal.h" #include "rofi.h" @@ -65,6 +66,10 @@ int monitor_active ( G_GNUC_UNUSED workarea *mon ) return 0; } +void display_startup_notification ( G_GNUC_UNUSED RofiHelperExecuteContext *context, G_GNUC_UNUSED GSpawnChildSetupFunc *child_setup, G_GNUC_UNUSED gpointer *user_data ) +{ +} + int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char ** argv ) { diff --git a/test/helper-expand.c b/test/helper-expand.c index 09760feb..628ffc7e 100644 --- a/test/helper-expand.c +++ b/test/helper-expand.c @@ -32,6 +32,7 @@ #include <helper.h> #include <string.h> #include <xcb/xcb_ewmh.h> +#include "display.h" #include "xcb.h" #include "xcb-internal.h" #include "rofi.h" @@ -66,6 +67,10 @@ int monitor_active ( G_GNUC_UNUSED workarea *mon ) return 0; } +void display_startup_notification ( G_GNUC_UNUSED RofiHelperExecuteContext *context, G_GNUC_UNUSED GSpawnChildSetupFunc *child_setup, G_GNUC_UNUSED gpointer *user_data ) +{ +} + int main ( int argc, char ** argv ) { cmd_set_arguments ( argc, argv ); diff --git a/test/helper-pidfile.c b/test/helper-pidfile.c index d01b5a66..9a5470cd 100644 --- a/test/helper-pidfile.c +++ b/test/helper-pidfile.c @@ -32,6 +32,7 @@ #include <helper.h> #include <string.h> #include <xcb/xcb_ewmh.h> +#include "display.h" #include "xcb.h" #include "xcb-internal.h" #include "rofi.h" @@ -56,6 +57,10 @@ int monitor_active ( G_GNUC_UNUSED workarea *mon ) return 0; } +void display_startup_notification ( G_GNUC_UNUSED RofiHelperExecuteContext *context, G_GNUC_UNUSED GSpawnChildSetupFunc *child_setup, G_GNUC_UNUSED gpointer *user_data ) +{ +} + int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char ** argv ) { if ( setlocale ( LC_ALL, "" ) == NULL ) { diff --git a/test/helper-test.c b/test/helper-test.c index 6a3cf2de..1ba581c8 100644 --- a/test/helper-test.c +++ b/test/helper-test.c @@ -32,6 +32,7 @@ #include <helper.h> #include <string.h> #include <xcb/xcb_ewmh.h> +#include "display.h" #include "xcb.h" #include "xcb-internal.h" #include "rofi.h" @@ -75,6 +76,10 @@ int monitor_active ( G_GNUC_UNUSED workarea *mon ) return 0; } +void display_startup_notification ( G_GNUC_UNUSED RofiHelperExecuteContext *context, G_GNUC_UNUSED GSpawnChildSetupFunc *child_setup, G_GNUC_UNUSED gpointer *user_data ) +{ +} + int main ( int argc, char ** argv ) { cmd_set_arguments ( argc, argv ); diff --git a/test/helper-tokenize.c b/test/helper-tokenize.c index 87212955..c251f04e 100644 --- a/test/helper-tokenize.c +++ b/test/helper-tokenize.c @@ -32,6 +32,7 @@ #include <helper.h> #include <string.h> #include <xcb/xcb_ewmh.h> +#include "display.h" #include "xcb.h" #include "xcb-internal.h" #include "rofi.h" @@ -56,6 +57,10 @@ int monitor_active ( G_GNUC_UNUSED workarea *mon ) return 0; } +void display_startup_notification ( G_GNUC_UNUSED RofiHelperExecuteContext *context, G_GNUC_UNUSED GSpawnChildSetupFunc *child_setup, G_GNUC_UNUSED gpointer *user_data ) +{ +} + int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char ** argv ) { if ( setlocale ( LC_ALL, "" ) == NULL ) { diff --git a/test/mode-test.c b/test/mode-test.c index 25f51cb1..00720d95 100644 --- a/test/mode-test.c +++ b/test/mode-test.c @@ -38,6 +38,7 @@ #include <dialogs/help-keys.h> #include <xkbcommon/xkbcommon.h> #include "rofi.h" +#include "display.h" #include "xcb.h" #include <keyb.h> #include <helper.h> @@ -73,6 +74,11 @@ gboolean rofi_view_trigger_action ( G_GNUC_UNUSED RofiViewState *state, G_GNUC_U { return FALSE; } + +void display_startup_notification ( G_GNUC_UNUSED RofiHelperExecuteContext *context, G_GNUC_UNUSED GSpawnChildSetupFunc *child_setup, G_GNUC_UNUSED gpointer *user_data ) +{ +} + #ifndef _ck_assert_ptr_null /* Pointer against NULL comparison macros with improved output * compared to ck_assert(). */ diff --git a/test/textbox-test.c b/test/textbox-test.c index 539a6a54..edb2d0ff 100644 --- a/test/textbox-test.c +++ b/test/textbox-test.c @@ -37,6 +37,7 @@ #include <widgets/textbox.h> #include <rofi.h> #include <cairo-xlib.h> +#include "display.h" #include "xcb.h" #include "settings.h" #include "xrmoptions.h" @@ -76,6 +77,10 @@ int monitor_active ( G_GNUC_UNUSED workarea *mon ) return 0; } +void display_startup_notification ( G_GNUC_UNUSED RofiHelperExecuteContext *context, G_GNUC_UNUSED GSpawnChildSetupFunc *child_setup, G_GNUC_UNUSED gpointer *user_data ) +{ +} + int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv ) { cairo_surface_t *surf = cairo_image_surface_create ( CAIRO_FORMAT_ARGB32, 100, 100 ); diff --git a/test/theme-parser-test.c b/test/theme-parser-test.c index 4707f8d3..c84bba61 100644 --- a/test/theme-parser-test.c +++ b/test/theme-parser-test.c @@ -35,6 +35,7 @@ #include "xcb-internal.h" #include "rofi.h" #include "settings.h" +#include "display.h" #include "xcb.h" #include "theme.h" #include "css-colors.h" @@ -70,6 +71,10 @@ int monitor_active ( G_GNUC_UNUSED workarea *mon ) return 0; } +void display_startup_notification ( G_GNUC_UNUSED RofiHelperExecuteContext *context, G_GNUC_UNUSED GSpawnChildSetupFunc *child_setup, G_GNUC_UNUSED gpointer *user_data ) +{ +} + #ifndef _ck_assert_ptr_null /* Pointer against NULL comparison macros with improved output * compared to ck_assert(). */ diff --git a/test/widget-test.c b/test/widget-test.c index 49c5b6ac..78cd4c4a 100644 --- a/test/widget-test.c +++ b/test/widget-test.c @@ -35,6 +35,7 @@ #include <widgets/widget.h> #include <widgets/widget-internal.h> #include "rofi.h" +#include "display.h" #include "xrmoptions.h" #include "xcb.h" unsigned int test =0; @@ -66,6 +67,10 @@ int rofi_view_error_dialog ( const char *msg, G_GNUC_UNUSED int markup ) return FALSE; } +void display_startup_notification ( G_GNUC_UNUSED RofiHelperExecuteContext *context, G_GNUC_UNUSED GSpawnChildSetupFunc *child_setup, G_GNUC_UNUSED gpointer *user_data ) +{ +} + int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv ) { // box 20 by 40 |