Skip to content

Commit a69073c

Browse files
committed
desktop: patch rofi to produce {app_id} for systemd-run names
davatorium/rofi#2048 (comment)
1 parent 52f29a9 commit a69073c

File tree

2 files changed

+145
-1
lines changed

2 files changed

+145
-1
lines changed

modules/desktop/module.nix

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,15 @@ in
152152

153153
environment.systemPackages = (with pkgs; [
154154
brightnessctl
155-
rofi-wayland
155+
(rofi-wayland.override {
156+
rofi-unwrapped = pkgs.rofi-wayland-unwrapped.overrideAttrs (old: {
157+
patches = old.patches or [ ] ++ [
158+
# Makes {app_id} available in -run-command.
159+
# https://github.com/davatorium/rofi/pull/2048#issuecomment-2466841262
160+
./rofi-desktop-app-id.patch
161+
];
162+
});
163+
})
156164
wev
157165
])
158166
++ lib.optionals this.tablet (with pkgs; [
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
diff --git a/include/helper.h b/include/helper.h
2+
index ed161931..6e9a28f1 100644
3+
--- a/include/helper.h
4+
+++ b/include/helper.h
5+
@@ -330,6 +330,23 @@ gboolean helper_execute_command(const char *wd, const char *cmd,
6+
gboolean run_in_term,
7+
RofiHelperExecuteContext *context);
8+
9+
+/**
10+
+ * @param wd The work directory (optional)
11+
+ * @param cmd The cmd to execute
12+
+ * @param run_in_term Indicate if command should be run in a terminal
13+
+ * @param context The startup notification context, if any
14+
+ * @param ... tuples of extra parameters the string can search/replace
15+
+ *
16+
+ * Execute command.
17+
+ * If needed members of context are NULL, they will be filled.
18+
+ * Pass {cmd} into the va-arg list.
19+
+ *
20+
+ * @returns FALSE On failure, TRUE on success
21+
+ */
22+
+gboolean helper_execute_command_full(const char *wd, const char *cmd,
23+
+ gboolean run_in_term,
24+
+ RofiHelperExecuteContext *context, ...);
25+
+
26+
/**
27+
* @param file The file path
28+
* @param height The wanted height
29+
diff --git a/source/helper.c b/source/helper.c
30+
index 53f366bf..0bf417c6 100644
31+
--- a/source/helper.c
32+
+++ b/source/helper.c
33+
@@ -72,7 +72,8 @@ void cmd_set_arguments(int argc, char **argv) {
34+
stored_argv = argv;
35+
}
36+
37+
-int helper_parse_setup(char *string, char ***output, int *length, ...) {
38+
+static int helper_parse_setup_v(char *string, char ***output, int *length,
39+
+ va_list ap) {
40+
GError *error = NULL;
41+
GHashTable *h;
42+
h = g_hash_table_new(g_str_hash, g_str_equal);
43+
@@ -80,8 +81,6 @@ int helper_parse_setup(char *string, char ***output, int *length, ...) {
44+
g_hash_table_insert(h, "{terminal}", config.terminal_emulator);
45+
g_hash_table_insert(h, "{ssh-client}", config.ssh_client);
46+
// Add list from variable arguments.
47+
- va_list ap;
48+
- va_start(ap, length);
49+
while (1) {
50+
char *key = va_arg(ap, char *);
51+
if (key == (char *)0) {
52+
@@ -93,7 +92,6 @@ int helper_parse_setup(char *string, char ***output, int *length, ...) {
53+
}
54+
g_hash_table_insert(h, key, value);
55+
}
56+
- va_end(ap);
57+
58+
char *res = helper_string_replace_if_exists_v(string, h);
59+
// Destroy key-value storage.
60+
@@ -115,6 +113,13 @@ int helper_parse_setup(char *string, char ***output, int *length, ...) {
61+
}
62+
return FALSE;
63+
}
64+
+int helper_parse_setup(char *string, char ***output, int *length, ...) {
65+
+ va_list ap;
66+
+ va_start(ap, length);
67+
+ int retv = helper_parse_setup_v(string, output, length, ap);
68+
+ va_end(ap);
69+
+ return retv;
70+
+}
71+
72+
void helper_tokenize_free(rofi_int_matcher **tokens) {
73+
for (size_t i = 0; tokens && tokens[i]; i++) {
74+
@@ -1027,15 +1032,21 @@ gboolean helper_execute(const char *wd, char **args, const char *error_precmd,
75+
gboolean helper_execute_command(const char *wd, const char *cmd,
76+
gboolean run_in_term,
77+
RofiHelperExecuteContext *context) {
78+
+ return helper_execute_command_full(wd, cmd, run_in_term, context, "{cmd}",
79+
+ cmd, (char *)0);
80+
+}
81+
+
82+
+static gboolean helper_execute_command_full_v(const char *wd, const char *cmd,
83+
+ gboolean run_in_term,
84+
+ RofiHelperExecuteContext *context,
85+
+ va_list ap) {
86+
char **args = NULL;
87+
int argc = 0;
88+
89+
if (run_in_term) {
90+
- helper_parse_setup(config.run_shell_command, &args, &argc, "{cmd}", cmd,
91+
- (char *)0);
92+
+ helper_parse_setup_v(config.run_shell_command, &args, &argc, ap);
93+
} else {
94+
- helper_parse_setup(config.run_command, &args, &argc, "{cmd}", cmd,
95+
- (char *)0);
96+
+ helper_parse_setup_v(config.run_command, &args, &argc, ap);
97+
}
98+
99+
if (args == NULL) {
100+
@@ -1063,10 +1074,19 @@ gboolean helper_execute_command(const char *wd, const char *cmd,
101+
102+
return helper_execute(wd, args, "", cmd, context);
103+
}
104+
+gboolean helper_execute_command_full(const char *wd, const char *cmd,
105+
+ gboolean run_in_term,
106+
+ RofiHelperExecuteContext *context, ...) {
107+
+ va_list ap;
108+
+ va_start(ap, context);
109+
+ gboolean retv =
110+
+ helper_execute_command_full_v(wd, cmd, run_in_term, context, ap);
111+
+ va_end(ap);
112+
+ return retv;
113+
+}
114+
115+
char *helper_get_theme_path(const char *file, const char **ext,
116+
const char *parent_file) {
117+
-
118+
char *filename = rofi_expand_path(file);
119+
g_debug("Opening theme, testing: %s\n", filename);
120+
if (g_path_is_absolute(filename)) {
121+
diff --git a/source/modes/drun.c b/source/modes/drun.c
122+
index c18d8f95..bdfebfb9 100644
123+
--- a/source/modes/drun.c
124+
+++ b/source/modes/drun.c
125+
@@ -402,7 +402,10 @@ static void exec_cmd_entry(DRunModeEntry *e, const char *path) {
126+
// terminal.
127+
gboolean terminal =
128+
g_key_file_get_boolean(e->key_file, e->action, "Terminal", NULL);
129+
- if (helper_execute_command(exec_path, fp, terminal, sn ? &context : NULL)) {
130+
+ if (helper_execute_command_full(exec_path, fp, terminal, sn ? &context : NULL,
131+
+ "{cmd}", fp, "{desktop_file_path}", e->path,
132+
+ "{app_id}", e->app_id, "{desktop_id}",
133+
+ e->desktop_id, (char *)0)) {
134+
char *drun_cach_path = g_build_filename(cache_dir, DRUN_CACHE_FILE, NULL);
135+
// Store it based on the unique identifiers (desktop_id).
136+
history_set(drun_cach_path, e->desktop_id);

0 commit comments

Comments
 (0)