1 /* -------------------------------
2  * vim:tabstop=4:shiftwidth=4
3  * tray.h
4  * Wed, 29 Sep 2004 23:10:02 +0700
5  * -------------------------------
6  * Common tray routines
7  * -------------------------------*/
8 
9 #ifndef _TRAY_H_
10 #define _TRAY_H_
11 
12 #include <X11/X.h>
13 #include <X11/Xlib.h>
14 #include <X11/Xutil.h>
15 
16 #include <limits.h>
17 
18 #include "config.h"
19 #include "common.h"
20 #include "icons.h"
21 #include "scrollbars.h"
22 #include "xembed.h"
23 
24 /* Tray opcode messages from System Tray Protocol Specification
25  * http:freedesktop.org/Standards/systemtray-spec/systemtray-spec-0.2.html */
26 #define SYSTEM_TRAY_REQUEST_DOCK    0
27 /* These two are unused */
28 #define SYSTEM_TRAY_BEGIN_MESSAGE   1
29 #define SYSTEM_TRAY_CANCEL_MESSAGE  2
30 /* Custom message: remote control */
31 #define STALONE_TRAY_REMOTE_CONTROL 0xFFFD
32 /* Custom message: request for status */
33 #define STALONE_TRAY_STATUS_REQUESTED 0xFFFE
34 /* Custom message: confirmation of embedding */
35 #define STALONE_TRAY_DOCK_CONFIRMED 0xFFFF
36 /* Name of tray selection atom */
37 #define	TRAY_SEL_ATOM "_NET_SYSTEM_TRAY_S"
38 /* Name of tray orientation atom*/
39 #define TRAY_ORIENTATION_ATOM "_NET_SYSTEM_TRAY_ORIENTATION"
40 /* Name of tray orientation atom*/
41 #define STALONETRAY_REMOTE_ATOM "STALONETRAY_REMOTE"
42 /* Values of tray orientation property */
43 #define _NET_SYSTEM_TRAY_ORIENTATION_HORZ 0
44 #define _NET_SYSTEM_TRAY_ORIENTATION_VERT 1
45 
46 /* Window decoration flags */
47 #define DECO_BORDER	(1 << 0)
48 #define DECO_TITLE (1 << 1)
49 #define DECO_NONE 0
50 #define DECO_ALL (DECO_BORDER | DECO_TITLE)
51 
52 /* WM struts flags */
53 #define WM_STRUT_NONE 0
54 #define WM_STRUT_LFT  1
55 #define WM_STRUT_RHT  2
56 #define WM_STRUT_TOP  3
57 #define WM_STRUT_BOT  4
58 #define WM_STRUT_AUTO 5
59 
60 /* Dockapp modes */
61 #define DOCKAPP_NONE 0
62 #define DOCKAPP_SIMPLE 1
63 #define DOCKAPP_WMAKER 2
64 
65 /* Kludge flags */
66 #define KLUDGE_FIX_WND_SIZE (1L << 1)
67 #define KLUDGE_FIX_WND_POS  (1L << 2)
68 #define KLUDGE_USE_ICONS_HINTS (1L << 3)
69 #define KLUDGE_FORCE_ICONS_SIZE (1L << 4)
70 
71 /* Remote click constants */
72 #define REMOTE_CLICK_BTN_DEFAULT Button1
73 #define REMOTE_CLICK_POS_DEFAULT INT_MAX
74 #define REMOTE_CLICK_CNT_DEFAULT 1
75 
76 /* Structure to hold all tray data */
77 struct TrayData {
78 	/* General */
79 	Window tray;							/* ID of tray window */
80 	Window hint_win;						/* ID of icon window */
81 	Display *dpy;							/* Display pointer */
82 	XSizeHints xsh;							/* Size & position of the tray window */
83 	XSizeHints root_wnd;					/* Size & position :) of the root window */
84 	Window old_selection_owner;				/* Old owner of tray selection */
85 	int terminated;							/* Exit flag */
86 	int is_active;							/* Is the tray active? */
87 	int is_reparented;						/* Was the tray reparented in smth like FvwmButtons ? */
88 	int kde_tray_old_mode;					/* Use legacy scheme to handle KDE icons via MapNotify */
89 
90 	/* Atoms */
91 	Atom xa_tray_selection;					/* Atom: _NET_SYSTEM_TRAY_SELECTION_S<creen number> */
92 	Atom xa_tray_opcode;					/* Atom: _NET_SYSTEM_TRAY_MESSAGE_OPCODE */
93 	Atom xa_tray_data;						/* Atom: _NET_SYSTEM_TRAY_MESSAGE_DATA */
94 	Atom xa_wm_protocols;					/* Atom: WM_PROTOCOLS */
95 	Atom xa_wm_delete_window;				/* Atom: WM_DELETE_WINDOW */
96 	Atom xa_net_wm_ping;					/* Atom: WM_PING */
97 	Atom xa_wm_take_focus;					/* Atom: WM_TAKE_FOCUS */
98 	Atom xa_kde_net_system_tray_windows;	/* Atom: _KDE_NET_SYSTEM_TRAY_WINDOWS */
99 	Atom xa_net_client_list;				/* Atom: _NET_CLIENT_LIST */
100 
101 	/* Background pixmap */
102 	Atom xa_xrootpmap_id;					/* Atom: _XROOTPMAP_ID */
103 	Atom xa_xsetroot_id;					/* Atom: _XSETROOT_ID */
104 	Pixmap bg_pmap;							/* Pixmap for tray background */
105 	struct Point bg_pmap_dims;              /* Background pixmap dimensions */
106 
107 	/* XEMBED data */
108 	struct XEMBEDData xembed_data;			/* XEMBED data */
109 
110 	/* Scrollbar data */
111 	struct ScrollbarsData scrollbars_data;
112 };
113 extern struct TrayData tray_data;
114 
115 /* Initialize all tray data structures */
116 void tray_init();
117 /* Create tray window */
118 void tray_create_window(int argc, char **argv);
119 /* Create phony tray window so that certain x11_ calls work */
120 void tray_create_phony_window();
121 /* Initialize tray selection atoms */
122 void tray_init_selection_atoms();
123 /* Acquire tray selection */
124 void tray_acquire_selection();
125 /* Show tray window */
126 void tray_show_window();
127 /* Refresh tray window */
128 void tray_refresh_window(int exposures);
129 /* Update tray background (and pixmap, if update_pixmap is true) */
130 int tray_update_bg(int update_pixmap);
131 /* Calculate tray window size given the size of icon area in pixels. */
132 int tray_calc_window_size(int base_width, int base_height, int *new_width, int *new_height);
133 /* Calculate size of icon area given the tray window size in pixels. */
134 int tray_calc_tray_area_size(int wnd_width, int wnd_height, int *base_width, int *base_height);
135 /* Update window struts (if enabled) */
136 int tray_update_window_strut();
137 /* Update tray window size and hints */
138 int tray_update_window_props();
139 /* Set tray window WM hints */
140 int tray_set_wm_hints();
141 
142 #endif
143