OSDN Git Service

Merge pull request #81 from bob8677/master
[instantos/instantOS.git] / autostart.sh
index 89810ca..578627e 100755 (executable)
@@ -16,6 +16,9 @@ else
     instantutils default
 fi
 
+# apply wm settings
+/usr/share/instantutils/wmautostart.sh
+
 # architecture detection
 if [ -z "$1" ]; then
     if uname -m | grep -q '^arm'; then
@@ -36,7 +39,9 @@ else
 fi
 
 cd
-command -v instantdotfiles && instantdotfiles
+if ! iconf -r keepdotfiles && ! iconf -i nodotfiles; then
+    command -v instantdotfiles && instantdotfiles
+fi
 
 if ! iconf -i rangerplugins && command -v rangerplugins; then
     mkdir instantos
@@ -67,6 +72,20 @@ islive() {
     fi
 }
 
+applymouse() {
+    # read cursor speed
+    if iconf mousespeed; then
+        echo "setting mousespeed"
+        instantmouse s "$(iconf mousespeed)"
+    fi
+
+    if iconf -i reversemouse; then
+        instantmouse r 1
+    else
+        instantmouse r 0
+    fi
+}
+
 # optionally disable status bar
 if iconf -i nobar; then
     NMON=$(iconf names | wc -l)
@@ -122,7 +141,9 @@ if ! pgrep dunst; then
 fi
 
 onlinetrigger() {
-    instantwallpaper &
+    if ! iconf -i nowallpaper; then
+        instantwallpaper &
+    fi
 }
 
 # set up oh-my-zsh config if not existing already
@@ -157,13 +178,19 @@ Disable compositing for this VM?" | imenu -C; then
     fi
 
     if ! [ -e /opt/instantos/guestadditions ]; then
-        if echo "virtual machine detected.
-Would you like to switch to a 1080p resolution?" | imenu -C; then
-            echo "applying virtual machine workaround"
-            /usr/share/instantassist/assists/t/v.sh
+        if lsmod | grep -q vboxguest; then
+            echo "guestadditions detected"
         else
-            if ! imenu -c "ask again next session"; then
-                iconf -i novmfix 1
+            if echo "virtual machine detected.
+Would you like to switch to a 1080p resolution?" | imenu -C; then
+                echo "applying virtual machine workaround"
+                /usr/share/instantassist/assists/t/v.sh
+            else
+                if [ -z "$ISLIVE" ]; then
+                    if ! imenu -c "ask again next session"; then
+                        iconf -i novmfix 1
+                    fi
+                fi
             fi
         fi
     fi
@@ -214,31 +241,14 @@ if ! islive; then
     fi &
 
     # apply keybpard layout
-    if iconf layout; then
-        setxkbmap -layout "$(iconf layout)"
-    else
-        CURLOCALE=$(locale | grep LANG | sed 's/.*=\(.*\)\..*/\1/')
-        case "$CURLOCALE" in
-        de_DE)
-            setxkbmap -layout de
-            ;;
-        *)
-            echo "no keyboard layout found for your locale"
-            ;;
-        esac
-    fi
-
-    # read cursor speed
-    if iconf mousespeed; then
-        echo "setting mousespeed"
-        instantmouse s "$(iconf mousespeed)"
+    if ! iconf layout; then
+        if iconf -r layout; then
+            iconf layout "$(iconf -r layout)"
+        fi
     fi
 
-    if iconf -i reversemouse; then
-        instantmouse r 1
-    else
-        instantmouse r 0
-    fi
+    KEYLAYOUT="$(iconf layout:us)"
+    setxkbmap -layout "$KEYLAYOUT"
 
     if ! iconf -i noconky; then
         shuf /usr/share/instantwidgets/tooltips.txt | head -1 >~/.cache/tooltip
@@ -275,6 +285,45 @@ if ! iconf -i nostatus; then
     source /usr/bin/instantstatus &
 fi
 
