Difference between revisions of "Qtile"

From ArchWiki
Jump to: navigation, search
m (Installing)
(Keys)
(14 intermediate revisions by 7 users not shown)
Line 1: Line 1:
 
[[Category:Tiling WMs]]
 
[[Category:Tiling WMs]]
 +
[[ja:Qtile]]
 
From [http://qtile.org/ Qtile web site]:
 
From [http://qtile.org/ Qtile web site]:
 
:''Qtile is a full-featured, hackable tiling window manager written in Python. Qtile is simple, small, and extensible. It's easy to write your own layouts, widgets, and built-in commands.It is written and configured entirely in Python, which means you can leverage the full power and flexibility of the language to make it fit your needs.''
 
:''Qtile is a full-featured, hackable tiling window manager written in Python. Qtile is simple, small, and extensible. It's easy to write your own layouts, widgets, and built-in commands.It is written and configured entirely in Python, which means you can leverage the full power and flexibility of the language to make it fit your needs.''
  
==Installing==
+
== Installing ==
Qtile (git version) is available in the AUR: {{AUR|qtile-git}}.
+
Install {{AUR|qtile-git}} from the [[Arch User Repository]]
  
A default configuration file is provided on [https://github.com/qtile/qtile/blob/master/libqtile/resources/default_config.py the git repository]. Copy it in {{ic|~/.config/qtile/config.py}}.
+
A default configuration file is provided in [https://github.com/qtile/qtile/blob/master/libqtile/resources/default_config.py the git repository]. Copy it to {{ic|~/.config/qtile/config.py}} by executing:
 
+
An easy way to do this is:
+
 
  $ mkdir -p ~/.config/qtile/
 
  $ mkdir -p ~/.config/qtile/
  $ wget https://raw.github.com/qtile/qtile/master/libqtile/resources/default_config.py -O - > ~/.config/qtile/config.py
+
  $ wget https://raw.github.com/qtile/qtile/develop/libqtile/resources/default_config.py -O - > ~/.config/qtile/config.py
  
==Starting Qtile==
+
If this fails execute the commands:
To start Qtile add {{ic|exec qtile}} to your {{ic|~/.xinitrc}} and launch Xorg.
+
The default configuration includes the shortcut Alt+Enter to open a new xterm terminal.
+
  
==Configuration==
+
$ rm ~/.config/qtile/config.py
 +
$ cp  /usr/lib/python2.7/site-packages/libqtile/resources/default_config.py ~/.config/qtile/config.py
 +
 
 +
== Starting Qtile ==
 +
To start Qtile add {{ic|exec qtile}} to your {{ic|~/.xinitrc}} and launch [[Xorg]]. The default configuration includes the shortcut {{Keypress|Alt+Enter}} to open a new {{ic|xterm}} terminal.
 +
 
 +
== Configuration ==
 
{{Note|This chapter only explains the basics of the configuration of Qtile. For more complete information, look at the [http://docs.qtile.org/en/latest/ official documentation].}}
 
{{Note|This chapter only explains the basics of the configuration of Qtile. For more complete information, look at the [http://docs.qtile.org/en/latest/ official documentation].}}
  
The configuration is fully done in python in the file {{ic|~/.config/qtile/config.py}}. The indentation is very important in python, therefore respect it.
+
The configuration is fully done in Python in the file {{ic|~/.config/qtile/config.py}}. For a ''very'' quick introduction to Python, you can read [https://developers.google.com/edu/python/introduction this tutorial]. It will explain Python variables, functions, modules and other things you need to know to quickly get started on configuring Qtile.
  
Before restarting Qtile you can test your config file for syntax error with the command:
+
Before restarting Qtile you can test your config file for syntax errors using the command:
  $ python2 ~/.config/qtile/config.py
+
  $ python2 -m py_compile ~/.config/qtile/config.py
 +
If the command gives no output, your script is correct.
  
===Groups===
+
=== Groups ===
In Qtile the workspaces (or views) are called Groups. They can be defined as following for instance:
+
In Qtile, the workspaces (or views) are called '''Groups'''. They can be defined as following:
<pre>
+
{{bc|<nowiki>
from libqtile.manager import Group
+
from libqtile.config import Group, Match
 +
...
 
groups = [
 
groups = [
 
     Group("term"),
 
     Group("term"),
    Group("web"),
 
 
     Group("irc"),
 
     Group("irc"),
]
+
    Group("web", match=Match(title=["Firefox"])),
</pre>
+
  ]
 +
...</nowiki>
 +
}}
  
===Keys===
+
=== Keys ===
You can configure your shortcuts with the function Key.
+
You can configure your shortcuts with the '''Key''' class.
Here is an example of the shortcut Alt+Shift+q to quit the Windows Manager.
+
Here is an example of the shortcut {{Keypress|Alt+Shift+q}} to quit the window manager.
<pre>
+
{{bc|<nowiki>
from libqtile.manager import Key
+
from libqtile.config import Key
 
from libqtile.command import lazy
 
from libqtile.command import lazy
 +
...
 
keys = [
 
keys = [
 
     Key(
 
     Key(
         ["shift","mod1"], "q",
+
         ["mod1", "shift"], "q",
         lazy.shutdown()
+
         lazy.shutdown())
    ),
+
  ]
]
+
...</nowiki>
</pre>
+
}}
You can find out which modX corresponds to which key with the command '''xmodmap'''.
+
You can find out which {{ic|modX}} corresponds to which key with the command [[Xmodmap]].
  
===Screens and Bars===
+
=== Screens and Bars ===
Create one Screen function for every monitor you have. The bars of Qtile are configured in the Screen function as in the following example:
+
Create one '''Screen''' class for every monitor you have. The bars of Qtile are configured in the '''Screen''' class as in the following example:
<pre>
+
{{bc|<nowiki>
from libqtile.manager import Screen
+
from libqtile.config import Screen
 
from libqtile import bar, widget
 
from libqtile import bar, widget
 +
...
 
screens = [
 
screens = [
 
     Screen(
 
     Screen(
         bottom=bar.Bar([
+
         bottom=bar.Bar([         # add a bar to the bottom of the screen
             widget.GroupBox(),
+
             widget.GroupBox(),   # display the current Group
             widget.WindowName()
+
             widget.WindowName()   # display the name of the window that currently has focus
 
             ], 30))
 
             ], 30))
]
+
  ]
</pre>
+
...</nowiki>
 +
}}
 +
 
 +
=== Widgets ===
 +
You can find a list of all the built-in widgets in [http://docs.qtile.org/en/latest/manual/ref/widgets.html the official documentation].
 +
 
 +
If you want to add a widget to your bar, just add it like in the example above (for the {{ic|WindowName}} widget). For example, if we want
 +
to add a battery notification, we can use the {{ic|Battery}} widget:
 +
{{bc|<nowiki>
 +
from libqtile.config import Screen
 +
from libqtile import bar, widget
 +
...
 +
screens = [
 +
    Screen(top=bar.Bar([
 +
        widget.GroupBox(),    # display the current Group
 +
        widget.Battery()      # display the battery state
 +
      ], 30))
 +
  ]
 +
...</nowiki>
 +
}}
 +
 
 +
=== Startup ===
 +
You can start up applications using '''hooks''', specifically the {{ic|startup}} hook. For a list of available hooks see [http://docs.qtile.org/en/latest/manual/ref/hooks.html the documentation].
 +
 
 +
Here is an example where an application starts only once:
 +
{{bc|<nowiki>
 +
import subprocess, re
 +
 
 +
def is_running(process):
 +
    s = subprocess.Popen(["ps", "axw"], stdout=subprocess.PIPE)
 +
    for x in s.stdout:
 +
        if re.search(process, x):
 +
            return True
 +
    return False
  
===Widgets===
+
def execute_once(process):
You can find information on the widgets in [http://docs.qtile.org/en/latest/manual/ref/widgets.html the documentation].
+
    if not is_running(process):
 +
        return subprocess.Popen(process.split())
  
Some of the widgets (such as BatteryIcon and Notify) are not included in the default git repository, but you can download them [https://github.com/paradoxxxzero/qtile/tree/master/libqtile/widget/ here] and copy them in {{ic|/usr/lib/python2.7/site-packages/libqtile/widget/}}.
+
# start the applications at Qtile startup
 +
@hook.subscribe.startup
 +
def startup():
 +
    execute_once("parcellite")
 +
    execute_once("nm-applet")
 +
    execute_once("dropboxd")
 +
    execute_once("feh --bg-scale ~/Pictures/wallpapers.jpg")</nowiki>
 +
}}
  
Then modify {{ic|/usr/lib/python2.7/site-packages/libqtile/widget/__init__.py}} to import the new widgets. Here is an example for BatteryIcon and Notify widgets:
+
=== Sound ===
 +
You can add shortcuts to easily control the sound volume and state by [[Users_and_Groups#Group_management|adding a user]] to the '''audio''' group and using the {{ic|alsamixer}} command-line interface.
 +
{{bc|<nowiki>
 +
keys= [
 +
    ...
 +
    # Sound
 +
    Key([], "XF86AudioMute", lazy.spawn("amixer -q set Master toggle")),
 +
    Key([], "XF86AudioLowerVolume", lazy.spawn("amixer -c 0 sset Master 1- unmute")),
 +
    Key([], "XF86AudioRaiseVolume", lazy.spawn("amixer -c 0 sset Master 1+ unmute"))
 +
  ]</nowiki>
 +
}}
  
{{hc
+
== Debugging ==
|/usr/lib/python2.7/site-packages/libqtile/widget/__init__.py
+
If you want to locate the source of a problem, you can execute the following line in your terminal:
|<nowiki>
+
echo "exec qtile" > /tmp/.start_qtile ; xinit /tmp/.start_qtile -- :2
[...]
+
from battery import Battery,BatteryIcon
+
from notify import Notify
+
[...]
+
</nowiki>}}
+
  
==See Also==
+
== See Also ==
 
* [http://qtile.org/ Qtile website]
 
* [http://qtile.org/ Qtile website]
 
* [http://docs.qtile.org/en/latest/ The official documentation]
 
* [http://docs.qtile.org/en/latest/ The official documentation]
 
* [[Comparison of Tiling Window Managers]]
 
* [[Comparison of Tiling Window Managers]]
 
* [[xinitrc]]
 
* [[xinitrc]]

Revision as of 00:24, 24 March 2013

From Qtile web site:

Qtile is a full-featured, hackable tiling window manager written in Python. Qtile is simple, small, and extensible. It's easy to write your own layouts, widgets, and built-in commands.It is written and configured entirely in Python, which means you can leverage the full power and flexibility of the language to make it fit your needs.

Installing

Install qtile-gitAUR from the Arch User Repository

A default configuration file is provided in the git repository. Copy it to ~/.config/qtile/config.py by executing:

$ mkdir -p ~/.config/qtile/
$ wget https://raw.github.com/qtile/qtile/develop/libqtile/resources/default_config.py -O - > ~/.config/qtile/config.py

If this fails execute the commands:

$ rm ~/.config/qtile/config.py
$ cp  /usr/lib/python2.7/site-packages/libqtile/resources/default_config.py ~/.config/qtile/config.py

Starting Qtile

To start Qtile add exec qtile to your ~/.xinitrc and launch Xorg. The default configuration includes the shortcut Template:Keypress to open a new xterm terminal.

Configuration

Note: This chapter only explains the basics of the configuration of Qtile. For more complete information, look at the official documentation.

The configuration is fully done in Python in the file ~/.config/qtile/config.py. For a very quick introduction to Python, you can read this tutorial. It will explain Python variables, functions, modules and other things you need to know to quickly get started on configuring Qtile.

Before restarting Qtile you can test your config file for syntax errors using the command:

$ python2 -m py_compile ~/.config/qtile/config.py

If the command gives no output, your script is correct.

Groups

In Qtile, the workspaces (or views) are called Groups. They can be defined as following:

from libqtile.config import Group, Match
...
groups = [
    Group("term"),
    Group("irc"),
    Group("web", match=Match(title=["Firefox"])),
   ]
...

Keys

You can configure your shortcuts with the Key class. Here is an example of the shortcut Template:Keypress to quit the window manager.

from libqtile.config import Key
from libqtile.command import lazy
...
keys = [
    Key(
        ["mod1", "shift"], "q",
        lazy.shutdown())
   ]
...

You can find out which modX corresponds to which key with the command Xmodmap.

Screens and Bars

Create one Screen class for every monitor you have. The bars of Qtile are configured in the Screen class as in the following example:

from libqtile.config import Screen
from libqtile import bar, widget
...
screens = [
    Screen(
        bottom=bar.Bar([          # add a bar to the bottom of the screen
            widget.GroupBox(),    # display the current Group
            widget.WindowName()   # display the name of the window that currently has focus
            ], 30))
   ]
...

Widgets

You can find a list of all the built-in widgets in the official documentation.

If you want to add a widget to your bar, just add it like in the example above (for the WindowName widget). For example, if we want to add a battery notification, we can use the Battery widget:

from libqtile.config import Screen
from libqtile import bar, widget
...
screens = [
    Screen(top=bar.Bar([
        widget.GroupBox(),    # display the current Group
        widget.Battery()      # display the battery state
       ], 30))
   ]
...

Startup

You can start up applications using hooks, specifically the startup hook. For a list of available hooks see the documentation.

Here is an example where an application starts only once:

import subprocess, re

def is_running(process):
    s = subprocess.Popen(["ps", "axw"], stdout=subprocess.PIPE)
    for x in s.stdout:
        if re.search(process, x):
            return True
    return False

def execute_once(process):
    if not is_running(process):
        return subprocess.Popen(process.split())

# start the applications at Qtile startup
@hook.subscribe.startup
def startup():
    execute_once("parcellite")
    execute_once("nm-applet")
    execute_once("dropboxd")
    execute_once("feh --bg-scale ~/Pictures/wallpapers.jpg")

Sound

You can add shortcuts to easily control the sound volume and state by adding a user to the audio group and using the alsamixer command-line interface.

keys= [
    ...
    # Sound
    Key([], "XF86AudioMute", lazy.spawn("amixer -q set Master toggle")),
    Key([], "XF86AudioLowerVolume", lazy.spawn("amixer -c 0 sset Master 1- unmute")),
    Key([], "XF86AudioRaiseVolume", lazy.spawn("amixer -c 0 sset Master 1+ unmute"))
   ]

Debugging

If you want to locate the source of a problem, you can execute the following line in your terminal:

echo "exec qtile" > /tmp/.start_qtile ; xinit /tmp/.start_qtile -- :2

See Also