diff --git a/examples/select_window.php b/examples/select_and_grow.php similarity index 59% rename from examples/select_window.php rename to examples/select_and_grow.php index 68a109a..bb84b2d 100644 --- a/examples/select_window.php +++ b/examples/select_and_grow.php @@ -6,6 +6,11 @@ use NoccyLabs\X11\WindowSelector; $selector = new WindowSelector(); +// Select window printf("Click a window to select it...\n"); $window = $selector->select(); $window->dump(); + +// Grow the window by 10 pixels +$size = $window->getWindowSize(); +$window->setWindowSize($size->width + 10, $size->height + 10); \ No newline at end of file diff --git a/src/Window.php b/src/Window.php index 2386d18..03dc213 100644 --- a/src/Window.php +++ b/src/Window.php @@ -86,12 +86,34 @@ class Window 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() { - 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->windowTitle, - $this->isVisible?'true':'false' + $this->isVisible?'true':'false', + $size->width, $size->height ); } }