message window on wrong monitor

Post your Gambas programming questions here.
Post Reply
sadams54
Posts: 59
Joined: Monday 09th July 2018 3:43am

message window on wrong monitor

Post by sadams54 » Wednesday 21st July 2021 11:20pm

I have programs written to take advantage of multiple monitors on a system. The problem I have is that I do not seem to be able to control where a standard message window appears. It seems to always appear on the wrong monitor leaving people looking for where the message is at so they can hit ok or cancel etc. Is there a way to control where the window appears?

example...
message.info("Hey, you forgot something") This appears somewhat randomly and never where I want to place it. How can I make it go where I want it?

User avatar
cogier
Site Admin
Posts: 739
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: message window on wrong monitor

Post by cogier » Thursday 22nd July 2021 2:05pm

I don't have a multi monitor system, but I wondered if you create a new Form for your message.info("Hey, you forgot something") instead of relying on the internal message.

Try this as a possible solution: -
' Gambas class file

NewMessage As Form
Button1 As Button
Button2 As Button
Label1 As Label

Public Sub Form_Open()

  With Me
    .Height = 400
    .Width = 500
    .Padding = 5
    .Arrangement = Arrange.None
    .Center
  End With

  With Button1 = New Button(Me) As "Button1"
    .X = 200
    .Y = 350
    .H = 28
    .W = 112
    .Text = "&Click me!"
  End With

End

Public Sub Button1_Click()

  With NewMessage = New Form As "NewMessage"
    .H = 100
    .W = 350
    .Show
  End With

  With Label1 = New Label(NewMessage) As "Label1"
    .X = 10
    .Y = 15
    .H = 28
    .W = 350
    .Font.Size = 16
    .Alignment = Align.Center
    .Text = "Hey, you forgot something."
  End With

  With Button2 = New Button(NewMessage) As "Button2"
    .X = 200
    .Y = 70
    .H = 28
    .W = 112
    .Text = "&OK"
  End With

End

Public Sub Button2_Click()

  NewMessage.Close

End

sadams54
Posts: 59
Joined: Monday 09th July 2018 3:43am

Re: message window on wrong monitor

Post by sadams54 » Thursday 22nd July 2021 5:53pm

I was actually looking to do that today but using the internal is just so much easier. However I was planning on making a universal message and input box setup in the mean time.

User avatar
stevedee
Posts: 450
Joined: Monday 20th March 2017 6:06pm

Re: message window on wrong monitor

Post by stevedee » Thursday 22nd July 2021 6:08pm

sadams54 wrote:
Wednesday 21st July 2021 11:20pm
...Is there a way to control where the window appears?
I don't know, but take a look at wmctrl which can move the active window to another workspace;

Code: Select all

wmctrl -r :ACTIVE: -t 2
...will send active window to workspace 3 ...I can't remember whether extra monitors are like additional workspaces.

sadams54
Posts: 59
Joined: Monday 09th July 2018 3:43am

Re: message window on wrong monitor

Post by sadams54 » Thursday 22nd July 2021 8:18pm

in this case workspaces and monitors are very different. so that would not work. I have attempted to use extensions that will move things to the right place but they do not affect dialogs which is what this is.
when using multiple monitors the x and or y attributes are essentially doubled making the monitors a single entity. so to put something on a particular monitor you would have to set the x or y values beyond the first monitor and into the field of the desired monitor. So workspaces are totally different in that respect.

User avatar
stevedee
Posts: 450
Joined: Monday 20th March 2017 6:06pm

Re: message window on wrong monitor

Post by stevedee » Friday 23rd July 2021 10:21am

sadams54 wrote:
Thursday 22nd July 2021 8:18pm
...when using multiple monitors the x and or y attributes are essentially doubled making the monitors a single entity. so to put something on a particular monitor you would have to set the x or y values beyond the first monitor and into the field of the desired monitor...
OK, I'm probably missing something here, but if the display is just spread over a number of monitors, why can't you do what you say above?
e.g. to place form on required display

Code: Select all

frmMessage.Left = Screen.Width * MonitorNumber
...assuming monitors numbered from zero

User avatar
PJBlack
Posts: 157
Joined: Tuesday 09th June 2020 10:26pm
Location: Florstadt, Hessen, Germany

Re: message window on wrong monitor

Post by PJBlack » Friday 23rd July 2021 11:05am

sadams54 wrote:
Wednesday 21st July 2021 11:20pm
This appears somewhat randomly
some strange twisted logic is definitely behind it ... maybe the messagebox appears on the monitor where the application with the focus is running?

if i skimmed the qt documentation correctly there is no way to determine the position there either ... so if you really want to define where the messagebox appears you have to program it yourself ...

interesting should be the calculation of the monitor ... negative x values for everything left of the primary monitor plus the respective y offsets for the different vertical positions ... well have fun

sadams54
Posts: 59
Joined: Monday 09th July 2018 3:43am

Re: message window on wrong monitor

Post by sadams54 » Friday 23rd July 2021 5:49pm

I ended up making my own inputbox and message so I can control where they go on a monitor or which monitor. The built in input and message do not have that ability and show up in unpredictable places. I modeled mine after the built in using same parameters so all I had to do was search and replace the name of the feature. Indeed the x and y position works that is how I control everything now but that option does not exist on the input and message that is built in. The idea to control it that way is sound but just not available. So as I said, I bit the bullet and made my own that does exactly what is needed.

Post Reply