Menu

Centering windows

2020-03-19
2020-03-30
1 2 > >> (Page 1 of 2)
  • John Duchek

    John Duchek - 2020-03-19

    Now that I have it working, I am learning to use it. One thing I have noted is that it doesn't really center windows correctly. I have a dual monitor setup, and a centered window appears between the two monitors. I do get that linux treats the the two monitors as one large area of memory. I don't know that there is a solution but thought I should report the effect.
    This is looking like exactly what I have been looking for. Simple to use, and not too many lines of code to get what you want done. Thanks for all your hard work!
    John

     
  • stabud

    stabud - 2020-03-20

    I'm sorry, but on Linux there is no unification for display-related functionality.
    That is, that code that can execute well on one machine may not work on another machine.
    At least I don’t know a 100% working way for all Linux to get full reliable information about the display. Even the famous XRANDR program on different machines / distributions behaves differently.

     
    • John Duchek

      John Duchek - 2020-03-20

      Yes, that is what I was afraid of. I know some programs do it, in fact gnome-terminal keeps coming up right in the middle of the screen when I run a freebasic program and I wish it wouldn't. Thanks for your reply,
      John

       
  • John Duchek

    John Duchek - 2020-03-20

    I was looking at xrandr on my machine (Fedora) and it gives the info needed in 3 different lines. the first line Screen 0: minimum 320 x 200, current 3520 x 1200, maximum 8192 x 8192
    gives the total of the monitors resolution (current).
    Then each "connected" monitor gives how much of that it is using.
    DVI-I-1 connected 1600x1200+0+0 (normal left inverted right x axis y axis) 408mm x 306mm
    VGA-1 connected primary 1920x1080+1600+0 (normal left inverted right x axis y axis) 698mm x 392mm
    FWTIW, John

     
  • John Duchek

    John Duchek - 2020-03-26

    I am back on this subject this morning. I ran "GetCurrentSettingsDisplay.bas" and it only found my smaller monitor. (results were 1600,1200,24,60). I looked at the code and it only looks like it finds one monitor. xrandr shows both as "active monitors". When I type (as in your code) xrandr | grep ''', I get both monitors. 1600x1200 60.00+, 1920x1080 60.00*+ 59.93.(on separate lines in the terminal) It seems to me your code is only getting the first monitor it finds, but all the active monitors are available.

     
  • stabud

    stabud - 2020-03-26

    John!

    I already wrote that I will not do anything with this function and even described the reason. Does XRANDR work well for you? On my main computer, it’s also good, but on my laptops it shows the wrong information. How can I rely on functionality that does not guarantee proper operation? Let everything remain as it is.

     
  • John Duchek

    John Duchek - 2020-03-26

    Xrander does seem to work well for me in Fedora. I understand that you cannot fix everything, and this is a discussion forum so I am bringing concerns up. I will tell you what I can do for you on this. I have 8 popular flavors of linux on harddrives for my laptops and three different models of dell laptops available where I am. I will try all the combinations I can (the hdrives don't fit all the laptops) and make a table of when xrandr is correct and when it is not. I can also slap a 2nd monitor on the laptops as I do this to see if that is reported correctly. That should at least give us a lay of the land. Believe me, I do not intend to criticize you in any way. I have already found that window9 is the missing link that I have needed to make freebasic a full featured language. The statement that it works like Purebasic is only partially true. I think it is superior to purebasic for getting windows running with a minimum of effort. Anyway I will be back with a summary of how well xrandr handles various linux flavors on laptops.

    John

     
  • John Duchek

    John Duchek - 2020-03-26

    Ok, I didn't bother with a table, there was no need. I just used 2 of my laptops(Dell E6530,Dell 630) , the others were 32 bit and awfully old. I tried Fedora, Ubuntu 18.04, Linux Mint 19.2, Debian 10.1, OpenSUSE Leap 15.1. I booted the computers with their native screen, and with a second monitor attached, independently and using a docking station. On the Dell D630, it booted with the 2nd monitor inactive so I manually activated it with 'Display'. In all cases xrander correctly identified the situation. Before manually activating the 2nd monitor it saw one. After activating it it saw both. I only have dell laptops so I cannot test other brands, but since most linux flavors are based on Fedora (centos, redhat), Debian (ubuntu, Mint), and OpenSUSE, it would seem xrandr is pretty accurate.
    FWTIW,
    John

     
  • stabud

    stabud - 2020-03-27

    I have one question: if 4-6 monitors are connected to the computer, then which monitor should display the window in the center?


    We cannot predict user preferences in advance . Therefore, programs make it possible to maintain the location of the window. CenterWindow is simply one of the default options for users. Agree that you cannot create something universal for all tasks.
    If you need such a functional so much, you can do what I do in such situations. I take the ready-made function, change it as needed and add it to the project.

     
  • John Duchek

    John Duchek - 2020-03-27

    I thought about that. I think making it a user choice would be the best. In the center windows routine, include an integer that would default to 1, but the user could manually adjust it (1 through 6 or whatever) to any one of his monitors and it would center on that monitor.. In a program written for other people, it could be set permanently that way in a parameter file, or changed as needed.
    It isn't just center_windows that bothers me, the getcurrent settings.bas just ignored my main monitor. If I center manually and roughly like this
    xsize=400
    ysize=400
    hwnd=OpenWindow("1",2540-xsize/2,540-ysize/2,xsize,ysize)
    (my second monitor is on the left, main on the right), that works. However If I give a copy to someone with a different set up, he would have to edit this to make it work with his computer. Or even if I put it on another of my computers. If I just give him the compiled version he would just be screwed.

    If I could program in C very well, I would do your last suggestion. Unfortunately that is why I program in basic.
    John

     
  • stabud

    stabud - 2020-03-27

    If I could program in C very well, I would do your last suggestion. Unfortunately that is why I program in basic.

    And what does the language C have to do with it? I meant that window9 code is open and you can always make changes to existing functions written in freebasic.

    As for this topic with monitors, I still physically cannot write these functions, since I only have one monitor and it is a little lively. :)

     
  • John Duchek

    John Duchek - 2020-03-27

    I had another idea ;-). if the user could input where his monitor that he wanted the centering on, then you wouldn't even need xrandr. For example, my main monitor starts in x at 1601 and goes 1900 pixels. In y it starts at 0 and goes 1080 pixels. My secondary monitor goes from 0 to 1600 in x and 0 to 1200 in y. My understanding is linux sets up an area for all the monitors to exist in. If I could give the centering routine 1601,1900,0,1080 then one simply has to center that area, no matter how many monitors I had. In addition I could have parameters and set up the 1-n monitors myself at that point. Ok, maybe it isn't C. It is all the pointers I have trouble with.

     
  • stabud

    stabud - 2020-03-27

    Ok, let's get it right from the start :) Can you show the result of the XRANDR output for your dual-monitor computer? Also, please show what the functions output: GetCurrentSettingsDisplay + GetHeightDesktop + GetWidthDesktop

     
  • John Duchek

    John Duchek - 2020-03-27

    Sure.
    first:
    [jduchek@localhost ~]$ xrandr | grep ''
    1600x1200 60.00
    +
    1920x1080 60.00+ 59.93
    [jduchek@localhost ~]$
    Second:
    [jduchek@localhost ~]$ xrandr
    Screen 0: minimum 320 x 200, current 3520 x 1200, maximum 8192 x 8192
    DVI-I-1 connected 1600x1200+0+0 (normal left inverted right x axis y axis) 408mm x 306mm
    1600x1200 60.00
    +
    1400x1050 74.76 59.98
    1600x900 59.95 59.82
    1280x1024 75.02 60.02
    1400x900 59.96 59.88
    1280x960 60.00
    1440x810 59.97
    1368x768 59.88 59.85
    1280x800 59.99 59.97 59.81 59.91
    1152x864 75.00
    1280x720 60.00 59.99 59.86 59.74
    1024x768 75.05 60.04 75.03 70.07 60.00
    960x720 75.00 60.00
    928x696 75.00 60.05
    896x672 75.05 60.01
    1024x576 59.95 59.96 59.90 59.82
    960x600 59.93 60.00
    832x624 74.55
    960x540 59.96 59.99 59.63 59.82
    800x600 75.00 70.00 65.00 60.00 72.19 75.00 60.32 56.25
    840x525 60.01 59.88
    864x486 59.92 59.57
    700x525 74.76 59.98
    800x450 59.95 59.82
    640x512 75.02 60.02
    700x450 59.96 59.88
    640x480 60.00 75.00 72.81 75.00 66.67 59.94
    720x405 59.51 58.99
    720x400 70.08
    684x384 59.88 59.85
    640x400 59.88 59.98
    576x432 75.00
    640x360 59.86 59.83 59.84 59.32
    512x384 75.03 70.07 60.00
    512x288 60.00 59.92
    416x312 74.66
    480x270 59.63 59.82
    400x300 72.19 75.12 60.32 56.34
    432x243 59.92 59.57
    320x240 72.81 75.00 60.05
    360x202 59.51 59.13
    320x180 59.84 59.32
    HDMI-1 disconnected (normal left inverted right x axis y axis)
    VGA-1 connected primary 1920x1080+1600+0 (normal left inverted right x axis y axis) 698mm x 392mm
    1920x1080 60.00*+ 59.93
    1680x1050 59.95 59.88
    1400x1050 74.76 59.98
    1600x900 59.95 59.82
    1280x1024 75.02 60.02
    1440x900 59.89
    1400x900 59.96 59.88
    1280x960 60.00
    1440x810 59.97
    1368x768 59.88 59.85
    1280x800 59.97 74.93 59.81 59.91
    1152x864 75.00
    1280x768 59.99
    1280x720 60.00 59.99 59.86 60.00 59.74
    1024x768 60.04 75.03 70.07 60.00
    960x720 75.00 60.00
    928x696 75.00 60.05
    896x672 75.05 60.01
    1024x576 59.95 59.96 59.90 59.82
    960x600 59.93 60.00
    832x624 74.55
    960x540 59.96 59.99 59.63 59.82
    800x600 75.00 70.00 65.00 60.00 72.19 75.00 60.32 56.25
    840x525 60.01 59.88
    864x486 59.92 59.57
    700x525 74.76 59.98
    800x450 59.95 59.82
    640x512 75.02 60.02
    700x450 59.96 59.88
    640x480 60.00 72.81 75.00 59.94
    720x405 59.51 58.99
    720x400 70.08
    684x384 59.88 59.85
    640x400 59.88 59.98
    576x432 75.00
    640x360 59.86 59.83 59.84 59.32
    512x384 75.03 70.07 60.00
    512x288 60.00 59.92
    416x312 74.66
    480x270 59.63 59.82
    400x300 72.19 75.12 60.32 56.34
    432x243 59.92 59.57
    320x240 72.81 75.00 60.05
    360x202 59.51 59.13
    320x180 59.84 59.32
    [jduchek@localhost ~]$
    Getcurrentsettingsdisplay.bas
    1600
    1200
    24
    60
    GetHeightDesktop.bas
    1600
    1200
    24
    60

    GetWidthDesktop.bas
    1600
    1200
    24
    60

     
  • stabud

    stabud - 2020-03-27

    Say what the terminal displays if you run this code:

    #include "window9.bi"
    
    dim as Display ptr dpy = XOpenDisplay(0)
    
    dim as Integer iCount = XScreenCount(dpy) 
    
    if iCount then
    
        for i as integer = 0 to iCount - 1
    
            ? XDisplayWidth(dpy  , i) , XDisplayHeight(dpy , i)
    
        Next    
    
    EndIf
    
    XCloseDisplay(dpy)
    
    sleep
    
     
  • John Duchek

    John Duchek - 2020-03-27

    It says:
    3520 1200

     
  • stabud

    stabud - 2020-03-27

    hm...

    Say what the terminal displays if you run this code:

    #include "window9.bi"
    
    Dim As String Directory = "/tmp/.X11-unix/"
    
    Var Dir_=ExamineDirectory(Directory, "*.*")
    
    Do
    
        If DirectoryEntryAttributes(Dir_) And FILE_ATTRIBUTE_DIRECTORY  Then
        else
    
            dim as string sDispName = DirectoryEntryName(Dir_)
    
            if left(sDispName , 1) <> "X" then
    
                continue do
    
            else
    
                dim as Display ptr dpy = XOpenDisplay(":" & mid(sDispName , 2))
    
                if dpy <> NULL then
    
                    ? "Display: " & mid(sDispName , 2)
    
                    dim as integer iCount = XScreenCount(dpy)
    
                    ? iCount
    
                    for i as integer = 0 to iCount - 1
    
                        ? XDisplayWidth(dpy  , i) , XDisplayHeight(dpy , i)
    
                    Next    
    
                    XCloseDisplay(dpy)
    
                endif
    
            EndIf
    
        endif
    
    Loop While NextDirectoryEntry(Dir_)
    
    FinishDirectory(Dir_)
    
    sleep
    
     
  • John Duchek

    John Duchek - 2020-03-27

    It says:
    Display: 0
    1
    3520 1200

     
  • John Duchek

    John Duchek - 2020-03-28

    I did learn something today about why this was ignoring my main monitor. I also learned from your code how to import anything from external programs. You probably already know this but here it is:

    include ONCE "window9.bi"

    dim as integer f = FreeFile
    dim as string sRetPipe ,sRetPipe1
    Open Pipe "xrandr | grep '*'" For Input As #f

    Line Input #f, sRetPipe
    line Input #f, sRetPipe1
    print sRetPipe
    print sRetPipe1
    
    Close #f
    

    Gives
    1600x1200 60.00+
    1920x1080 60.00
    + 59.93

    as its output.
    so basically one has to loop through all the monitors.

    The other thing I noticed is that if I put the 1600x1200 monitor above the 1900x1080 monitor the display area changes its size. Here is the xrandr output of that: Everything is pretty much the same except the screen 0 line which changes current dimensions. FWTIW,
    John

    [jduchek@localhost ~]$ xrandr
    Screen 0: minimum 320 x 200, current 1920 x 2280, maximum 8192 x 8192
    DVI-I-1 connected 1600x1200+0+0 (normal left inverted right x axis y axis) 408mm x 306mm
    1600x1200 60.00+
    1400x1050 74.76 59.98
    1600x900 59.95 59.82
    1280x1024 75.02 60.02
    1400x900 59.96 59.88
    1280x960 60.00
    1440x810 59.97
    1368x768 59.88 59.85
    1280x800 59.99 59.97 59.81 59.91
    1152x864 75.00
    1280x720 60.00 59.99 59.86 59.74
    1024x768 75.05 60.04 75.03 70.07 60.00
    960x720 75.00 60.00
    928x696 75.00 60.05
    896x672 75.05 60.01
    1024x576 59.95 59.96 59.90 59.82
    960x600 59.93 60.00
    832x624 74.55
    960x540 59.96 59.99 59.63 59.82
    800x600 75.00 70.00 65.00 60.00 72.19 75.00 60.32 56.25
    840x525 60.01 59.88
    864x486 59.92 59.57
    700x525 74.76 59.98
    800x450 59.95 59.82
    640x512 75.02 60.02
    700x450 59.96 59.88
    640x480 60.00 75.00 72.81 75.00 66.67 59.94
    720x405 59.51 58.99
    720x400 70.08
    684x384 59.88 59.85
    640x400 59.88 59.98
    576x432 75.00
    640x360 59.86 59.83 59.84 59.32
    512x384 75.03 70.07 60.00
    512x288 60.00 59.92
    416x312 74.66
    480x270 59.63 59.82
    400x300 72.19 75.12 60.32 56.34
    432x243 59.92 59.57
    320x240 72.81 75.00 60.05
    360x202 59.51 59.13
    320x180 59.84 59.32
    HDMI-1 disconnected (normal left inverted right x axis y axis)
    VGA-1 connected primary 1920x1080+0+1200 (normal left inverted right x axis y axis) 698mm x 392mm
    1920x1080 60.00
    + 59.93
    1680x1050 59.95 59.88
    1400x1050 74.76 59.98
    1600x900 59.95 59.82
    1280x1024 75.02 60.02
    1440x900 59.89
    1400x900 59.96 59.88
    1280x960 60.00
    1440x810 59.97
    1368x768 59.88 59.85
    1280x800 59.97 74.93 59.81 59.91
    1152x864 75.00
    1280x768 59.99
    1280x720 60.00 59.99 59.86 60.00 59.74
    1024x768 60.04 75.03 70.07 60.00
    960x720 75.00 60.00
    928x696 75.00 60.05
    896x672 75.05 60.01
    1024x576 59.95 59.96 59.90 59.82
    960x600 59.93 60.00
    832x624 74.55
    960x540 59.96 59.99 59.63 59.82
    800x600 75.00 70.00 65.00 60.00 72.19 75.00 60.32 56.25
    840x525 60.01 59.88
    864x486 59.92 59.57
    700x525 74.76 59.98
    800x450 59.95 59.82
    640x512 75.02 60.02
    700x450 59.96 59.88
    640x480 60.00 72.81 75.00 59.94
    720x405 59.51 58.99
    720x400 70.08
    684x384 59.88 59.85
    640x400 59.88 59.98
    576x432 75.00
    640x360 59.86 59.83 59.84 59.32
    512x384 75.03 70.07 60.00
    512x288 60.00 59.92
    416x312 74.66
    480x270 59.63 59.82
    400x300 72.19 75.12 60.32 56.34
    432x243 59.92 59.57
    320x240 72.81 75.00 60.05
    360x202 59.51 59.13
    320x180 59.84 59.32

     
  • stabud

    stabud - 2020-03-28

    Do you have the ability to connect monitors to the same interface (hdmi or vga or ...)? I.e:

    1 monitor using HDMI , 2 monitor using HDMI

    or

    1 monitor using VGA , 2 monitor using VGA

    ....

    Then execute XRANDR and show the result of work. It’s important for me to understand what XRANDR will return in this situation

    As important info XRANDR in which both monitors duplicate the same information (that is, displays the same thing on two monitors)

     
  • stabud

    stabud - 2020-03-28

    How many files you have at : /tmp/.X11-unix/ ?

     
  • stabud

    stabud - 2020-03-28

    That will show this code:

    #include "window9.bi"
    
    dim as Long iDisplay 
    
    do
    
        dim as Display ptr dpy = XOpenDisplay(":" & iDisplay)
    
        if dpy then
    
            XCloseDisplay(dpy)
    
            dim as Long iScreen
    
            ? "Display: " & iDisplay
    
            do
    
                dpy = XOpenDisplay(":" & iDisplay & "." & iScreen)
    
                if dpy then
    
                    ? "Screen: " & iDisplay & "." & iScreen
    
                    dim as Integer iCount = XScreenCount(dpy) 
    
                    if iCount then
    
                        for i as integer = 0 to iCount - 1
    
                            ? XDisplayWidth(dpy  , i) , XDisplayHeight(dpy , i)
    
                        Next    
    
                    EndIf
    
                    iScreen +=1
    
                    XCloseDisplay(dpy)
    
                else
    
                    exit do
    
                endif
    
            loop
    
        else
    
            exit do     
    
        EndIf
    
        iDisplay +=1
    
    Loop
    
    sleep
    
     

    Last edit: stabud 2020-03-28
  • John Duchek

    John Duchek - 2020-03-28

    Your last program came back with:
    Display: 0
    Screen: 0.0
    3520 1200

    How many files you have at : /tmp/.X11-unix/ ?
    I have one file in that directory, named X0 and ls -l says
    srwxrwxrwx. 1 root root 0 Mar 28 06:59 X0

    So what I think is that you want two monitors with the same interface, (vga, hdmi). I have 7 computers here, you would think I could. I will check into that and see.

     
  • John Duchek

    John Duchek - 2020-03-28

    I have no way of getting two vga or two hdmi on one computer. My laptops don't consider their internal screen as vga under linux even though they do under windows. I had another idea. A raspberry pi 4 has two hdmi ports and speaks debian. I don't have one here, but I asked the raspberry pi group on facebook for people who have the dual hdmi setup to send me a text file of xrandr output. As they have thousands of members I am sure someone will get back to me soon.

     
  • stabud

    stabud - 2020-03-29

    Hi John!

    That will show this code:

    #include "window9.bi"
    
    dim as GdkScreen ptr scr
    
    dim as Long num_monitors
    
    dim as Long i
    
    scr = gdk_screen_get_default ()
    
    num_monitors = gdk_display_get_n_screens (gdk_display_get_default ()) 'for gtk3 gdk_display_get_n_monitors
    
    for i as long = 0 to num_monitors - 1
    
        dim as GdkRectangle r
    
        gdk_screen_get_monitor_geometry (scr, i, @r)
    
        ? i , r.width , r.height
    
    next
    
    sleep
    
     
1 2 > >> (Page 1 of 2)

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.