Giter Site home page Giter Site logo

Comments (39)

RSATom avatar RSATom commented on July 28, 2024

I'll look what I can do. At the first look it should be possible, just don't sure what exact logic will be best.

from webchimera.

jaruba avatar jaruba commented on July 28, 2024

I think this can be done with just NW.js, try something like:

var gui = require('nw.gui');
gui.Screen.Init();
var win = gui.Window.get();
var lastScreens = 1;

function checkScreens() {
    win = gui.Window.get();
    if (gui.Screen.screens.length != lastScreens) {
        if (gui.Screen.screens.length == 2 && lastScreens == 1) {
            lastScreens = gui.Screen.screens.length;
            if (win.x < gui.Screen.screens[lastScreens -1].work_area.x) win.x = gui.Screen.screens[lastScreens -1].work_area.x + win.x;
        } else if (gui.Screen.screens.length == 1 && lastScreens == 2) lastScreens = gui.Screen.screens.length;
    }
}

setInterval(function() { checkScreens(); },2000);

checkScreens();

This should (hopefully) move the nw window to the second monitor when it is detected.. it does not move the window back to the first monitor when the second monitor is disconnected because the OS does that anyway (why would it leave it on a non-existing screen?). I did not test this to much though.. tell me if it worked for you. :)

from webchimera.

kevkha avatar kevkha commented on July 28, 2024

Thanks for a quick turnaround. The above code works great as this observation

  1. Start off with two screens
  2. Launch NW app and player appears on screen 2
  3. Disconnect screen 2, player goes back to screen 1 as expected
  4. Reconnect screen 2, player does not go back to screen 2

Can you check on # 4 again? Thanks.

from webchimera.

jaruba avatar jaruba commented on July 28, 2024

I think I over-complicated things in that code, try this code instead:

var gui = require('nw.gui');
gui.Screen.Init();
win = gui.Window.get();
if (win.x < gui.Screen.screens[gui.Screen.screens.length -1].work_area.x) win.x = gui.Screen.screens[gui.Screen.screens.length -1].work_area.x + win.x;

var screenCB = {
    onDisplayAdded : function(screen) {
        win = gui.Window.get();
        if (win.x < screen.work_area.x) win.x = screen.work_area.x + win.x;
    }
};

gui.Screen.on('displayAdded', screenCB.onDisplayAdded);

It worked for me in all the situations you mentioned.

from webchimera.

kevkha avatar kevkha commented on July 28, 2024

You are a super genius, latter code works both cases. Thanks so much.
Now, suppose I create a second window ie

// Create a new window
var new_win = gui.Window.open('player.html', {
  position: 'center',
  width: 800,
  height: 640
});

and want to move the second window instead and leave default 'win' on screen 1 at all time. Can I simply replace 'win' with 'new_win'?

from webchimera.

jaruba avatar jaruba commented on July 28, 2024

why not just put that code only in player.html directly?

from webchimera.

kevkha avatar kevkha commented on July 28, 2024

Good point. I was thinking a hard way again and focused on default index.html. Will keep you posted shortly. Thanks.

from webchimera.

kevkha avatar kevkha commented on July 28, 2024

Sweet! Everything works the way I wanted. Thanks so much again jaruba! Please consider NW.js side is resolved.

from webchimera.

jaruba avatar jaruba commented on July 28, 2024

Glad I could help! :)

from webchimera.

kevkha avatar kevkha commented on July 28, 2024

Is there a donate button on your plugin page? Gotta buy you coffees :-)

from webchimera.

jaruba avatar jaruba commented on July 28, 2024

The button from http://www.webchimera.org/ is the entire project's donate button.

You already donated. :)

from webchimera.

kevkha avatar kevkha commented on July 28, 2024

Ok cool. Good to know. More to come in a few days ;p

from webchimera.

RSATom avatar RSATom commented on July 28, 2024

I think we still need do something similar for fullscreen window?

from webchimera.

kevkha avatar kevkha commented on July 28, 2024

Agreed.

from webchimera.

RSATom avatar RSATom commented on July 28, 2024

@kevkha, btw, how do you attach/detach additional displays? hdmi? And why do you need it to do "on the fly"?

from webchimera.

kevkha avatar kevkha commented on July 28, 2024