+offerdpi() {
+    HEIGHT=$(iconf max | grep -o '[0-9]*$')
+    WIDTH=$(iconf max | grep -o '^[0-9]*')
+    RESOLUTION="$((HEIGHT * WIDTH))"
+    DPIMESSAGE="HiDpi settings can be found in settings->display->dpi"
+    if ! imenu -C <<<"high resolution display detected
+would you like to enable HiDpi?"; then
+        if imenu -c "ask again next time?"; then
+            return
+        fi
+        iconf -i nohidpi 1
+        imenu -m "$DPIMESSAGE"
+        return
+    fi
+
+    DPI=$(imenu -i 'enter dpi (default is 96)')
+    while ! [ "$DPI" -eq "$DPI" ] || [ "$DPI" -gt 500 ] || [ "$DPI" -lt "20" ]; do
+        imenu -m "please enter a number between 20 and 500 (default is 96), enter q to skip hidpi"
+        DPI=$(imenu -i 'enter dpi (default is 96)')
+        if grep -q 'q' <<<"$DPI"; then
+            imenu -m "$DPIMESSAGE"
+            return
+        fi
+    done
+
+    iconf dpi "$DPI"
+
+    instantdpi
+    xrdb ~/.Xresources
+    imenu -m "a restart is needed to globally apply dpi"
+
+}
+
+if ! iconf -i nohidpi && iconf max; then
+    if [ "$RESOLUTION" -gt 8294000 ]; then
+        offerdpi
+    fi
+fi
+
 # compositing
 if iconf -i potato || iconf -i nocompositing; then
     echo "compositing disabled"
@@ -282,19 +331,12 @@ else
     ipicom &
 fi
 
-while :; do
-    lxpolkit
-    sleep 10
-done &
-
 xfce4-power-manager &
 
-
 # auto open menu when connecting/disconnecting monitor
 if ! (iconf -i noautoswitch && iconf -i islaptop) || iconf -i autoswitch; then
 
-    if nvidia-xconfig --query-gpu-info
-    then
+    if nvidia-xconfig --query-gpu-info; then
         DISPLAYCOUNT="$(nvidia-xconfig --query-gpu-info | grep -oi 'number of dis.*' | grep -o '[0-9]*')"
     else
         DISPLAYCOUNT="$(xrandr | grep -c '[^s]connected')"
@@ -350,6 +392,20 @@ if ! iconf -i norootinstall && ! islive; then
     fi
 fi
 
+TODAY="$(date '+%d%m')"
+OTHERTODAY="$(iconf today)"
+
+if [ -z "$OTHERTODAY" ]; then
+    iconf today "$(date '+%d%m')"
+    OTHERTODAY="$(iconf today)"
+fi
+
+if ! [ "$TODAY" = "$OTHERTODAY" ]; then
+    iconf today "$(date '+%d%m')"
+    echo "running daily routine"
+    menuclean
+fi &
+
 # displays message user opens the terminal for the first time
 if ! iconf -i nohelp; then
     if ! grep -q 'instantterminalhelp' ~/.zshrc; then
@@ -372,13 +428,18 @@ confcommand() {
 }
 
 if iconf savebright; then
+    export NOBRIGHTMESSAGE=true
     /usr/share/instantassist/utils/b.sh 2 "$(iconf savebright)"
 fi
 
 confkey highfps "super+alt+shift+d"
 confkey noanimations "super+alt+shift+s"
-# disable wm alttab for graphical alttab
-confkey alttab "super+alt+control+shift+Tab"
+
+if iconf -i alttab; then
+    instantwmctrl alttab 3
+else
+    instantwmctrl alttab 1
+fi
 
 # desktop icons
 confcommand desktopicons rox --pinboard Default
@@ -393,7 +454,7 @@ if [ -e ~/.config/instantos/autostart.sh ]; then
 fi &
 
 # update notifier
-if ! iconf -i noupdates; then
+if ! iconf -i noupdates && [ -z "$ISLIVE" ]; then
     sleep 2m
     if checkinternet; then
         instantupdatenotify
@@ -410,14 +471,28 @@ if ! iconf -i noupdates; then
     fi
 fi &
 
+# needed for things like the pamac auth prompt
+while :; do
+    lxpolkit
+    sleep 2
+done &
+
 # start processes that need to be kept running
 while :; do
-    sleep 10
+    sleep 2
+    # check if new device has been plugged in
+    XINPUTSUM="$(xinput | md5sum)"
+    if ! [ "$OLDXSUM" = "$XINPUTSUM" ]; then
+        OLDXSUM="$XINPUTSUM"
+        instantmouse gen
+        applymouse
+    fi
+    sleep 2
     if iconf -i wifiapplet && ! pgrep nm-applet; then
-        echo "starting bluetooth applet"
+        echo "starting wifi applet"
         nm-applet &
     fi
-
+    sleep 2
     if iconf -i bluetoothapplet && ! pgrep blueman-applet; then
         echo "starting bluetooth applet"
         blueman-applet &
@@ -426,7 +501,6 @@ while :; do
     if iconf -i alttab && ! pgrep alttab; then
         alttab -fg "#ffffff" -bg "#292F3A" -frame "#5293E1" -d 0 -s 1 -t 128x150 -i 127x64 -w 1 -vp pointer &
     fi
-    sleep 2m
 
+    sleep 1m
 done
-