Weeeeelll, If you want to control the desktop then I guess that you are going to take into consideration "the desktop".
Or use the dbus notify method. (I believe that I may have mentioned this before )
[SOLVED] take over system focus
Re: take over system focus
Have you ever noticed that software is never advertised using the adjective "spreadable".
Re: take over system focus
I did more testing and the code
Public Sub OpenTestWindow()
Dim w As Window = New Window
w.W = 300
w.H = 200
w.Move(Screens[1].X + 100, 100)
w.Stacking = Window.Above
w.TopOnly = True
w.Show
End
will open a window but it is under the VLC full screen. I am still trying to find a way to pop up a window even over a full screen app. or find that it just can't be done. VLC "jitters" for a second when the message pops under it but that is all.
Maybe we are not on the same page as to what full screen means. I am for example bringing up vlc and double click the window so it uses the entire screen. No controls or edges. This on fedora 37 using wayland (yes I know yuck but I need to be able to work with default installs). Even on X I get the same behavior.
Public Sub OpenTestWindow()
Dim w As Window = New Window
w.W = 300
w.H = 200
w.Move(Screens[1].X + 100, 100)
w.Stacking = Window.Above
w.TopOnly = True
w.Show
End
will open a window but it is under the VLC full screen. I am still trying to find a way to pop up a window even over a full screen app. or find that it just can't be done. VLC "jitters" for a second when the message pops under it but that is all.
Maybe we are not on the same page as to what full screen means. I am for example bringing up vlc and double click the window so it uses the entire screen. No controls or edges. This on fedora 37 using wayland (yes I know yuck but I need to be able to work with default installs). Even on X I get the same behavior.
- BruceSteers
- Posts: 1579
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: take over system focus
My code and vlc has no problem on X (see screenshot)
I did find that TopOnly = True and Stacking = Window.Above do not operate as expected where the window should remain on top but if i click the vlc window it pops to front above the other window, but the other window initially is above vlc here.
I've had to make a couple of workarounds on my software to make something that worked on other systems but didn't work on fedora function properly.
Maybe try this way, it works for me.
I first open the window, then set the flags to bring it to front after it's opened...
I did find that TopOnly = True and Stacking = Window.Above do not operate as expected where the window should remain on top but if i click the vlc window it pops to front above the other window, but the other window initially is above vlc here.
I've had to make a couple of workarounds on my software to make something that worked on other systems but didn't work on fedora function properly.
Maybe try this way, it works for me.
I first open the window, then set the flags to bring it to front after it's opened...
Public Sub OpenTestWindow()
Wait 2 ' wait for me to move the mouse to VLC screen to test.
' find what screen the mouse is on...
Dim hRect As Rect, iScreen As Integer
If Screens.Count > 1 Then
For Each hScreen As Screen In Screens
hRect = Rect(hScreen.X, hScreen.Y, hScreen.W, hScreen.H)
If hRect.Contains(Mouse.ScreenX, Mouse.ScreenY) Then Break
Inc iScreen
Next
Endif
' Make window on mouse screen
Dim w As Window = New Window
w.W = 300
w.H = 200
w.Move(Screens[iScreen].X + 100, Screens[iScreen].Y + 100)
w.Utility = True
' open window
w.Show
Wait 0.1
' force it to front
w.Stacking = Window.Above
w.TopOnly = True
w.Activate
End
- Attachments
-
- Screenshot at 2023-08-02 07-50-43.png (672.01 KiB) Viewed 1620 times
If at first you don't succeed , try doing something differently.
BruceS
BruceS
Re: take over system focus
Bruce you are a genius. That worked perfectly. and deadpool is awesome.
Re: take over system focus
This is a great thread and very helpful.
I've struggled with coming up with a solution to this problem myself, and failed. I have to hand it to BruceSteers for sharing his method, which solved the problem for me.
I'm attaching my own code, based on Bruce's code. I'm trying to help anyone easily be able to plug Bruce's method into their own code. And use it as a replacement for Gambas' built-in Message() function.
It uses it a simple function that loads a child form, where I've more or less re-created the Gambas Message() window. Depending on how you call the function, it can show information alerts, warning alerts, and a Yes/No question dialog. All with appropriate icons.
Hopefully in the future, something like Bruce's "Window.Above" can be built into the Gambas Message() function and be there as a user option.
I'm not in league with the great coders on this forum. So if anyone would like to improve on this code, make it more logical, make it even easier for anyone to plug it into their own applications as a replacement for Message(), I welcome it and look forward to it.
I've struggled with coming up with a solution to this problem myself, and failed. I have to hand it to BruceSteers for sharing his method, which solved the problem for me.
I'm attaching my own code, based on Bruce's code. I'm trying to help anyone easily be able to plug Bruce's method into their own code. And use it as a replacement for Gambas' built-in Message() function.
It uses it a simple function that loads a child form, where I've more or less re-created the Gambas Message() window. Depending on how you call the function, it can show information alerts, warning alerts, and a Yes/No question dialog. All with appropriate icons.
Hopefully in the future, something like Bruce's "Window.Above" can be built into the Gambas Message() function and be there as a user option.
I'm not in league with the great coders on this forum. So if anyone would like to improve on this code, make it more logical, make it even easier for anyone to plug it into their own applications as a replacement for Message(), I welcome it and look forward to it.
- Attachments
-
- OnTopMessage.tar.gz
- (21.31 KiB) Downloaded 87 times
- cogier
- Site Admin
- Posts: 1127
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: take over system focus
Well, you asked! I hope I have simplified this. Anyway, I had a bit of fun doing it.I'm not in league with the great coders on this forum. So if anyone would like to improve on this code, make it more logical, make it even easier for anyone to plug it into their own applications as a replacement for Message(), I welcome it and look forward to it.
Re: take over system focus
Bravo cogier! You nailed it. And great idea to put the function that does the work in the child form. And you took me to school. I will learn a lot from studying your much-improved code.cogier wrote: ↑Thursday 10th August 2023 2:42pmWell, you asked! I hope I have simplified this. Anyway, I had a bit of fun doing it.I'm not in league with the great coders on this forum. So if anyone would like to improve on this code, make it more logical, make it even easier for anyone to plug it into their own applications as a replacement for Message(), I welcome it and look forward to it.
OnTopMessage-0.0.1.tar.gz
I haven't had time to try it yet. But I think for anyone wanting to plug this functionality into their own code, simply copy (from cogier's code) ".src/OTMessage.class" and ".src/OTMessage.form" and paste it into your project's ".src/" folder. And using simple calls from your main form (using the examples from cogier's code) will give you Message() popups that will never be hidden behind itself, or any other application.
Thank you cogier for taking the time to work on this. And I'm glad it was fun for you.
UPDATE: copying (from cogier's code) ".src/OTMessage.class" and ".src/OTMessage.form" and pasting it into your project's ".src/" folder allows you to easily plug this functionality into any of your projects. I recommend also copying the 3 icons "info.png", "question.png", and "warning.png" into your application's base folder. But it's only cosmetic. Message windows will still function normally, without error.