Yes, attach and detach the HDMI cable. I need this solution when there is no mouse available to drag player to another screen.

from webchimera.

RSATom avatar RSATom commented on July 28, 2024

so it will be enough for fullscreen window if it just will follow movements of main application window across displays (i.e. without need save active screen history inside fullscreen window)?

from webchimera.

RSATom avatar RSATom commented on July 28, 2024

or it's another solution exists - if you can detect screen attach/detach inside NW.js - you could just:

  • turn off fullscreen
  • move main application window to appropriate screen
  • turn on fullscreen

It should work, since fullscreen window shown on screen where plugin area is (inside browser). Now it will work at least on Windows, on Mac I still need implement fullcreen on second monitor.

from webchimera.

kevkha avatar kevkha commented on July 28, 2024

For my project I need main app window be on screen 1 to display other elements from back end server. When there is only one screen the player (second) window should move to screen 1 and can be on top of main app window. I haven't tested in fullscreen mode movement yet. Do you suggest that I should add fullscreen in onLoad or do it in QML?

from webchimera.

RSATom avatar RSATom commented on July 28, 2024

Hm... it's more complex configuration than I thought.
Did you implement this 2 windows already? I just don't sure if it possible communicate between 2 top level windows in NW.js?

from webchimera.

RSATom avatar RSATom commented on July 28, 2024

And will you have WebChimera on both windows or only one of them?

from webchimera.

kevkha avatar kevkha commented on July 28, 2024

Yes, I have implemented two windows. I only have WebChimera on second window. So it will be active to accept commands from IR. I will test to see if I can do some basic controls using mouse from main window like toggleFullscreen() to second window.

from webchimera.

jaruba avatar jaruba commented on July 28, 2024

Do you guys mean that if a second monitor is connected, and the player is already fullscreen on the first window, it should move with fullscreen already set to the second monitor?

var wasFullscreen = 0;
var gui = require('nw.gui');
gui.Screen.Init();

function onDisplayAdded(screen) {
    if (wjs("#webchimera").plugin.fullscreen) {
        wasFullscreen = 1;
        wjs("#webchimera").plugin.toggleFullscreen();
    } else wasFullscreen = 0;
    if (wjs("#webchimera").plugin.fullscreen) wjs("#webchimera").plugin.toggleFullscreen();
    win = gui.Window.get();
    if (win.x < screen.work_area.x) win.x = screen.work_area.x + win.x;
    if (wasFullscreen == 1) setTimeout(function() { wjs("#webchimera").plugin.toggleFullscreen(); }, 3000);
}

function onDisplayRemoved(screen) {
    if (wjs("#webchimera").plugin.fullscreen) {
        wjs("#webchimera").plugin.toggleFullscreen();
        setTimeout(function() { wjs("#webchimera").plugin.toggleFullscreen(); }, 1000);
    }
}

if (gui.Screen.screens.length > 1) onDisplayAdded(gui.Screen.screens[gui.Screen.screens.length -1]);

gui.Screen.on('displayAdded', onDisplayAdded);
gui.Screen.on('displayRemoved', onDisplayRemoved);

Or do you want the player to auto-fullscreen on the second monitor every time it is connected? (as you mentioned you had no mouse anyway)

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

function onDisplayAdded(screen) {
    if (wjs("#webchimera").plugin.fullscreen) wjs("#webchimera").plugin.toggleFullscreen();
    win = gui.Window.get();
    if (win.x < screen.work_area.x) win.x = screen.work_area.x + win.x;
    setTimeout(function() { wjs("#webchimera").plugin.toggleFullscreen(); }, 3000);
}

function onDisplayRemoved(screen) {
    if (wjs("#webchimera").plugin.fullscreen) {
        wjs("#webchimera").plugin.toggleFullscreen();
        setTimeout(function() { wjs("#webchimera").plugin.toggleFullscreen(); }, 1000);
    }
}

if (gui.Screen.screens.length > 1) onDisplayAdded(gui.Screen.screens[gui.Screen.screens.length -1]);

gui.Screen.on('displayAdded', onDisplayAdded);
gui.Screen.on('displayRemoved', onDisplayRemoved);

These are untested though, but they should work.

As @RSATom mentioned, fullscreen on second monitor will only work on Windows, on Mac it was not implemented yet.

