Create a non modal 'always on top' window like Firefox's PiP?

Talk about code development, features, specific bugs, enhancements, patches, and similar things.
Forum rules
Please keep everything here strictly on-topic.
This board is meant for Pale Moon source code development related subjects only like code snippets, patches, specific bugs, git, the repositories, etc.

This is not for tech support! Please do not post tech support questions in the "Development" board!
Please make sure not to use this board for support questions. Please post issues with specific websites, extensions, etc. in the relevant boards for those topics.

Please keep things on-topic as this forum will be used for reference for Pale Moon development. Expect topics that aren't relevant as such to be moved or deleted.
User avatar
moonbat
Knows the dark side
Knows the dark side
Posts: 4942
Joined: 2015-12-09, 15:45
Contact:

Create a non modal 'always on top' window like Firefox's PiP?

Unread post by moonbat » 2020-09-15, 07:18

I want to enhance PMPlayer so that the popup window it creates can be always on top even when you switch away from Pale Moon. Currently the only way is if your window manager supports always on top, so that's not an option for Windows users sans 3rd party software.

In Firefox, the pop up window stays on top even when you switch to a different application. How do they do it?

I use a regular XUL <window> (not <dialog>, for obvious reasons) that is opened using

Code: Select all

			window.open("chrome://pmplayer/content/pmpwindow.xul",
			            "pmplayerwindow", "chrome,width="+window.screen.width*PMPlayer.Common.globals.screensize/100+
			            ",height="+window.screen.height*PMPlayer.Common.globals.screensize/100+
			            ",resizable=yes,dialog,alwaysRaised,centerscreen");
The dialog option ensures that it stays always on top with respect to the Pale Moon window, but not if I switch away from Pale Moon.
"One hosts to look them up, one DNS to find them and in the darkness BIND them."

Image
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35473
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

Re: Create a non modal 'always on top' window like Firefox's PiP?

Unread post by Moonchild » 2020-09-15, 08:22

Perhaps you should look at how desktop notifications are created in the toolkit for hints how to do this?
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

User avatar
moonbat
Knows the dark side
Knows the dark side
Posts: 4942
Joined: 2015-12-09, 15:45
Contact:

Re: Create a non modal 'always on top' window like Firefox's PiP?

Unread post by moonbat » 2020-09-15, 09:05

That's an idea. I've also looked at the nsiWindowMediator and similar classes that allow opening a window, but they don't offer anything different from the regular Javascript options. One thing though - the Firefox version of this window is a regular top level desktop window without a frame, just displaying the video, but always on top regardless of whether Firefox has focus.
"One hosts to look them up, one DNS to find them and in the darkness BIND them."

Image
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35473
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

Re: Create a non modal 'always on top' window like Firefox's PiP?

Unread post by Moonchild » 2020-09-15, 09:14

"always on top" is a specific window mode that can be set when creating/changing a window's parameters - it doesn't matter if the application has focus or not for those types of windows. I think off-hand that's how notifications are done since they are toolkit-generated, not system-generated, to be able to have custom content layout in them.
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

User avatar
moonbat
Knows the dark side
Knows the dark side
Posts: 4942
Joined: 2015-12-09, 15:45
Contact:

Re: Create a non modal 'always on top' window like Firefox's PiP?

Unread post by moonbat » 2020-09-15, 09:21

I found nsiWindowWatcher.openWindow() that takes on a list of features, but they're the same as passed to regular Javascript window.open() and there is nothing about always on top there. Closest is 'dialog' which I've used, and it makes the window always on top with respect to Pale Moon. I think that may be due to a parent vs child window relationship that implicitly occurs - in the former case the parent window parameter is optional.

Maybe if I set that to null it might work.
"One hosts to look them up, one DNS to find them and in the darkness BIND them."

Image
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35473
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

Re: Create a non modal 'always on top' window like Firefox's PiP?

Unread post by Moonchild » 2020-09-15, 09:28

A dialog by design is bound to a window. That's how dialogs work. They will be on top of the application, not on top of all.
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

User avatar
moonbat
Knows the dark side
Knows the dark side
Posts: 4942
Joined: 2015-12-09, 15:45
Contact:

Re: Create a non modal 'always on top' window like Firefox's PiP?

Unread post by moonbat » 2020-09-15, 09:32

But the window in question being opened is a XUL window element, not a dialog..does that make a difference?
"One hosts to look them up, one DNS to find them and in the darkness BIND them."

Image
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35473
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

Re: Create a non modal 'always on top' window like Firefox's PiP?

Unread post by Moonchild » 2020-09-15, 09:42

Perhaps this area of existing code will help:
http://xref.palemoon.org/moonchild-cent ... ts.cpp#341
Does seem they are opened as dialogs without a parent.
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

User avatar
FranklinDM
Add-ons Team
Add-ons Team
Posts: 575
Joined: 2017-01-14, 02:40
Location: Philippines
Contact:

Re: Create a non modal 'always on top' window like Firefox's PiP?

