Startup Script

Using applications, configuring, problems
Post Reply
Message
Author
dcung
Posts: 242
Joined: Sat 14 Jul 2018, 00:11
Location: Down Under - 3rd rock from Sun.

Startup Script

#1 Post by dcung »

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. ... 60#1030760
Last edited by dcung on Sat 22 Jun 2019, 23:57, edited 1 time in total.

dcung
Posts: 242
Joined: Sat 14 Jul 2018, 00:11
Location: Down Under - 3rd rock from Sun.

#2 Post by dcung »

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

wiak
Posts: 2040
Joined: Tue 11 Dec 2007, 05:12
Location: not Bulgaria

#3 Post by wiak »

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/ ... on-startup

https://askubuntu.com/questions/356950/ ... al-monitor

https://askubuntu.com/questions/137927/ ... ng-station

wiak

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#4 Post by greengeek »

Do you have the utility wmctrl on your machine?

williams2
Posts: 337
Joined: Fri 14 Dec 2018, 22:18

#5 Post by williams2 »

If you want you can disable your laptop screen and only use your external monitor, something like:

Code: Select all

xrandr --output HDMI-0 --auto --primary --output LVDS --off
To find out the names of your screens type:

Code: Select all

xrandr
Or you can make the external screen the primary screen, something like this:

Code: Select all

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.

dcung
Posts: 242
Joined: Sat 14 Jul 2018, 00:11
Location: Down Under - 3rd rock from Sun.

#6 Post by dcung »

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. :)
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: Select all

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. :)
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.

dcung
Posts: 242
Joined: Sat 14 Jul 2018, 00:11
Location: Down Under - 3rd rock from Sun.

#7 Post by dcung »

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.. :)
Hence, I changed it back, the laptop is the primary.

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

williams2
Posts: 337
Joined: Fri 14 Dec 2018, 22:18

#8 Post by williams2 »

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.

User avatar
rufwoof
Posts: 3690
Joined: Mon 24 Feb 2014, 17:47

#9 Post by rufwoof »

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.
[size=75]( ͡° ͜ʖ ͡°) :wq[/size]
[url=http://murga-linux.com/puppy/viewtopic.php?p=1028256#1028256][size=75]Fatdog multi-session usb[/url][/size]
[size=75][url=https://hashbang.sh]echo url|sed -e 's/^/(c/' -e 's/$/ hashbang.sh)/'|sh[/url][/size]

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#10 Post by fredx181 »

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: Select all

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/devil ... placement/

Fred

stemsee

#11 Post by stemsee »

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. ... &start=405

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#12 Post by fredx181 »

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. ... &start=405
Yes, the example from Misko using Thunar works well for me:
http://murga-linux.com/puppy/viewtopic. ... 682#989682

I changed it a little to make it work with firefox:

Code: Select all

#!/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

dcung
Posts: 242
Joined: Sat 14 Jul 2018, 00:11
Location: Down Under - 3rd rock from Sun.

#13 Post by dcung »

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: Select all

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.

Post Reply