diff --git a/.gitignore b/.gitignore index 9e7464c..6848f2b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ \#*# *~ /trayion/trayion +/trayion.org diff --git a/README b/README index aba25de..15ca041 100644 --- a/README +++ b/README @@ -75,24 +75,26 @@ to: Now you can control the icon size using the trayion '-iconsize' command line argument. The default size is 14 pixels. -Icon Sorting +Config Files ============ -You can define icon sorting creating the file - ~/.trayion/trayion-sorted-iconlist.txt -issuing the command +Icon Sorting: ~/.trayion/trayion-sorted-iconlist.txt +Icon Hiding: ~/.trayion/trayion-hidden-iconlist.txt + +An initial version of the file can be created issuing the command $ kill -s USR1 -a file containing the current ordering will be created in - /tmp/trayion-sorted-iconlist.txt -Just reorder the lines to your liking and copy that file to - ~/.trayion/ -and restart trayion. - -Icon Hiding -=========== -Follow the same process for the Icon Sorting, -but move the file as - ~/.trayion/trayion-hidden-iconlist.txt -Specify all the icons you want it to hide. +in a shell. This will create a file + /tmp/trayion-icon-list.txt +You can copy the contents of the file in +~/.trayion/trayion-sorted-iconlist.txt +and +~/.trayion/trayion-hidden-iconlist.txt + +and then edit them, changing the ordering of the icons in the first +one, selecting which icons you want to be hidden in the second one. + +The configuration files can be reloaded on the fly issuing the command + $ kill -s USR2 +in a shell. License/Copyright Information ============================== diff --git a/trayion/Makefile b/trayion/Makefile index a3ef7f2..14909f6 100644 --- a/trayion/Makefile +++ b/trayion/Makefile @@ -4,7 +4,7 @@ CC = gcc CFLAGS = ${X11CFLAGS} -DTRACE_LEVEL=${TRACE_LEVEL} -I../xembed -Wall -g LDFLAGS = ${X11LDFLAGS} -OBJS = main.o ui.o systray.o list_sort.o sorted_classes.o hidden_list.o string_list.o +OBJS = main.o ui.o systray.o list_sort.o sorted_classes.o hidden_list.o string_list.o configuration_files.o XEMBED_OBJS = ../xembed/xembed.o trayion: ${OBJS} ${XEMBED_OBJS} diff --git a/trayion/configuration_files.c b/trayion/configuration_files.c new file mode 100644 index 0000000..e4a0e5a --- /dev/null +++ b/trayion/configuration_files.c @@ -0,0 +1,45 @@ +#include "configuration_files.h" +#include +#include +#include +#include "systray.h" +#include "string_list.h" +#include "sorted_classes.h" +#include "hidden_list.h" + +void reload_config_files() +{ + static int initialized=0; + load_sorting_config(); + load_hiding_config(); + if (initialized){ + recalc_window_ranks(); + sort_systray_list(); + } + initialized = 1; +} +char* home_relative_path(char *rpath) +{ + char *homedir; + char *apath; + homedir = getenv("HOME"); + apath = malloc((strlen(rpath) + strlen(homedir) + 2) * sizeof(char)); + apath[0]='\0'; + strcpy(apath, homedir); + strcat(apath, "/"); + strcat(apath, rpath); + return apath; +} + +void load_sorting_config() +{ + char *path = home_relative_path(".trayion/trayion-sorted-iconlist.txt"); + load_sorted_classes_list(path); + free(path); +} +void load_hiding_config() +{ + char *path = home_relative_path(".trayion/trayion-hidden-iconlist.txt"); + load_hidden_list(path); + free(path); +} diff --git a/trayion/configuration_files.h b/trayion/configuration_files.h new file mode 100644 index 0000000..735dc81 --- /dev/null +++ b/trayion/configuration_files.h @@ -0,0 +1,12 @@ +#ifndef _CONFIGURATION_FILES_H_ +#define _CONFIGURATION_FILES_H_ + + + +char* home_relative_path(char *rpath); +void load_sorting_config(); +void load_hiding_config(); +void reload_config_files(); + + +#endif /* _CONFIGURATION_FILES_H_ */ diff --git a/trayion/main.c b/trayion/main.c index 90ab1f2..fcc62dc 100644 --- a/trayion/main.c +++ b/trayion/main.c @@ -21,9 +21,8 @@ #include "ui.h" #include "systray.h" -#include "sorted_classes.h" #include "version.h" -#include "hidden_list.h" +#include "configuration_files.h" void usage(); @@ -33,38 +32,10 @@ static int error_handler(Display *d, XErrorEvent *e) { return 0; } -char* home_relative_path(char *rpath) -{ - char *homedir; - char *apath; - homedir = getenv("HOME"); - apath = malloc((strlen(rpath) + strlen(homedir) + 2) * sizeof(char)); - apath[0]='\0'; - strcpy(apath, homedir); - strcat(apath, "/"); - strcat(apath, rpath); - return apath; -} - -void load_sorting_config() -{ - char *path = home_relative_path(".trayion/trayion-sorted-iconlist.txt"); - load_sorted_classes_list(path); - free(path); -} -void load_hiding_config() -{ - char *path = home_relative_path(".trayion/trayion-hidden-iconlist.txt"); - load_hidden_list(path); - free(path); -} - int main(int argc, char **argv) { struct sigaction act, oldact; - load_sorting_config(); - load_hiding_config(); - print_sorted_classes_list(); + reload_config_files(); XSetErrorHandler(error_handler); @@ -74,6 +45,7 @@ int main(int argc, char **argv) { sigaction (SIGTERM, &act, &oldact); sigaction (SIGINT, &act, &oldact); sigaction (SIGUSR1, &act, &oldact); + sigaction (SIGUSR2, &act, &oldact); if (init_ui ("wmsystray", argc, argv) != 0) { printf ("Could not connect to X server!\n"); diff --git a/trayion/sorted_classes.h b/trayion/sorted_classes.h index 6c0aea9..88d675b 100644 --- a/trayion/sorted_classes.h +++ b/trayion/sorted_classes.h @@ -1,6 +1,7 @@ #ifndef SORTED_CLASSES_H #define SORTED_CLASSES_H +#include #include "list.h" extern struct list_head sorted_classes_list; diff --git a/trayion/systray.c b/trayion/systray.c index a941acd..9f161b5 100644 --- a/trayion/systray.c +++ b/trayion/systray.c @@ -303,6 +303,18 @@ struct systray_item *systray_item_at_coords (int x, int y) { return ret; } +void recalc_window_ranks() +{ + struct list_head *l; + struct systray_item *item; + + list_for_each (l, &systray_list) { + item = list_entry (l, struct systray_item, systray_list); + item->rank = window_rank(item->window_id); + if (is_hidden(item->window_id)) + item->rank = - item->rank; + } +} int systray_list_length() { @@ -399,7 +411,10 @@ int compare_items(struct list_head *a, struct list_head *b) it2 = list_entry(b, struct systray_item, systray_list); return it1->rank - it2->rank; } - +void sort_systray_list() +{ + list_sort(&systray_list, compare_items); +} /* * handle_dock_request * @@ -486,7 +501,7 @@ int handle_dock_request (Window embed_wind) { status = xembed_modality_off (main_disp, embed_wind); XSync (main_disp, False); */ - list_sort(&systray_list, compare_items); + sort_systray_list(); repaint_systray(item->window_id); TRACE((stderr, "LEAVING: handle_dock_request\n")); return 0; diff --git a/trayion/systray.h b/trayion/systray.h index 07a9e7f..8bc4d15 100644 --- a/trayion/systray.h +++ b/trayion/systray.h @@ -14,6 +14,7 @@ #ifndef WMSYSTRAY_SYSTRAY_H #define WMSYSTRAY_SYSTRAY_H +#include #include #include "list.h" @@ -46,5 +47,7 @@ int handle_systray_event(XEvent *ev); void repaint_systray(int new_icon); struct systray_item *find_systray_item(Window id); int systray_property_update(struct systray_item *item); +void recalc_window_ranks(); +void sort_systray_list(); #endif diff --git a/trayion/ui.c b/trayion/ui.c index 6473696..4497a01 100644 --- a/trayion/ui.c +++ b/trayion/ui.c @@ -25,6 +25,7 @@ #include "systray.h" #include "ui.h" #include "hidden_list.h" +#include "configuration_files.h" Display *main_disp; @@ -329,6 +330,7 @@ void print_item_info(const char* fname) fclose(fptr); } + /* * wmsystray_handle_signal * @@ -337,7 +339,12 @@ void print_item_info(const char* fname) void wmsystray_handle_signal (int signum) { switch (signum) { case SIGUSR1: - print_item_info("/tmp/trayion-sorted-iconlist.txt"); + print_item_info("/tmp/trayion-icon-list.txt"); + break; + case SIGUSR2: + reload_config_files(); + repaint_systray(0); + printf("reloading config files.\n"); break; case SIGINT: case SIGTERM: @@ -370,12 +377,13 @@ void handle_leave_event() void check_pointer_inside_tray_kludge() { Window root_return, child_return; - int pointer_root_x, pointer_root_y, window_x, window_y, pointer_mask; + int pointer_root_x, pointer_root_y, window_x, window_y; + unsigned int pointer_mask; static int iteration=0; XWindowAttributes attrib; iteration++; if (iteration%100==0) { - XQueryPointer(main_disp, icon_wind, &root_return, &child_return, + XQueryPointer(main_disp, icon_wind, &root_return, &child_return, &pointer_root_x, &pointer_root_y, &window_x, &window_y, &pointer_mask); XGetWindowAttributes(main_disp, main_wind, &attrib);