X11::WMCtrl - a Perl wrapper for the wmctrl program.
wmctrl
use X11::WMCtrl; use strict; my $wmctrl = X11::WMCtrl->new; printf("window manager is %s\n", $wmctrl->get_window_manager->{name}); my @windows = $wmctrl->get_windows; my $workspaces = $wmctrl->get_workspaces; $wmctrl->switch(1); my $app = $windows[0]->{title}; $wmctrl->maximize($app); $wmctrl->unmaximize($app); $wmctrl->shade($app); $wmctrl->unshade($app); $wmctrl->close($app);
The wmctrl program is a command line tool to interact with an EWMH/NetWM compatible X Window Manager.
It provides command line access to almost all the features defined in the EWMH specification. Using it, it's possible to, for example, obtain information about the window manager, get a detailed list of desktops and managed windows, switch and resize desktops, change number of desktops, make windows full-screen, always-above or sticky, and activate, close, move, resize, maximize and minimize them.
The X11::WMCtrl module provides a simple wrapper to this program.
The wmctrl program can be downloaded from http://sweb.cz/tripie/utils/wmctrl/.
my $wmctrl = X11::WMCtrl->new;
This returns a new X11::WMCtrl object. It will fail if an executable wmctrl program can't be found.
my $wm = $wmctrl->get_window_manager;
This returns a hashref of information about the current window manager. The contents of the hash will vary depending on which one is in use - about the only one you can rely on is name.
name
my @windows = $wmctrl->get_windows;
This method returns an array of hash references with information about the currently managed windows. Each element will contain these keys:
id - the internal ID of the window
id
workspace - the workspace number of the window. Workspaces are zero indexed. If the workspace value is -1, then the window is 'sticky'.
workspace
host - the hostname of the X client drawing the window.
host
title - the title of the window.
title
my $workspaces = $wmctrl->get_workspaces;
This methods returns a hash ref. The keys are the workspaces IDs, and the values are their names.
$wmctrl->switch($workspace);
Switch to workspace $workspace.
$workspace
$wmctrl->activate($window);
Activate the window with the title $window by switching to its workspace and raising it.
$window
$wmctrl->close($window);
Tell the window with the title $window to close.
$wmctrl->move_activate($window);
Activate the window with the title $window by moving it to the current workspace and raising it.
$wmctrl->move_to($window, $workspace);
Moves the window with the title $window to the workspace $workspace.
$wmctrl->maximize($window);
Maximize $window.
$wmctrl->unmaximize($window);
Unaximize $window.
$wmctrl->minimize($window);
Minimize $window.
$wmctrl->unminimize($window);
Unminimize $window.
$wmctrl->shade($window);
Shade $window.
$wmctrl->unshade($window);
Unshade $window.
$wmctrl->sticky($window);
Make the window $window sticky.
$wmctrl->unstick($window);
Removes the 'sticky' property from $window.
$wmctrl->fullscreen($window);
Make $window full-screen.
$wmctrl->unfullscreen($window);
Restore $window from full-screen mode.
$wmctrl->wmctrl(@args);
This methods allows you to send instructions directly to wmctrl. This is used by X11::WMCtrl internally, but if you want to do something that the module doesn't support, this is the easiest way.
$wmctrl->modify_state($window, $mod, @params);
This is another low-level function for sending state modifications to windows. The value of $mod can be either add or remove. @params may have either one or two elements. They may be any of the following:
$mod
add
remove
@params
modal, sticky, maximized_vert, maximized_horz, shaded, skip_taskbar, skip_pager, hidden, fullscreen, above, below
To install this module type the following:
perl Makefile.PL make make test make install
Currently stick(), unstick(), minimize() and unminimize() don't work. This appears to be a problem with wmctrl itself since.
stick()
unstick()
minimize()
unminimize()
Gavin Brown (gavin.brown@uk.com).
Copyright (c) 2014 Gavin Brown. This program is free software, you can use it and/or modify it under the same terms as Perl itself.
To install X11::WMCtrl, copy and paste the appropriate command in to your terminal.
cpanm
cpanm X11::WMCtrl
CPAN shell
perl -MCPAN -e shell install X11::WMCtrl
For more information on module installation, please visit the detailed CPAN module installation guide.