Add -n flag to witray to opt out of replacing existing systray.

This commit is contained in:
Kris Maglione 2011-09-19 20:24:32 -04:00
parent 67cb8d196e
commit 7eb2bef1bd
8 changed files with 40 additions and 20 deletions

View File

@ -105,7 +105,10 @@ class Events():
if ary is not None: if ary is not None:
action(*ary) action(*ary)
except Exception, e: except Exception, e:
traceback.print_exc(sys.stderr) try:
traceback.print_exc(sys.stderr)
except:
pass
def loop(self): def loop(self):
""" """

View File

@ -278,6 +278,7 @@ class File(object):
if offset is None: if offset is None:
self.offset = offs self.offset = offs
return ''.join(res) return ''.join(res)
def readlines(self): def readlines(self):
last = None last = None
while True: while True:
@ -293,6 +294,7 @@ class File(object):
last = lines[-1] last = lines[-1]
if last: if last:
yield last yield last
def write(self, data, offset=None): def write(self, data, offset=None):
if offset is None: if offset is None:
offset = self.offset offset = self.offset

View File

@ -6,6 +6,7 @@
#include <ixp.h> #include <ixp.h>
#include <stuff/x.h> #include <stuff/x.h>
#include <stuff/util.h> #include <stuff/util.h>
#include "selection.h"
#ifndef EXTERN #ifndef EXTERN
# define EXTERN extern # define EXTERN extern
@ -25,7 +26,6 @@ enum TrayOpcodes {
typedef struct Client Client; typedef struct Client Client;
typedef struct Message Message; typedef struct Message Message;
typedef struct Selection Selection;
typedef struct XEmbed XEmbed; typedef struct XEmbed XEmbed;
struct Client { struct Client {
@ -43,18 +43,6 @@ struct Message {
IxpMsg msg; IxpMsg msg;
}; };
struct Selection {
Window* owner;
char* selection;
ulong time_start;
ulong time_end;
void (*cleanup)(Selection*);
void (*message)(Selection*, XClientMessageEvent*);
void (*request)(Selection*, XSelectionRequestEvent*);
long timer;
ulong oldowner;
};
struct XEmbed { struct XEmbed {
Window* w; Window* w;
Window* owner; Window* owner;

View File

@ -11,9 +11,6 @@ int main(int, char*[]);
void message(Selection*, XClientMessageEvent*); void message(Selection*, XClientMessageEvent*);
void message_cancel(Client*, long); void message_cancel(Client*, long);
void restrut(Window*, int); void restrut(Window*, int);
Selection* selection_create(char*, ulong, void (*)(Selection*, XSelectionRequestEvent*), void (*)(Selection*));
Selection* selection_manage(char*, ulong, void (*)(Selection*, XClientMessageEvent*), void (*)(Selection*));
void selection_release(Selection*);
void tray_init(void); void tray_init(void);
void tray_resize(Rectangle); void tray_resize(Rectangle);
void tray_update(void); void tray_update(void);

View File

@ -18,7 +18,7 @@ static struct sigaction sa;
static void static void
usage(void) { usage(void) {
fprint(2, "usage: %s [-a <address>] [-NESW] [-HV] [-p <padding>] [-s <iconsize>] [-t tags]\n" fprint(2, "usage: %s [-a <address>] [-NESW] [-HVn] [-p <padding>] [-s <iconsize>] [-t tags]\n"
" %s -v\n", argv0, argv0); " %s -v\n", argv0, argv0);
exit(1); exit(1);
} }
@ -112,6 +112,7 @@ ErrorCode ignored_xerrors[] = {
int int
main(int argc, char *argv[]) { main(int argc, char *argv[]) {
static char* address; static char* address;
bool steal;
program_args = argv; program_args = argv;
@ -119,6 +120,7 @@ main(int argc, char *argv[]) {
fmtinstall('r', errfmt); fmtinstall('r', errfmt);
fmtinstall('E', fmtevent); fmtinstall('E', fmtevent);
steal = true;
tray.orientation = OHorizontal; tray.orientation = OHorizontal;
tray.tags = "/./"; tray.tags = "/./";
tray.padding = 1; tray.padding = 1;
@ -142,6 +144,9 @@ main(int argc, char *argv[]) {
case 'V': case 'V':
tray.orientation = OVertical; tray.orientation = OVertical;
break; break;
case 'n':
steal = false;
break;
case 'p': case 'p':
if(!getulong(EARGF(usage()), &tray.padding)) if(!getulong(EARGF(usage()), &tray.padding))
usage(); usage();
@ -179,7 +184,7 @@ main(int argc, char *argv[]) {
event_updatextime(); event_updatextime();
tray.selection = selection_manage(sxprint(Net("SYSTEM_TRAY_S%d"), scr.screen), tray.selection = selection_manage(sxprint(Net("SYSTEM_TRAY_S%d"), scr.screen),
event_xtime, message, cleanup); event_xtime, message, cleanup, steal);
if(tray.selection == nil) if(tray.selection == nil)
fatal("Another system tray is already running."); fatal("Another system tray is already running.");
if(tray.selection->oldowner) if(tray.selection->oldowner)

View File

@ -70,12 +70,16 @@ timeout(long timer, void *v) {
Selection* Selection*
selection_manage(char *selection, ulong time, selection_manage(char *selection, ulong time,
void (*message)(Selection*, XClientMessageEvent*), void (*message)(Selection*, XClientMessageEvent*),
void (*cleanup)(Selection*)) { void (*cleanup)(Selection*),
bool steal) {
Selection *s; Selection *s;
Window *w; Window *w;
XWindow old; XWindow old;
if((old = XGetSelectionOwner(display, xatom(selection)))) { if((old = XGetSelectionOwner(display, xatom(selection)))) {
if (!steal)
return nil;
w = emallocz(sizeof *w); w = emallocz(sizeof *w);
w->type = WWindow; w->type = WWindow;
w->xid = old; w->xid = old;

18
cmd/tray/selection.h Normal file
View File

@ -0,0 +1,18 @@
typedef struct Selection Selection;
struct Selection {
Window* owner;
char* selection;
ulong time_start;
ulong time_end;
void (*cleanup)(Selection*);
void (*message)(Selection*, XClientMessageEvent*);
void (*request)(Selection*, XSelectionRequestEvent*);
long timer;
ulong oldowner;
};
Selection* selection_create(char*, ulong, void (*)(Selection*, XSelectionRequestEvent*), void (*)(Selection*));
Selection* selection_manage(char*, ulong, void (*)(Selection*, XClientMessageEvent*), void (*)(Selection*), bool);
void selection_release(Selection*);

View File

@ -38,6 +38,9 @@ to configure, and generally Just Works.
Specifies whether icons are to be aligned horizontally or Specifies whether icons are to be aligned horizontally or
vertically, respectively. Also determines from which edge of vertically, respectively. Also determines from which edge of
the screen windows are shunted to make room for the tray. the screen windows are shunted to make room for the tray.
: -n
Only create a new tray if a previous tray manager is not
already running.
: -p <padding> : -p <padding>
Sets the padding between icons and around the edge of the Sets the padding between icons and around the edge of the
tray. In pixels. tray. In pixels.