Browse Source

scripts

master
Simon Vieille 4 years ago
parent
commit
4716b05f62
6 changed files with 186 additions and 0 deletions
  1. 3
    0
      i3_mouse_click.sh
  2. 22
    0
      i3_move_mouse.sh
  3. 63
    0
      i3_switch_focus_container.php
  4. 22
    0
      i3_switch_monitor.sh
  5. 3
    0
      i3_switch_monitor_wrapper.sh
  6. 73
    0
      i3_switch_workspace.php

+ 3
- 0
i3_mouse_click.sh View File

@@ -0,0 +1,3 @@
#!/bin/sh

xdotool click 1

+ 22
- 0
i3_move_mouse.sh View File

@@ -0,0 +1,22 @@
#!/bin/sh

DIRECTION=$1

getMouseX() {
xdotool getmouselocation 2>/dev/null | awk '{ print $1 }' | cut -d: -f2
}

getMouseY() {
xdotool getmouselocation 2>/dev/null | awk '{ print $2 }' | cut -d: -f2
}

moveTo() {
xdotool mousemove $1 $2
}

case $DIRECTION in
left) moveTo $(echo "$(getMouseX)-20" | bc) $(getMouseY);;
right) moveTo $(echo "$(getMouseX)+20" | bc) $(getMouseY);;
up) moveTo $(getMouseX) $(echo "$(getMouseY)-20" | bc) ;;
down) moveTo $(getMouseX) $(echo "$(getMouseY)+20" | bc);;
esac

+ 63
- 0
i3_switch_focus_container.php View File

@@ -0,0 +1,63 @@
#!/usr/bin/php5
<?php

function getTree()
{
return json_decode(shell_exec('i3-msg -t get_tree'));
}

function getFocusedWindowContainer($tree)
{
if (empty($tree->nodes)) {
return null;
}

foreach ($tree->nodes as $k => $container) {
if (true === $container->focused) {
return $tree->nodes;
}

if (null !== $container = getFocusedWindowContainer($container)) {
return $container;
}
}

return null;
}

function getFocusWindowNumber($default, $max)
{
global $argv;

if (!isset($argv[1])) {
$argv[1] = $default;
}

return min($max, max(1, $argv[1])) - 1;
}

function getDefaultFocusWindowNumber($container)
{
foreach ($container as $k => $v) {
if ($v->focused) {
return $k + 1;
}
}
}

function setFocusToWindow($window)
{
shell_exec(sprintf("i3-msg '[con_id=\"%s\"] focus'", $window->id));
}

$container = getFocusedWindowContainer(getTree());

if ($container !== null) {
$number = getFocusWindowNumber(getDefaultFocusWindowNumber($container), count($container));
foreach ($container as $k => $window) {
if ($k == $number) {
setFocusToWindow($window);
}
}
}

+ 22
- 0
i3_switch_monitor.sh View File

@@ -0,0 +1,22 @@
#!/bin/sh

MONITOR1_WIDTH=$1
MONITOR2_WIDTH=$2

getMouseX() {
xdotool getmouselocation 2>/dev/null | awk '{ print $1 }' | cut -d: -f2
}

getMouveNextX() {
if [ $(getMouseX) -lt $MONITOR1_WIDTH ]; then
echo "$MONITOR1_WIDTH+$MONITOR2_WIDTH/2-10" | bc
else
echo "$MONITOR1_WIDTH/2-10" | bc
fi
}

moveTo() {
xdotool mousemove $1 540
}

moveTo $(getMouveNextX)

+ 3
- 0
i3_switch_monitor_wrapper.sh View File

@@ -0,0 +1,3 @@
#!/bin/sh

exec ~/bin/i3_switch_monitor.sh 1920 1920

+ 73
- 0
i3_switch_workspace.php View File

@@ -0,0 +1,73 @@
#!/usr/bin/php5
<?php

function getOrderedWorkspaces()
{
$json = shell_exec('i3-msg -t get_workspaces');
$workspaces = json_decode($json);

$ordered = array();

foreach ($workspaces as $w) {
$ordered[] = $w->name;
}

sort($ordered);

foreach ($ordered as $k => $v) {
foreach ($workspaces as $x => $w) {
if ($w->name == $v) {
$ordered[$k] = $w;
unset($workspaces[$x]);
}
}
}

return $ordered;
}

function getMoveOption()
{
global $argv;

if (!isset($argv[1])) {
$argv[1] = 'next';
}

return in_array($argv[1], array('next', 'previous')) ? $argv[1] : 'next';
}

function getNextWorkspace($workspaces)
{
$key = 0;

foreach ($workspaces as $k => $v) {
if ($v->focused) {
$key = $k;
}
}

return $workspaces[($key + 1) % count($workspaces)];
}

function getPreviousWorkspace($workspaces)
{
$count = count($workspaces);
$key = 0;

foreach ($workspaces as $k => $v) {
if ($v->focused) {
$key = $k;
}
}

return $workspaces[ --$key >= 0 ? $key : $count - 1 ];
}

function moveToWorkspace($workspace)
{
shell_exec(sprintf("i3-msg 'workspace \"%s\"'", $workspace->name));
}

$workspaces = getOrderedWorkspaces();
moveToWorkspace(getMoveOption() === 'next' ? getNextWorkspace($workspaces) : getPreviousWorkspace($workspaces));

Loading…
Cancel
Save