Bugfixes and improvements

This commit is contained in:
Chris 2016-12-26 21:06:30 +01:00
parent f9c2f8f543
commit 8c2d752780
2 changed files with 29 additions and 2 deletions

View File

@ -6,6 +6,11 @@ use NoccyLabs\X11\WindowSelector;
$selector = new WindowSelector(); $selector = new WindowSelector();
// Select window
printf("Click a window to select it...\n"); printf("Click a window to select it...\n");
$window = $selector->select(); $window = $selector->select();
$window->dump(); $window->dump();
// Grow the window by 10 pixels
$size = $window->getWindowSize();
$window->setWindowSize($size->width + 10, $size->height + 10);

View File

@ -86,12 +86,34 @@ class Window
return $this; return $this;
} }
public function getWindowSize()
{
exec("xdotool getwindowgeometry {$this->windowId}", $output, $status);
$str = join("\n",$output);
if (preg_match('/Geometry: ([0-9]+?)x([0-9]+?)$/i', $str, $match)) {
return (object)[
'width' => intval($match[1]),
'height' => intval($match[2])
];
}
return false;
}
public function setWindowSize($width, $height)
{
exec("xdotool windowsize {$this->windowId} {$width} {$height}");
return $this;
}
public function dump() public function dump()
{ {
printf("Window: (id=0x%08x)\n Title: %s\n Visible: %s\n", $size = $this->getWindowSize();
printf("Window: (id=0x%08x)\n Title: %s\n Visible: %s\n Size: %dx%d\n",
$this->windowId, $this->windowId,
$this->windowTitle, $this->windowTitle,
$this->isVisible?'true':'false' $this->isVisible?'true':'false',
$size->width, $size->height
); );
} }
} }