Home » Developing U++ » U++ Developers corner » Stuck with TrayIcon in Linux....
Stuck with TrayIcon in Linux.... [message #7556] |
Sat, 06 January 2007 11:59  |
 |
mirek
Messages: 14255 Registered: November 2005
|
Ultimate Member |
|
|
...almost there:
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
NAMESPACE_UPP
Atom TraySelection()
{
return XAtom(Format("_NET_SYSTEM_TRAY_S%d", Xscreenno));
}
struct TrayIcon : TopWindow {
virtual bool HookProc(XEvent *event);
virtual void Paint(Draw& draw);
virtual void LeftDown(Point p, dword keyflags);
virtual void Layout();
void AddToTray();
Window traywin;
XSizeHints *size_hints;
TrayIcon();
~TrayIcon();
};
void TrayIcon::Layout()
{
DUMP(GetRect());
}
void TrayIcon::AddToTray()
{
traywin = XGetSelectionOwner(Xdisplay, TraySelection());
if(!traywin) return;
XSelectInput(Xdisplay, traywin, StructureNotifyMask);
XWindowAttributes attr;
XGetWindowAttributes(Xdisplay, Xroot, &attr);
XSelectInput(Xdisplay, Xroot, attr.your_event_mask | StructureNotifyMask);
size_hints->min_width = 22;
size_hints->min_height = 22;
size_hints->max_width = 22;
size_hints->max_height = 22;
size_hints->x = 0;
size_hints->y = 0;
size_hints->width = 22;
size_hints->height = 22;
size_hints->win_gravity = StaticGravity;
size_hints->flags = PMinSize|PMaxSize|PPosition|PSize|PWinGravity;
XSetWMNormalHints(Xdisplay, GetWindow(), size_hints);
bool x11trap = TrapX11Errors();
XEvent e;
Zero(e);
e.xclient.data.l[0] = CurrentTime;
e.xclient.data.l[2] = GetWindow();
e.xclient.window = traywin;
e.xclient.type = ClientMessage;
e.xclient.message_type = XAtom("_NET_SYSTEM_TRAY_OPCODE");
e.xclient.format = 32;
XSendEvent(Xdisplay, traywin, XFalse, 0, &e);
XSync(Xdisplay, XFalse);
UntrapX11Errors(x11trap);
}
bool TrayIcon::HookProc(XEvent *event)
{
XAnyEvent *e = (XAnyEvent *)event;
if(e->type == DestroyNotify && e->window == traywin) {
AddToTray();
return true;
}
if(e->type == ClientMessage && !traywin) {
XClientMessageEvent *cm = (XClientMessageEvent *)event;
if(cm->message_type == XAtom("MANAGER") && (Atom)cm->data.l[1] == TraySelection()) {
AddToTray();
return true;
}
}
return false;
}
void TrayIcon::Paint(Draw& w)
{
w.DrawRect(GetSize(), Cyan);
}
void TrayIcon::LeftDown(Point p, dword keyflags)
{
EndLoop();
}
TrayIcon::TrayIcon()
{
size_hints = XAllocSizeHints();
SetRect(0, 0, 24, 24);
ignoretakefocus = true;
Create(NULL, true, false);
if(top) popup = true;
WndShow(visible);
AddToTray();
}
TrayIcon::~TrayIcon()
{
XFree(size_hints);
}
END_UPP_NAMESPACE
GUI_APP_MAIN
{
TrayIcon icon;
Ctrl::EventLoop(&icon);
}
...however, tray icon created is only 1 pixel wide. Anybody has the idea why?
Mirek
|
|
|
|
|
|
Goto Forum:
Current Time: Mon Apr 28 01:03:33 CEST 2025
Total time taken to generate the page: 0.01003 seconds
|