Skip to content

Commit

Permalink
On the fly config files reloading
Browse files Browse the repository at this point in the history
  • Loading branch information
laynor committed Jan 28, 2011
1 parent e8ef28a commit eb77fe3
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 53 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@
\#*#
*~
/trayion/trayion
/trayion.org
34 changes: 18 additions & 16 deletions README
Expand Up @@ -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 <trayion process pid>
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 <trayion process pid>
in a shell.

License/Copyright Information
==============================
Expand Down
2 changes: 1 addition & 1 deletion trayion/Makefile
Expand Up @@ -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}
Expand Down
45 changes: 45 additions & 0 deletions trayion/configuration_files.c
@@ -0,0 +1,45 @@
#include "configuration_files.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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);
}
12 changes: 12 additions & 0 deletions 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_ */
34 changes: 3 additions & 31 deletions trayion/main.c
Expand Up @@ -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();
Expand All @@ -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);

Expand All @@ -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");
Expand Down
1 change: 1 addition & 0 deletions trayion/sorted_classes.h
@@ -1,6 +1,7 @@
#ifndef SORTED_CLASSES_H
#define SORTED_CLASSES_H

#include <X11/Xlib.h>
#include "list.h"

extern struct list_head sorted_classes_list;
Expand Down
19 changes: 17 additions & 2 deletions trayion/systray.c
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions trayion/systray.h
Expand Up @@ -14,6 +14,7 @@
#ifndef WMSYSTRAY_SYSTRAY_H
#define WMSYSTRAY_SYSTRAY_H

#include <X11/Xlib.h>
#include <xembed.h>
#include "list.h"

Expand Down Expand Up @@ -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
14 changes: 11 additions & 3 deletions trayion/ui.c
Expand Up @@ -25,6 +25,7 @@
#include "systray.h"
#include "ui.h"
#include "hidden_list.h"
#include "configuration_files.h"


Display *main_disp;
Expand Down Expand Up @@ -329,6 +330,7 @@ void print_item_info(const char* fname)
fclose(fptr);
}


/*
* wmsystray_handle_signal
*
Expand All @@ -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:
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit eb77fe3

Please sign in to comment.