Unread post by FranklinDM » 2020-09-15, 09:43

In the extension, Splashed!, I was able to keep the splash window as topmost using js-ctypes. The approach I currently have here works only for Windows, I haven't explored any solutions yet for the other platforms.

The following code should be sufficient enough to make the caller XUL window topmost, at least on Windows:

Code: Select all

const Ci = Components.interfaces;
const Cc = Components.classes;
const Cu = Components.utils;

Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/ctypes.jsm");

        try {
            let lib = ctypes.open("user32.dll");
            let setWindowPos = lib.declare("SetWindowPos",
                            ctypes.winapi_abi,
                            ctypes.bool,
                            ctypes.voidptr_t,
                            ctypes.int32_t,
                            ctypes.int32_t,
                            ctypes.int32_t,
                            ctypes.int32_t,
                            ctypes.int32_t,
                            ctypes.uint32_t);

            let baseWindow = window.QueryInterface(Ci.nsIInterfaceRequestor)
                              .getInterface(Ci.nsIWebNavigation)
                              .QueryInterface(Ci.nsIDocShellTreeItem)
                              .treeOwner
                              .QueryInterface(Ci.nsIInterfaceRequestor)
                              .getInterface(Ci.nsIBaseWindow);
            let hWndString = baseWindow.nativeHandle;
            let hWnd = ctypes.voidptr_t(ctypes.UInt64(hWndString));

            setWindowPos(hWnd, -1, 0, 0, 0, 0, 19);

            lib.close();
	} catch (e) {}

User avatar
moonbat
Knows the dark side
Knows the dark side
Posts: 4942
Joined: 2015-12-09, 15:45
Contact:

Re: Create a non modal 'always on top' window like Firefox's PiP?

Unread post by moonbat » 2020-09-18, 14:38

Just got back to this thread. Pity this will involve OS specific API calls - I'm using Linux only and have no idea about system calls here (or if there's even a standard way to do it across window managers in case that makes a difference).
"One hosts to look them up, one DNS to find them and in the darkness BIND them."

Image
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX

vannilla
Moon Magic practitioner
Moon Magic practitioner
Posts: 2183
Joined: 2018-05-05, 13:29

Re: Create a non modal 'always on top' window like Firefox's PiP?

Unread post by vannilla » 2020-09-18, 15:08

moonbat wrote:
2020-09-18, 14:38
Just got back to this thread. Pity this will involve OS specific API calls - I'm using Linux only and have no idea about system calls here (or if there's even a standard way to do it across window managers in case that makes a difference).
On Linux and BSD you set a window "always on top" by giving hints to the window manager.
It's not guaranteed to be the same on every window manager, but the more popular ones (and even some less popular ones) do "the right thing" so you shouldn't worry about it being a hint.
When using a toolkit like GTK or even plain X it's trivial, but I don't know how to do that with XUL.

User avatar
moonbat
Knows the dark side
Knows the dark side
Posts: 4942
Joined: 2015-12-09, 15:45
Contact:

Re: Create a non modal 'always on top' window like Firefox's PiP?

Unread post by moonbat » 2020-09-18, 15:14

It will get messy if I have to do it the way FranklinDM showed above - basically making a call to a native API using js-ctypes. And since I don't have Windows I can't test it anyway.
Maybe that's how Firefox does it for their implementation but I wouldn't know where to look, let alone whether their approach can be implemented here on a totally different codebase.
"One hosts to look them up, one DNS to find them and in the darkness BIND them."

Image
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35473
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

Re: Create a non modal 'always on top' window like Firefox's PiP?

Unread post by Moonchild » 2020-09-18, 15:41

It's also quite possible they do it by spawning another content process in its own window and doing it that way.
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

User avatar
moonbat
Knows the dark side
Knows the dark side
Posts: 4942
Joined: 2015-12-09, 15:45
Contact:

Re: Create a non modal 'always on top' window like Firefox's PiP?

Unread post by moonbat » 2020-09-18, 16:04

I use Firefox for Amazon Prime - what I've seen is that subtitles won't display in the popup but only in the main tab that it was launched from. Still wonder how an application window gets to stay on top of all the rest, programmatically.
"One hosts to look them up, one DNS to find them and in the darkness BIND them."

Image
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35473
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

Re: Create a non modal 'always on top' window like Firefox's PiP?

Unread post by Moonchild » 2020-09-18, 16:23

moonbat wrote:
2020-09-18, 16:04
Still wonder how an application window gets to stay on top of all the rest, programmatically.
I already explained. It's a mode flag that is set on the window.
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

User avatar
moonbat
Knows the dark side
Knows the dark side
Posts: 4942
Joined: 2015-12-09, 15:45
Contact:

Re: Create a non modal 'always on top' window like Firefox's PiP?

Unread post by moonbat » 2020-09-18, 16:28

If only they exposed the flag as an option via XPCOM :(
Beats having to directly go down to the OS
"One hosts to look them up, one DNS to find them and in the darkness BIND them."

Image
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX

Locked