Completed refresh-execp
This commit is contained in:
@@ -683,6 +683,14 @@ void add_entry(char *key, char *value)
|
||||
/* Execp */
|
||||
else if (strcmp(key, "execp") == 0) {
|
||||
panel_config.execp_list = g_list_append(panel_config.execp_list, create_execp());
|
||||
} else if (strcmp(key, "execp_name") == 0) {
|
||||
Execp *execp = get_or_create_last_execp();
|
||||
execp->backend->name[0] = 0;
|
||||
if (strlen(value) > sizeof(execp->backend->name) - 1)
|
||||
fprintf(stderr, RED "tint2: execp_name cannot be more than %ld bytes: '%s'" RESET "\n",
|
||||
sizeof(execp->backend->name) - 1, value);
|
||||
else if (strlen(value) > 0)
|
||||
snprintf(execp->backend->name, sizeof(execp->backend->name), value);
|
||||
} else if (strcmp(key, "execp_command") == 0) {
|
||||
Execp *execp = get_or_create_last_execp();
|
||||
free_and_null(execp->backend->command);
|
||||
|
||||
@@ -20,6 +20,7 @@ extern bool debug_executors;
|
||||
|
||||
typedef struct ExecpBackend {
|
||||
// Config:
|
||||
char name[21];
|
||||
// Command to execute at a specified interval
|
||||
char *command;
|
||||
// Interval in seconds
|
||||
@@ -154,4 +155,6 @@ void execp_default_font_changed();
|
||||
|
||||
void handle_execp_events();
|
||||
|
||||
void execp_force_update(Execp *execp);
|
||||
|
||||
#endif // EXECPLUGIN_H
|
||||
|
||||
10
src/main.c
10
src/main.c
@@ -32,7 +32,6 @@
|
||||
#include <X11/extensions/Xdamage.h>
|
||||
#include <Imlib2.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
#include <time.h>
|
||||
@@ -545,6 +544,15 @@ void handle_x_event(XEvent *e)
|
||||
handle_dnd_position(&e->xclient);
|
||||
} else if (e->xclient.message_type == server.atom.XdndDrop) {
|
||||
handle_dnd_drop(&e->xclient);
|
||||
} else if (e->xclient.message_type == server.atom.TINT2_REFRESH_EXECP &&
|
||||
e->xclient.format == 8) {
|
||||
char name[sizeof(e->xclient.data.b) + 1] = {};
|
||||
memcpy(name, e->xclient.data.b, sizeof(e->xclient.data.b));
|
||||
for (GList *l = panel_config.execp_list; l; l = l->next) {
|
||||
Execp *execp = (Execp *)l->data;
|
||||
if (strncmp(name, execp->backend->name, sizeof(execp->backend->name) - 1) == 0)
|
||||
execp_force_update(execp);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
ifeq ($(PREFIX),)
|
||||
PREFIX := /usr/local
|
||||
endif
|
||||
|
||||
tint2-send: tint2-send.c
|
||||
$(CC) tint2-send.c -lX11 -o tint2-send
|
||||
|
||||
install: tint2-send
|
||||
install -m 755 tint2-send $(DESTDIR)/$(PREFIX)/bin/
|
||||
|
||||
clean:
|
||||
rm -f tint2-send
|
||||
@@ -45,8 +45,8 @@ int is_tint2(Window window)
|
||||
XWindowAttributes attr = {};
|
||||
if (!XGetWindowAttributes(display, window, &attr))
|
||||
return 0;
|
||||
if (attr.map_state != IsViewable)
|
||||
return 0;
|
||||
// if (attr.map_state != IsViewable)
|
||||
// return 0;
|
||||
|
||||
char *wm_class = get_property(window, XA_STRING, "WM_NAME");
|
||||
if (!wm_class) {
|
||||
@@ -60,11 +60,10 @@ int is_tint2(Window window)
|
||||
return class_match;
|
||||
}
|
||||
|
||||
void handle_tint2_window(Window window, void *arg)
|
||||
void handle_tint2_window(Window window, char *action, char **args)
|
||||
{
|
||||
if (!is_tint2(window))
|
||||
return;
|
||||
char *action = (char *)arg;
|
||||
if (strcmp(action, "show") == 0) {
|
||||
fprintf(stderr, "Showing tint2 window: %lx\n", window);
|
||||
XEvent event = {};
|
||||
@@ -85,16 +84,40 @@ void handle_tint2_window(Window window, void *arg)
|
||||
event.xcrossing.same_screen = True;
|
||||
XSendEvent(display, window, False, 0, &event);
|
||||
XFlush(display);
|
||||
} else if (strcmp(action, "refresh-execp") == 0) {
|
||||
XEvent event = {};
|
||||
char *name = args[0];
|
||||
if (!name) {
|
||||
fprintf(stderr, "Error: missing execp name\n");
|
||||
return;
|
||||
}
|
||||
if (!name[0]) {
|
||||
fprintf(stderr, "Error: empty execp name\n");
|
||||
return;
|
||||
}
|
||||
if (strlen(name) > sizeof(event.xclient.data.b)) {
|
||||
fprintf(stderr, "Error: execp name bigger than %ld bytes\n", sizeof(event.xclient.data.b));
|
||||
return;
|
||||
}
|
||||
fprintf(stderr, "Refreshing execp '%s' for window: %lx\n", name, window);
|
||||
event.xclient.type = ClientMessage;
|
||||
event.xclient.window = window;
|
||||
event.xclient.send_event = True;
|
||||
event.xclient.message_type = XInternAtom(display, "_TINT2_REFRESH_EXECP", False);
|
||||
event.xclient.format = 8;
|
||||
strncpy(event.xclient.data.b, name, sizeof(event.xclient.data.b));
|
||||
XSendEvent(display, window, False, 0, &event);
|
||||
XFlush(display);
|
||||
} else {
|
||||
fprintf(stderr, "Error: unknown action %s\n", action);
|
||||
}
|
||||
}
|
||||
|
||||
typedef void window_callback_t(Window window, void *arg);
|
||||
typedef void window_callback_t(Window window, char *action, char **args);
|
||||
|
||||
void walk_windows(Window node, window_callback_t *callback, void *arg)
|
||||
void walk_windows(Window node, window_callback_t *callback, char *action, char **args)
|
||||
{
|
||||
callback(node, arg);
|
||||
callback(node, action, args);
|
||||
Window root = 0;
|
||||
Window parent = 0;
|
||||
Window *children = 0;
|
||||
@@ -104,7 +127,7 @@ void walk_windows(Window node, window_callback_t *callback, void *arg)
|
||||
return;
|
||||
}
|
||||
for (unsigned int i = 0; i < nchildren; i++) {
|
||||
walk_windows(children[i], callback, arg);
|
||||
walk_windows(children[i], callback, action, args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,11 +141,12 @@ int main(int argc, char **argv)
|
||||
|
||||
argc--, argv++;
|
||||
if (!argc) {
|
||||
fprintf(stderr, "Usage: tint2-show [show|hide]\n");
|
||||
fprintf(stderr, "Usage: tint2-send [show|hide|refresh-execp]\n");
|
||||
exit(1);
|
||||
}
|
||||
char *action = argv[0];
|
||||
walk_windows(DefaultRootWindow(display), handle_tint2_window, action);
|
||||
char **args = argv + 1;
|
||||
walk_windows(DefaultRootWindow(display), handle_tint2_window, action, args);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -4271,6 +4271,23 @@ void create_execp(GtkWidget *notebook, int i)
|
||||
gtk_table_set_col_spacings(GTK_TABLE(table), COL_SPACING);
|
||||
row = 0, col = 2;
|
||||
|
||||
label = gtk_label_new(_("Name"));
|
||||
gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
|
||||
gtk_widget_show(label);
|
||||
gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, 0, 0, 0);
|
||||
col++;
|
||||
|
||||
executor->execp_name = gtk_entry_new();
|
||||
gtk_widget_show(executor->execp_name);
|
||||
gtk_entry_set_width_chars(GTK_ENTRY(executor->execp_name), 20);
|
||||
gtk_entry_set_max_length(GTK_ENTRY(executor->execp_name), 20);
|
||||
gtk_table_attach(GTK_TABLE(table), executor->execp_name, col, col + 1, row, row + 1, GTK_FILL, 0, 0, 0);
|
||||
col++;
|
||||
gtk_widget_set_tooltip_text(executor->execp_name,
|
||||
_("Specifies a name that can be used with `tint2-send refresh-execp` to re-execute "
|
||||
"the command."));
|
||||
|
||||
row++, col = 2;
|
||||
label = gtk_label_new(_("Command"));
|
||||
gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
|
||||
gtk_widget_show(label);
|
||||
|
||||
@@ -132,6 +132,7 @@ typedef struct Executor {
|
||||
GtkWidget *container;
|
||||
GtkWidget *page_execp;
|
||||
GtkWidget *page_label;
|
||||
GtkWidget *execp_name;
|
||||
GtkWidget *execp_command, *execp_interval, *execp_has_icon, *execp_cache_icon, *execp_show_tooltip;
|
||||
GtkWidget *execp_continuous, *execp_markup, *execp_tooltip, *execp_monitor;
|
||||
GtkWidget *execp_left_command, *execp_right_command;
|
||||
|
||||
@@ -857,6 +857,7 @@ void config_write_execp(FILE *fp)
|
||||
Executor *executor = &g_array_index(executors, Executor, i);
|
||||
|
||||
fprintf(fp, "execp = new\n");
|
||||
fprintf(fp, "execp_name = %s\n", gtk_entry_get_text(GTK_ENTRY(executor->execp_name)));
|
||||
fprintf(fp, "execp_command = %s\n", gtk_entry_get_text(GTK_ENTRY(executor->execp_command)));
|
||||
fprintf(fp, "execp_interval = %d\n", (int)gtk_spin_button_get_value(GTK_SPIN_BUTTON(executor->execp_interval)));
|
||||
fprintf(fp,
|
||||
@@ -1962,6 +1963,8 @@ void add_entry(char *key, char *value)
|
||||
/* Executor */
|
||||
else if (strcmp(key, "execp") == 0) {
|
||||
execp_create_new();
|
||||
} else if (strcmp(key, "execp_name") == 0) {
|
||||
gtk_entry_set_text(GTK_ENTRY(execp_get_last()->execp_name), value);
|
||||
} else if (strcmp(key, "execp_command") == 0) {
|
||||
gtk_entry_set_text(GTK_ENTRY(execp_get_last()->execp_command), value);
|
||||
} else if (strcmp(key, "execp_interval") == 0) {
|
||||
|
||||
@@ -122,6 +122,9 @@ void server_init_atoms()
|
||||
server.atom.XdndActionCopy = XInternAtom(server.display, "XdndActionCopy", False);
|
||||
server.atom.XdndFinished = XInternAtom(server.display, "XdndFinished", False);
|
||||
server.atom.TARGETS = XInternAtom(server.display, "TARGETS", False);
|
||||
|
||||
// tint2 atoms
|
||||
server.atom.TINT2_REFRESH_EXECP = XInternAtom(server.display, "_TINT2_REFRESH_EXECP", False);
|
||||
}
|
||||
|
||||
const char *GetAtomName(Display *disp, Atom a)
|
||||
|
||||
@@ -91,6 +91,7 @@ typedef struct Global_atom {
|
||||
Atom XdndActionCopy;
|
||||
Atom XdndFinished;
|
||||
Atom TARGETS;
|
||||
Atom TINT2_REFRESH_EXECP;
|
||||
} Global_atom;
|
||||
|
||||
typedef struct Property {
|
||||
|
||||
Reference in New Issue
Block a user