Window titles and windowlist visible matching
This commit is contained in:
parent
8c2d752780
commit
a8ccaca28a
@ -8,13 +8,21 @@ use NoccyLabs\X11\WindowList;
|
||||
$windows = new WindowList();
|
||||
$windows->dump();
|
||||
|
||||
// Select only visible windows
|
||||
$visible = $windows->visible();
|
||||
$visible->dump();
|
||||
|
||||
// Select all the windows with a title matching *code*
|
||||
$windows = $windows->visible()->find("*code*");
|
||||
$windows->dump();
|
||||
$codewindows = $visible->find("*code*");
|
||||
if (count($codewindows)==0) {
|
||||
printf("Sorry, couldn't find any vscode instances running!\n");
|
||||
exit;
|
||||
}
|
||||
$codewindows->dump();
|
||||
|
||||
// Grab the first window
|
||||
$window = $windows->first();
|
||||
$window->dump();
|
||||
$codewindow = $codewindows->first();
|
||||
$codewindow->dump();
|
||||
|
||||
// Focus the window and simulate F1 being pressed
|
||||
$window->focus()->sendKeys("F1");
|
||||
$codewindow->focus()->activate()->sendKeys("F1");
|
||||
|
9
examples/window_title.php
Normal file
9
examples/window_title.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__."/../vendor/autoload.php";
|
||||
|
||||
use NoccyLabs\X11\Window;
|
||||
|
||||
$me = new Window();
|
||||
|
||||
$me->setWindowTitle("Awesome Terminal");
|
@ -26,11 +26,6 @@ class Window
|
||||
foreach ($output as $line) {
|
||||
if (preg_match('/^(.+?): (.+?)$/', trim($line), $match)) {
|
||||
switch ($match[1]) {
|
||||
case 'xwininfo':
|
||||
if (preg_match('/Window id: .+? "(.+?)"/', $match[2], $m)) {
|
||||
$this->windowTitle = $m[1];
|
||||
}
|
||||
break;
|
||||
case 'Map State':
|
||||
$this->isVisible = ($match[2]=='IsViewable');
|
||||
break;
|
||||
@ -54,16 +49,20 @@ class Window
|
||||
|
||||
public function getWindowTitle()
|
||||
{
|
||||
return $this->windowTitle;
|
||||
return trim(exec("xdotool getwindowname {$this->windowId}"));
|
||||
}
|
||||
|
||||
public function sendKeys($keys, $forceFocus=false)
|
||||
public function setWindowTitle($title)
|
||||
{
|
||||
if ($forceFocus) {
|
||||
$this->focus();
|
||||
$cmdl = sprintf("xdotool key %s", $keys);
|
||||
} else {
|
||||
exec("xdotool set_window --name ".escapeshellarg($title)." {$this->windowId}");
|
||||
}
|
||||
|
||||
public function sendKeys($keys, $forceWindow=false)
|
||||
{
|
||||
if ($forceWindow) {
|
||||
$cmdl = sprintf("xdotool key --delay 100 --window %d %s", $this->windowId, $keys);
|
||||
} else {
|
||||
$cmdl = sprintf("xdotool key %s", $keys);
|
||||
}
|
||||
echo "$ {$cmdl}\n";
|
||||
exec($cmdl);
|
||||
|
@ -63,11 +63,12 @@ class WindowList implements IteratorAggregate, Countable
|
||||
|
||||
}
|
||||
|
||||
public function visible()
|
||||
public function visible($match=true)
|
||||
{
|
||||
$found = [];
|
||||
$match = (bool)$match;
|
||||
foreach ($this->windows as $window) {
|
||||
if ($window->isVisible())
|
||||
if ($window->isVisible() == $match)
|
||||
$found[] = $window;
|
||||
}
|
||||
return new WindowList($found);
|
||||
|
Loading…
Reference in New Issue
Block a user