Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extending Tray [$500 awarded] #1874

Closed
saneef opened this issue May 17, 2014 · 12 comments
Closed

Extending Tray [$500 awarded] #1874

saneef opened this issue May 17, 2014 · 12 comments
Assignees
Labels

Comments

@saneef
Copy link

saneef commented May 17, 2014

I'm just starting out with node-webkit.

Is it possible to extend the Tray to have an view inside it?
63ff50f8-8a39-47e4-9968-1b557ac95c29
I'm trying to have a small view inside Taskbar Menu. Any small pointers is much appreciated.

The $500 bounty on this issue has been claimed at Bountysource.

@sindresorhus
Copy link

👍

@FWeinb
Copy link
Contributor

FWeinb commented May 17, 2014

I made click events work with this PR. The things left to do are:

  • API for getting the position of the tray icon.
  • support for transparent frames to create a non rectangle overlay (PR)

@mrfabbri
Copy link
Member

I'm looking into this and I found out there is no reliable way to get general access to the view associated with the tray status icon across all platforms (and even across different versions of the same platform); also the tray icon could be hidden (like on Windows where tray icons often are placed in an extended area) so in that case a Tray.x getter wouldn't make much sense.

What I think instead is a viable solution (and also makes sense usage wise) is to have x and y coordinates of the tray icon inside the click event of the Tray item, e.g.:

var gui = require('nw.gui');

function showCustomTrayMenuAt(position) {
  ...
}

var tray = new gui.Tray({ icon:'path-to-icon.png' });
tray.on('click', function(pos) {
  // pos.x is x coordinate of the tray icon
  // pos.y is y coordinate of the tray icon
  showCustomTrayMenuAt(pos);
}

On Mac OS X we can find the position of the status item (as it is view associated with currentEvent during the click event) while on Aura (Windows and Linux) we can only return the cursor position (which would be inside the bounding box of the status icon but with slight differences depending on where effectively the user clicked).

/cc @rogerwang @tommoor

mrfabbri added a commit to mrfabbri/node-webkit that referenced this issue Dec 14, 2014
- Add a parameter to the `click` event of the  `Tray` API object containing the
coordinates of the tray icon/mouse pointer.
The parameter has `x` and `y` fields for the coordinates.
On Mac OS X the coordinates always refer to the position (lower left corner) of
the tray item (NSStatusItem).
On Aura (Linux, Windows) the coordinates refer to the cursor position (which
would be inside the bounding box of the status icon but with slight differences
depending on where effectively the user clicked).

Usage example:

    tray.on('click', function(pos) {
      // pos.x is x coordinate of the tray icon
      // pos.y is y coordinate of the tray icon
      showCustomTrayMenuAt(pos);
    }

FIX nwjs#1874
mrfabbri added a commit to mrfabbri/node-webkit that referenced this issue Dec 14, 2014
- Add a manual test and an example usage (tray only application with a custom
tray menu) of the position parameter in `Tray` `click` event as discussed in
nwjs#1874
mrfabbri added a commit to mrfabbri/node-webkit that referenced this issue Dec 14, 2014
- Add a manual test and an example usage (tray only application with a custom
tray menu) of the position parameter in `Tray` `click` event as discussed in
nwjs#1874
@FWeinb
Copy link
Contributor

FWeinb commented Dec 16, 2014

I made a little Proof Of Concept:
node-tray
You can download it here

So it is finally possible to do this with node-webkit 0.11.3

@tommoor
Copy link

tommoor commented Dec 17, 2014

@FWeinb very nice, this will be helpful for folks 😄

@mrfabbri
Copy link
Member

@FWeinb neat! This could definitely go into a gist and be referenced from docs; also the templating of icons on dark menus is nice :-)

/mf

On 17 Dec 2014, at 00:01, FWeinb notifications@github.com wrote:

I made a little Proof Of Concept:

You can download it here

So it is finally possible to to this with node-webkit 0.11.3


Reply to this email directly or view it on GitHub.

@FWeinb
Copy link
Contributor

FWeinb commented Dec 17, 2014

@mrfabbri Thanks!
There is still an issue, the tray window is always rendered in low-res even on a hi-dpi display. I don't now maybe the Window.open command can't create hi-dpi views?

@tommoor
Copy link

tommoor commented Dec 17, 2014

It's rendered hi res here, although in your demo there is a drop shadow filter which makes it look blurry. If I remove that it's crisp

On Wed, Dec 17, 2014 at 3:06 AM, FWeinb notifications@github.com wrote:

@mrfabbri Thanks!

There is still an issue, the tray window is always rendered in low-res even on a hi-dpi display. I don't now maybe the Window.open command can't create hi-dpi views?

Reply to this email directly or view it on GitHub:
#1874 (comment)

@rogerwang rogerwang changed the title Extending Tray [$500] Extending Tray Dec 24, 2014
@rogerwang rogerwang changed the title Extending Tray Extending Tray [$500 awarded] Feb 21, 2015
@lassse
Copy link

lassse commented Sep 1, 2015

@FWeinb Thanks, great example!

@raguay
Copy link

raguay commented Jun 14, 2016

This isn't working on the latest build (version 15). The line that tries to make use of the position data freezes the application. The above proof of concept is dead. At least, it isn't working for me on a Mac OS X system.

@rogerwang
Copy link
Member

CC @ghostoy

@garymoon
Copy link

There are several recent changes that break custom tray window apps (another example here: https://github.com/zcbenz/nw-sample-apps/tree/master/custom-tray-menu) including the deprecation of the toolbar property and the switch from return value to callback in Window.open. However, after accounting for these changes, it does seem that the Tray object's click event does not provide any arguments in the latest build on OS X. I've decided against using this functionality myself for now, but would be happy to test a fix if desired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants