Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 12 Nov 2019, 21:02
All times are UTC - 4
 Forum index » House Training » Users ( For the regulars )
Startup Script
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [13 Posts]  
Author Message
dcung

Joined: 13 Jul 2018
Posts: 236
Location: Down Under - 3rd rock from Sun.

PostPosted: Fri 21 Jun 2019, 19:45    Post subject:  Startup Script
Subject description: Dual displays, how to make one program open on a certain monitor?
 

Hi all,
I dedicated a laptop (BionicDog64) with external monitor (TV).
How do I startup Firefox browser on the external monitor (TV) automatically?
If I put in Startup dir, it starts on the laptop monitor. Then I drag it across.
So, I'm after a sample script to put in Startup for this purpose.
Something equivalent to start maximized (in MS Windows) on 2nd monitor (TV). Thanks.

I also post this question in BionicDog section.
http://murga-linux.com/puppy/viewtopic.php?p=1030760#1030760

Last edited by dcung on Sat 22 Jun 2019, 19:57; edited 1 time in total
Back to top
View user's profile Send private message 
dcung

Joined: 13 Jul 2018
Posts: 236
Location: Down Under - 3rd rock from Sun.

PostPosted: Sat 22 Jun 2019, 19:54    Post subject:  

Searching the net, I have not found a solution yet.
This guy is having 'exactly' the same question...

https://ubuntuforums.org/showthread.php?t=1569807
Back to top
View user's profile Send private message 
wiak

Joined: 11 Dec 2007
Posts: 1828
Location: not Bulgaria

PostPosted: Sat 22 Jun 2019, 20:48    Post subject:  

I don't have two monitors, but found another couple of links related to your problem perhaps. Here are the links in case any use:

https://askubuntu.com/questions/789282/auto-switch-to-external-monitor-only-on-startup

https://askubuntu.com/questions/356950/getting-laptop-boot-screen-on-external-monitor

https://askubuntu.com/questions/137927/use-external-monitor-automatically-when-started-in-docking-station

wiak

_________________
Tiny Linux Blog: http://www.tinylinux.info/
Check Firmware: www.murga-linux.com/puppy/viewtopic.php?p=1022797
tinycore/slitaz: http://www.murga-linux.com/puppy/viewtopic.php?p=990130#990130
Back to top
View user's profile Send private message 
greengeek


Joined: 20 Jul 2010
Posts: 5623
Location: Republic of Novo Zelande

PostPosted: Sun 23 Jun 2019, 04:06    Post subject:  

Do you have the utility wmctrl on your machine?
Back to top
View user's profile Send private message 
williams2

Joined: 14 Dec 2018
Posts: 190

PostPosted: Sun 23 Jun 2019, 12:53    Post subject:  

If you want you can disable your laptop screen and only use your external monitor, something like:
Code:
xrandr --output HDMI-0 --auto --primary --output LVDS --off


To find out the names of your screens type:
Code:
xrandr


Or you can make the external screen the primary screen, something like this:
Code:
xrandr --output HDMI-0 --auto --primary --output LVDS --auto


xrandr --help

A good place to put an xrandr command is in /root/.xinitrc

Edit: removed an extraneous colon character.
Back to top
View user's profile Send private message 
dcung

Joined: 13 Jul 2018
Posts: 236
Location: Down Under - 3rd rock from Sun.

PostPosted: Sun 23 Jun 2019, 21:40    Post subject:  

wiak wrote:
I don't have two monitors, but found another couple of links related to your problem perhaps. Here are the links in case any use:
Thanks wiak. Smile

greengeek wrote:
Do you have the utility wmctrl on your machine?
Thanks greengeek. Yes, it appears BionicDog64 has wmctrl installed. I don't know how to use it to achieve my need yet...will have to tinker a bit.

williams2 wrote:
If you want you can disable your laptop screen and only use your external monitor, something like:
Code:
xrandr --output HDMI-0 --auto --primary --output LVDS --off

Thanks williams2. I already am using xrandr somewhat to position my monitors (left & right). I need both monitors. Does not appear xrandr allow me to do what I want.

Have been using this 2 monitors in last 6 months. Happy with everything so far, just getting lazy and trying to automate somewhat. Smile
Just to clarify - my grief is that Firefox always start in laptop screen, regardless where I click the icon from. So, if possible, I'd like a script to start it on the external monitor, without having to drag it across.
Back to top
View user's profile Send private message 
dcung

Joined: 13 Jul 2018
Posts: 236
Location: Down Under - 3rd rock from Sun.

PostPosted: Sun 23 Jun 2019, 22:03    Post subject:  

Since it has been 6 months when I experimented with xrandr, I forgot whether I did make the TV the primary. So, I made the TV the primary just now.
Now I remember, I did try this and didn't like it. Now my problem is the reverse. Everything I click, starts on the TV. Not what I want.. Smile
Hence, I changed it back, the laptop is the primary.

I want I script to start a program on a monitor of my choosing.
Back to top
View user's profile Send private message 
williams2

Joined: 14 Dec 2018
Posts: 190

PostPosted: Mon 24 Jun 2019, 00:02    Post subject:  

Quote:
I want I script to start a program on a monitor of my choosing

The window manager is what usually controls where a window is displayed. When you drag a window from one monitor to another, it is the window manager that is doing it.

I'm running DWM https://dwm.suckless.org/
The default configuration makes Firefox windows always open automatically in workspace 9. It can easily be configured to open on whatever monitor screen you want. Many WMs can be configured to do that. I'm not sure about JWM, I don't use it much. I think IceWM can be configured that way.

wmctrl can move your windows (by asking the window manager to do it.) I'm not sure if it can move windows between monitor screens. Maybe the viewport option? Some WMs work better with wmctrl than others.
Back to top
View user's profile Send private message 
rufwoof


Joined: 24 Feb 2014
Posts: 3611

PostPosted: Mon 24 Jun 2019, 06:47    Post subject:  

If you have Xephyr installed then you can start another X session on a different DISPLAY. For instance run

Xephyr :1 &

to open a window with X running on :1 then send commands to that using something like

DISPLAY=:1 jwm &

Or you could set up a sequence of programs/commands in a script ...
#!/bin/sh
DISPLAY=:1 export DISPLAY
firefox &
jwm

With Xephyr you can specify the initial size, or fullscreen

Xephyr --fullscreen :1 &

My thinking is that if you can get it so that the default DISPLAY (:0) is showing on the monitor and DISPLAY :1 on the TV then you'll have pretty much what you want. Not sure of the commands to do that however. (I'd start by looking at https://en.wikipedia.org/wiki/Multiseat_configuration).

Note that when you run Xephyr in full screen then you'll need to know the minimise key combination in order to reveal the other window when you're displaying on a single monitor. Under jwm its alt-F6 I believe whilst in OpenBox you can use alt-space N (to iconify) - subject of course to having been configured that way (key bindings).

With that setup you could for instance have different window manager running on the two DISPLAYS. Or the other DISPLAY might have no window manager at all, just firefox running for instance. Personally I like to run cwm on my second DISPLAY as that has no decorations, but is a functional window manager i.e. you can move windows around, launch menus or Exec prompt (alt-shift-/ (alt-?)) ...etc.

_________________
( ͡° ͜ʖ ͡°) :wq
Fatdog multi-session usb

echo url|sed -e 's/^/(c/' -e 's/$/ hashbang.sh)/'|sh
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 4157
Location: holland

PostPosted: Mon 24 Jun 2019, 07:05    Post subject:  

dcung wrote:
wmctrl installed. I don't know how to use it to achieve my need yet...will have to tinker a bit.


I can't really test your setup (don't have TV monitor), but this may be a start (adjust the values to your needs)
Code:
PROG="firefox"
X=900        # position, left to right
Y=0          # position, top to bottom
width=1000
height=1000

$PROG & sleep 3; wmctrl -r $PROG -b remove,maximized_vert,maximized_horz; wmctrl -r $PROG -e 0,$X,$Y,$width,$height


As far as I know, wmctrl can place a window at desired position, but only if it's an already existing window (by moving it).
Devilspie2 can do it directly, but is more difficult to configure.
https://www.justingedge.com/linux/devilspie2-automatic-window-placement/

Fred

_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2530
Location: In The Way

PostPosted: Mon 24 Jun 2019, 08:27    Post subject:  

Misko_2083 and Mochimoppel both came up with code to remember locations for app windows to open, only need to add --screen=1:0 or 0:1 or what have you. I took Mocchis version and added it to some scripts both gtk-dialog and yad, but should work with anything that has a window title.

http://murga-linux.com/puppy/viewtopic.php?t=97458&start=405
Back to top
View user's profile Send private message MSN Messenger 
fredx181


Joined: 11 Dec 2013
Posts: 4157
Location: holland

PostPosted: Mon 24 Jun 2019, 09:34    Post subject:  

stemsee wrote:
Misko_2083 and Mochimoppel both came up with code to remember locations for app windows to open, only need to add --screen=1:0 or 0:1 or what have you. I took Mocchis version and added it to some scripts both gtk-dialog and yad, but should work with anything that has a window title.

http://murga-linux.com/puppy/viewtopic.php?t=97458&start=405


Yes, the example from Misko using Thunar works well for me:
http://murga-linux.com/puppy/viewtopic.php?p=989682#989682

I changed it a little to make it work with firefox:
Code:
#!/bin/bash
# Misko_2083 Thunar example modified for Firefox
# see: http://murga-linux.com/puppy/viewtopic.php?p=989682#989682

# Temp file to store absolute position and dimensions
DimFile="$HOME/firefoxXYWH"
WorkspFile="$HOME/firefoxworkspace"

[[ ! -f "$DimFile" ]] && >"${DimFile}"

grep -q '[^[:space:]]' < "$DimFile" &&  readarray -t START <"$DimFile"

app=firefox
$app &

# Check for running instances of $app on current desktop/workspace.
until xdotool getwindowname "$(xdotool search --desktop $(xdotool get_desktop) --class $app 2>/dev/null | tail -1 2>/dev/null)" &>/dev/null; do
        # sleep until the window opens
        sleep .1
done

#Decimal
WindowID="$(xdotool search --desktop $(xdotool get_desktop) --class $app 2>/dev/null | tail -1)"

workspace="$(cat "${WorkspFile}" 2>/dev/null)"

if [[ ${workspace} != "" ]]; then
   # change desktop
   xdotool set_desktop "${workspace: -1}"
   
   # change desktop for window
   xdotool set_desktop_for_window $WindowID "${workspace: -1}"
fi

if [[ ${START[@]} != "" ]]; then
  xdotool windowsize --sync $WindowID ${START[2]} ${START[3]}
  xdotool windowmove --sync $WindowID ${START[0]} ${START[1]}
fi

#Hexadecimal
WindowIDHex=$(printf "0x%08x" ${WindowID})

#Base seven
WindowBSeven=$(printf "0x%07x" ${WindowID})

#Get starting position and size: x, y, width, height
   XWININFO=$(xwininfo -id $WindowIDHex)
   ARRAY=(${XWININFO#* X: })
   AX=${ARRAY[0]}
   AY=${ARRAY[4]}
   RX=${ARRAY[8]}
   RY=${ARRAY[12]}
   W=${ARRAY[14]}
   H=${ARRAY[16]}
   X=$((AX))
   Y=$((AY))

# This monitors the window absolute-top-left x, y, width and height for changes
# If the window is moved - this will get new pos and size
# On destroy event, saves X,Y, W, and H
xev -event structure -id ${WindowIDHex} 2>/dev/null |
       while IFS=$',' read -a A;do
            if [[ "${A[0]#"${A%%[![:space:]]*}"}" =~ "event ${WindowBSeven}" && "${A[1]}${A[2]:1:1}${A[3]: -1}" =~ "window ${WindowBSeven}()" ]]; then
                  X="${A[2]//" ("/}"
                  Y="${A[3]%")"}"
                  W="${A[4]//" width "/}"
                  H="${A[5]//" height "/}"
            # On destroy event
            elif [[ "${A[0]}" =~ "DestroyNotify event" ]]; then
                  >"${DimFile}"
                  X=$((X-RX))
                  Y=$((Y-RY))
                  # Exports dimensions
                  echo "$X" >> "${DimFile}"
                  echo "$Y" >> "${DimFile}"
                  echo "$W" >> "${DimFile}"
                  echo "$H" >> "${DimFile}"
                  # save current workspace
                  workspace="$(xprop -root -notype _NET_CURRENT_DESKTOP 2>/dev/null)"
                  echo "${workspace:-1}" > "${WorkspFile}"
                  # xev dies hard
                  XevPID="$(ps -eo pid,cmd | grep "xev -event structure -id $WindowIDHex" | grep -v "grep" | awk '{ print $1 }')"
                  kill $XevPID 2> /dev/null
            fi
             A=()
        done

exit 0


Fred

_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
dcung

Joined: 13 Jul 2018
Posts: 236
Location: Down Under - 3rd rock from Sun.

PostPosted: Mon 24 Jun 2019, 18:59    Post subject:  

Thank you all for your inputs.

I don't want to install additional software. I ended up adding Fred's code to my startup script.
Code:
PROG="firefox"
X=0          # position, left to right
Y=0          # position, top to bottom
width=1920
height=1080

$PROG & sleep 3; wmctrl -r $PROG -b remove,maximized_vert,maximized_horz; wmctrl -r $PROG -e 0,$X,$Y,$width,$height


The code open Firefox on laptop monitor, then close/reopen on the TV. So now I can turn on laptop&TV, sit on my bed with my remote (wireless mouse). Saving me squinting to drag it from laptop (14") to TV (47"). Laptop still is the main monitor for other tasks (rarely) when TV is off. Achieved what I want.

I noticed some quirks that I didn't before. When Firefox is maximized on laptop, you can drag it to TV and windows manager automatically adjust it (maximized). The reverse is not true, ie. when Firefox is maximized on TV you can not drag it to laptop. I guess it has something to do with the TV has the higher resolution. Of course, when not maximized (ie. windowed) you can drag the window to wherever you want, if the window is bigger than laptop resolution, it just overlap.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [13 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » Users ( For the regulars )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0724s ][ Queries: 11 (0.0053s) ][ GZIP on ]