scripts
This commit is contained in:
parent
ab58b2a87a
commit
4716b05f62
3
i3_mouse_click.sh
Executable file
3
i3_mouse_click.sh
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
xdotool click 1
|
22
i3_move_mouse.sh
Executable file
22
i3_move_mouse.sh
Executable 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
i3_switch_focus_container.php
Executable file
63
i3_switch_focus_container.php
Executable 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
i3_switch_monitor.sh
Executable file
22
i3_switch_monitor.sh
Executable 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
i3_switch_monitor_wrapper.sh
Executable file
3
i3_switch_monitor_wrapper.sh
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
exec ~/bin/i3_switch_monitor.sh 1920 1920
|
73
i3_switch_workspace.php
Executable file
73
i3_switch_workspace.php
Executable 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…
Reference in a new issue