Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » Stuck with TrayIcon in Linux....
Stuck with TrayIcon in Linux.... [message #7556] Sat, 06 January 2007 11:59 Go to next message
mirek is currently offline  mirek
Messages: 13975
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
Re: Stuck with TrayIcon in Linux.... [message #7586 is a reply to message #7556] Sun, 07 January 2007 23:44 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
OK, thanks to Bas, solved... (solution is weird, but works...)
Re: Stuck with TrayIcon in Linux.... [message #7587 is a reply to message #7586] Mon, 08 January 2007 11:18 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Update: Still stuck Smile Bas's suggestion solved some cases, but not all.

Mirek
Re: Stuck with TrayIcon in Linux.... [message #23743 is a reply to message #7587] Wed, 18 November 2009 22:09 Go to previous message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

Hello All,

Method TrayIcon::Info do not show message for Linux.

For win32 work fine!

I have Ubuntu 9.10

Can anybody help me?
Previous Topic: .t / MSC / CJK windows possible solution
Next Topic: .t / MSC / CJK - commited
Goto Forum:
  


Current Time: Sat Apr 27 20:12:51 CEST 2024

Total time taken to generate the page: 0.04528 seconds