Announcement

Collapse
No announcement yet.

Centre a window via keyboard shortcut ... with NVIDIA Twinview

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Centre a window via keyboard shortcut ... with NVIDIA Twinview

    I'd like a keyboard shortcut to centre a window on the current screen. I don't see any such action in settings, Global Keyboard Shortcuts > KWin. But it should be easy enough to write a script to do it, right?

    Only I can't find any way to get the dimensions of the current screen in my setup, which is using two physical screens (1920x1080 and 1366x768) with the NVIDIA driver running "Twinview". All the X commands I've tried see it as one screen with dimensions 1920x1848, which is the way Twinview is supposed to work. But KWin at least must know about the physical screens since it avoids placing new windows halfway across the two screens or in the dead space beside the smaller screen.

    Any advice?
    Last edited by SecretCode; Mar 01, 2012, 07:40 AM. Reason: removed a smilie 8)
    I'd rather be locked out than locked in.

    #2
    I have no idea ,but I would maybe wait for a more experienced person to answer,I want to share some games ,such as Blackwood & Bell Mysteries,
    Lucky Cruise,
    Hidden haunts,
    New In Town and
    Code of War
    Last edited by Guest; Mar 20, 2012, 03:50 AM.

    Comment


      #3
      Thank you ... I think

      Bump for attention of more experienced people!
      I'd rather be locked out than locked in.

      Comment


        #4
        Download the xdotool from the repositories and use this script:

        #! /bin/bash

        Bottom_Panel=30
        Gap=40

        window=`xdotool getactivewindow`

        x=`xrandr | grep "*" | awk '{print $1}' | awk -F "x" '{print $1}'`
        y=`xrandr | grep "*" | awk '{print $1}' | awk -F "x" '{print $2}'`
        w=`xwininfo -id $window | grep "Width" | awk '{print $2}'`
        h=`xwininfo -id $window | grep "Height" | awk '{print $2}'`

        #working area
        xpos=$((($x-$w)/2))
        ypos=$(((($y-$h)/2)-$Bottom_Panel))

        xdotool windowmove $window $xpos $ypos

        # End of script

        Play around with the Bottom_Panel and Gap settings until you get what you want.

        Make the script executable and then assign it to a Shortcut Key. This works for me.

        Comment


          #5
          No good, unfortunately - xrandr | grep "*" returns
          Code:
             1920x1848     102.0*
          so it is not aware of the Twinview setup and thus this code will centre windows across the two outputs.

          The information on the physical outputs is definitely available to KWin, but I don't know how to retrieve it.
          I'd rather be locked out than locked in.

          Comment


            #6
            Try this:

            #! /bin/bash

            Bottom_Panel=35
            Gap=20

            window=$(xdotool getactivewindow)
            # mousepos == ( "2401" "750" )
            mousepos=( $( xdotool getmouselocation 2>&1 | sed -n -e 's|^x:\([0-9]\+\) y:\([0-9]\+\) .*$|\1 \2|p' | head -n1 ) )

            # ${monitors[@]} == ( "2560,1440,1920,0" "1920,1080,0,0" )
            monitors=( $(xrandr | sed -n -e 's:^.*\bconnected \([0-9]\+\)x\([0-9]\+\)+\([0-9]\+\)+\([0-9]\+\) .*$:\1,\2,\3,\4') )

            monitor=( 0 0 1024 768 )

            for m in ${monitors[@]}
            do
            tmpm=( ${m//,/ } )
            x0=${tmpm[2]}
            x1=$((x0 + ${tmpm[0]}))
            y0=${tmpm[3]}
            y1=$((y0 + ${tmpm[1]}))
            xm=${mousepos[0]}
            ym=${mousepos[1]}
            if [[ ($x0 -le $xm) && ($xm -le $x1) && ($y0 -le $ym) && ($ym -le $y1) ]]
            then
            monitor=( $x0 $y0 $x1 $y1 )
            break
            fi
            done

            x=${monitor[2]}
            y=${monitor[3]}
            w=$(xwininfo -id $window | grep "Width" | awk '{print $2}')
            h=$(xwininfo -id $window | grep "Height" | awk '{print $2}')

            newx=$(( x - w ))
            xpos=$(( newx - Gap ))

            xdotool windowmove "${window}" "${xpos}" "${Gap}"

            # It should place the window top right - but might give you an idea.

            Comment


              #7
              Same problem.

              I don't see anywhere in this code that recognises the two separate outputs, only one large monitor.
              I'd rather be locked out than locked in.

              Comment

              Working...
              X