Although we could partially hack it on Mac too.. as HTML5 fullscreen does not require any user interaction in NW. (but the player will act by the rules of a non-fullscreen environment, as with html5 fullscreen, it doesn't know when it's fullscreen or not in QML)

from webchimera.

RSATom avatar RSATom commented on July 28, 2024

@jaruba, yes, something like this. I just think (but didn't try, so not sure) current fullscreen implementation has bug with disconnecting second monitor on-the-fly: If fullscreen mode activated on second screen, and detach this screen, I think fullscreen window will not go to first screen without help from JS.

from webchimera.

jaruba avatar jaruba commented on July 28, 2024

I edited the code above to include a scenario in which the display is removed. (although I didn't test this either) I also delayed the second .toggleFullscreen() for safety. I tried to test it but didn't manage to test it to well... I think it's because I don't test it with a hdmi cable, I'm testing with WiDi on a TV and connecting/disconnecting take a lot longer, in my last tests fullscreen didn't work on the tv at all.. but again, this could be from WiDi.

from webchimera.

kevkha avatar kevkha commented on July 28, 2024

@jaruba I tested both of your new codes but none works. Player does not follow screen 2 at all.

Since I can't move webchimera player when in fullscreen mode I manged to move NW fullscreen window back and forth with following code

// moving player to secondary screen when available
var gui = require('nw.gui');
gui.Screen.Init();
win = gui.Window.get();
if (win.x < gui.Screen.screens[gui.Screen.screens.length -1].work_area.x) win.x = gui.Screen.screens[gui.Screen.screens.length -1].work_area.x + win.x;

// start with fullscreen and focus
win.enterFullscreen();
win.focus();

var screenCB = {
    onDisplayBoundsChanged : function(screen) {
        win = gui.Window.get();
        win.leaveFullscreen();
        win.enterFullscreen();
    },
    onDisplayAdded : function(screen) {
        win = gui.Window.get();
        if (win.x < screen.work_area.x) win.x = screen.work_area.x + win.x;
        win.leaveFullscreen();
        win.enterFullscreen();
    },
    onDisplayRemoved : function(screen) {
        win = gui.Window.get();
        win.leaveFullscreen();
        win.enterFullscreen();
    }
};

// listen to screen events
gui.Screen.on('displayBoundsChanged', screenCB.onDisplayBoundsChanged);
gui.Screen.on('displayAdded', screenCB.onDisplayAdded);
gui.Screen.on('displayRemoved', screenCB.onDisplayRemoved);

And in css I have

html, body { margin: 0; padding: 0; overflow: hidden}
#player_wrapper { width: 100%; height: 100%; position: absolute; top: 0; bottom: 0}

With this solution I need to disable fullscreen on double-click to prevent window movement issue.

from webchimera.

jaruba avatar jaruba commented on July 28, 2024

But that will make the player act like it is not fullscreen.. for example, the toolbar doesn't fade out, it slides down and the progress bar remains visible..

What happens when you try my codes?

from webchimera.

kevkha avatar kevkha commented on July 28, 2024

Yes, that's the only last thing I need to hide.

from webchimera.

jaruba avatar jaruba commented on July 28, 2024

And about your code.. I think this code:

// moving player to secondary screen when available
var gui = require('nw.gui');
gui.Screen.Init();
win = gui.Window.get();
if (win.x < gui.Screen.screens[gui.Screen.screens.length -1].work_area.x) win.x = gui.Screen.screens[gui.Screen.screens.length -1].work_area.x + win.x;

// start with fullscreen and focus
win.enterFullscreen();
win.focus();

function onDisplayAdded(screen) {
    win = gui.Window.get();
    if (win.x < screen.work_area.x) win.x = screen.work_area.x + win.x;
    win.leaveFullscreen();
    win.enterFullscreen();
}

// listen to screen events
gui.Screen.on('displayAdded', onDisplayAdded);

Does the exact same thing, I don't think you need displayBoundsChanged and displayRemoved at all in this particular case. :)

from webchimera.

kevkha avatar kevkha commented on July 28, 2024

You're absolutely right. I use your code now to save some memory :-). Any hint to hide the Toolbar in this situation? I observe the entire tool bar is visible on screen 1 and on screen 2 just the single progress bar which I can live at the moment but hide the whole thing would be a nice hack.

from webchimera.

jaruba avatar jaruba commented on July 28, 2024

That is a bit tricky... the toolbar itself is not made of one element..

In /player/themes/sleek/components/Toolbar.qml change:

anchors.bottomMargin: fullscreen ? 0 : parent.containsMouse ? 0 : -height
...
opacity: fullscreen ? settings.ismoving > 5 ? 0 : 1 : 1

to this:

anchors.bottomMargin: 0
...
opacity: settings.ismoving > 5 ? 0 : 1

Then in /player/themes/sleek/components/ProgressBar.qml change:

anchors.bottomMargin: settings.multiscreen == 1 ? fullscreen ? 32 : -8 : fullscreen ? 32 : mousesurface.containsMouse ? 30 : 0 // Multiscreen - Edit
opacity: settings.multiscreen == 1 ? fullscreen ? fullscreen ? settings.ismoving > 5 ? 0 : 1 : 1 : 0 : fullscreen ? settings.ismoving > 5 ? 0 : 1 : 1 // Multiscreen - Edit

to:

anchors.bottomMargin: 30
opacity: settings.ismoving > 5 ? 0 : 1

I can't be sure of any other implications node-webkit's internal fullscreen window might have on the player though..

from webchimera.

jaruba avatar jaruba commented on July 28, 2024

Mouse Cursor might now disappear either..

from webchimera.

kevkha avatar kevkha commented on July 28, 2024

Above works well except for the circular/square progress position indicator. Which line is it?

from webchimera.

jaruba avatar jaruba commented on July 28, 2024

Try going to /player/themes/sleek/components/ProgressBar.qml and looking for id: movecur then changing:

anchors.bottomMargin: settings.multiscreen == 1 ? fullscreen ? toolbar.height : -16 : fullscreen ? toolbar.height : mousesurface.containsMouse ? toolbar.height : 0
opacity: settings.multiscreen == 1 ? fullscreen ? settings.ismoving > 5 ? 0 : 1 : 0 : fullscreen ? settings.ismoving > 5 ? 0 : 1 : 1

to this:

anchors.bottomMargin: toolbar.height
opacity: settings.ismoving > 5 ? 0 : 1

from webchimera.

kevkha avatar kevkha commented on July 28, 2024

You're super! Everything is working. Thanks! As for your NW complication concern I don't it matter with webchimer player not being fullscreen inside NW fullscreen window. If we have both NW and Webchimera in fullscreen mode there would be 2 or more instances of windows to deal with. If I wish to exit fullscreen of NW I can do so with win.toggleFullscreen().

from webchimera.

jaruba avatar jaruba commented on July 28, 2024

I don't see it as a complication, quite the contrary, I understand why your doing it. Even more so, as fullscreen does not work on second monitor on Mac and doesn't work at all on Linux, using a full-window player with Node-Webkit's Window API - Fullscreen actually fixes all of them in Node-Webkit.

My concern was with the player itself.. it checks "fullscreen" in a lot of places in the logic. So more things might not work as expected.. and I can never be sure what works and what doesn't in this scenario as the player is really big these days. :)

Also, for a more general scenario, it might even be better to use HTML5 Fullscreen instead of NW's Window API - Fullscreen, as HTML5 Fullscreen can be called on html elements, so the player doesn't even need to be the full size of the window for it to work.

from webchimera.

kevkha avatar kevkha commented on July 28, 2024

I hear you. Currently, I have disabled Key_F and double-click for toggleFullscreen in QML so that should prevent it I think. I will run more tests on Windows before moving onto Linux and OSX later. If you don't hear back from me which means things are going well. :-)

My next challenge is figure out how to use global variables in NW so that I can pass and and make calls to webchimera player commands using Javascript API across windows. If you have any ideas I'm all ears. Thanks mate!

from webchimera.

jaruba avatar jaruba commented on July 28, 2024

I'm afraid I never tried communication between 2 windows in NW.

I know there is an object in NW, called localStorage that is not erased even between app close/reopen, so it might also be possible to use it between windows, I can't be sure though, I never tried. I just keep user settings in localStorage.

from webchimera.

mitselek avatar mitselek commented on July 28, 2024

Consider using something like socket.io for communication

from webchimera.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.