瀏覽代碼

Add scripts to handle projector connect and dual monitors toggle

Andrew Swistak 11 年之前
父節點
當前提交
92d83714bc
共有 5 個文件被更改,包括 63 次插入1 次删除
  1. 1 1
      fehbg
  2. 6 0
      openbox/rc.xml
  3. 27 0
      scripts/find_max_ext_monitor_res.rb
  4. 12 0
      scripts/toggle_dual_monitor.sh
  5. 17 0
      scripts/toggle_mirror_display.sh

+ 1 - 1
fehbg

@@ -1 +1 @@
-feh  --bg-fill '/home/drew/Pictures/triforce_1366.jpg' 
+feh  --bg-scale '/home/drew/Pictures/triforce_1680x945.jpg' 

+ 6 - 0
openbox/rc.xml

@@ -382,6 +382,12 @@
       </action>
     </keybind>
     -->
+    <!--Toggle Projector Mode-->
+    <keybind key="XF86Display">
+      <action name="Execute">
+        <command>~/Documents/dotfiles/scripts/find_max_ext_monitor_res.rb</command>
+      </action>
+    </keybind>
     <!--Volume Control-->
     <keybind key="XF86AudioRaiseVolume">
       <action name="Execute">

+ 27 - 0
scripts/find_max_ext_monitor_res.rb

@@ -0,0 +1,27 @@
+#!/usr/bin/env ruby
+
+max_res = nil
+scale = 1
+default_x = `xrandr`.gsub(/.*LVDS.*?\n/m, '')
+                    .gsub(/^\S.*/m, '')
+                    .scan(/\d{1,4}(?=x.*\*)/)[0].to_f
+max_x = default_x
+
+`xrandr`.sub(/.*HDMI.*?\n/m, '').scan(/\d{1,4}x\d{1,4}i?p?/).each do |res|
+  x, y = res.split(/[xip]/).map { |dim| dim.to_f }
+  if x/y == 16.0/9.0
+    unless max_res.nil?
+      if x > max_x
+        max_res, max_x = res, x
+        scale = x/default_x
+      end
+    else
+      max_res, max_x = res, x
+      scale = x/default_x
+    end
+  end
+end
+
+puts scale
+puts max_res
+system "$HOME/Documents/dotfiles/scripts/toggle_mirror_display.sh #{scale}x#{scale} #{max_res}"

+ 12 - 0
scripts/toggle_dual_monitor.sh

@@ -0,0 +1,12 @@
+#!/bin/bash
+
+IN="LVDS1"
+EXT="HDMI1"
+
+if (xrandr | grep "$EXT disconnected"); then
+  xrandr --output $IN --auto --output $EXT --off
+  $HOME/.fehbg
+else
+  xrandr --output $IN --auto --primary --output $EXT --auto --right-of $IN
+  $HOME/.fehbg
+fi

+ 17 - 0
scripts/toggle_mirror_display.sh

@@ -0,0 +1,17 @@
+#!/bin/bash
+
+IN="LVDS1"
+EXT="HDMI1"
+
+if (xrandr | grep "$EXT disconnected"); then
+  xrandr --output $IN --auto --scale 1.0x1.0 --output $EXT --off
+  $HOME/.fehbg
+  killall conky 1>/dev/null 2>&1
+  conky -c $HOME/.config/conky/conkyrc 1>/dev/null 2>&1 &
+else
+  xrandr --output $IN --scale $1 \
+         --output $EXT --auto --mode $2 --same-as $IN
+  $HOME/.fehbg
+  killall conky 1>/dev/null 2>&1
+  conky -c $HOME/.config/conky/conkyrc 1>/dev/null 2>&1 &
+fi