The first experience of Linux window manager--qtile

Source: Internet
Author: User

Tiling window manager--A tiled Windows manager that manages windows in layers differently than floating, flattening all windows horizontally, seamlessly docking windows, which helps to view the contents of multiple windows at the same time, which is especially useful for programmers.

Tiled window Manager There are many, more famous like Awesome,i3 and so on, but awesome is written in Lua language, I did not use, do not introduce. And Qtile is written in pure Python, as a Python fan (although the sea is a rookie of the rookie), I naturally choose Qtile.

Qtile's official website: http://www.qtile.org

The Qtile Graphical object (object graph) has a total of seven parts: layouts, windows, screen, groups, bars, widgets and a root.

Layouts: layout, in what way to distribute the window, including max (Single Window occupies the entire screen), Tiling (prorated window), Floationg (floating window), monadtall (tiled window simulating xmonad), Slice, Stack (divides the screen into multiple stacks), Treetab, zoomy

Groups: A workspace equivalent to another desktop environment.

Screens: Physical Screen

Bar: bar, which can be understood as the taskbar

Widgets: Widgets, components, including many, like time, weather, mail view, Task List, GroupBox, etc...


Installation of Qtile method can refer to the official website, but I then follow the official website compile prompt error, is a importerror, as if to say missing a module, but this module I did not find ... Later, after Google a few, find the following workaround:

Pip Install Cffipip install xcffibgit clone-b xcb https://github.com/flacjacket/cairocffi.gitcd cairocffi && Sud o python setup.py installgit clone git://github.com/qtile/qtile.gitcd qtilesudo python setup.py install

It seems that the author has compiled several modules together ...


About the configuration file on the official website provides a lot, both the default configuration, there are other user-written configuration, can be used after reference. After that I will give my configuration, but it is not good.

The details can be seen in official documents, but the official documentation is not exhaustive and many configurations are not mentioned. Especially with regard to Windows (Window objects), in addition to the official default configuration, other users ' configuration uses the content of Windows. I google, Niang for half a day, nothing (or maybe I check the wrong way). It seems likely to look directly at the source code ...


Just passed a bit, it seems not very good upload, now directly paste the configuration file:

#!/usr/bin/env python#-*-coding:utf-8-*-import osfrom libqtile import layout,widget, bar,manager,hookfrom libqtile.widget import basefrom libqtile.manager import  screen,dragfrom libqtile.command import lazytry:    from  libqtile.manager import key,groupexcept importerror:    from  libqtile.config import key,groupsup= ' mod4 ' alt= ' mod1 ' #键位映射keys =[     #Layout      key ([SUP], ' Down ', Lazy.layout.down ()),     key ([sup], ' Up ', lazy.layout.up () ),     key ([Alt], ' tab ', Lazy.layout.next ()),     key ([Alt, ' Shift '], ' tab ', Lazy.layout.previous ()),     key ([sup], ' space ', Lazy.nextlayout ()),     Key ([sup], ' K ', Lazy.layout.increase_ratio ()),     key ([sup], ' J ', Lazy.layout.decrease_ratio () ),     key ([sup], 'L ', Lazy.layout.increase_nmaster ()),     key ([sup], ' h ', Lazy.layout.decrease_nmaster ()),      #Window     key ([Alt], ' F4 ', Lazy.window.kill ()),     key ([Alt], ' F10 ', Lazy.window.toggle_maximize ()),     #Group     key ([SUP], ' left ', Lazy.group.prevgroup ()),     key ([sup], ' right ', Lazy.group.nextgroup ()),      #Application  launchers    key ([sup], ' Return ', Lazy.spawn (' Sakura ')),     key ([sup], ' f ', Lazy.spawn (' Firefox ')),     key ([sup], ' m ', Lazy.spawn ( ' VLC '),     key ([sup], ' V ', lazy.spawn (' VirtualBox ')),     key ([sup], ' t ', Lazy.spawn (' Thunar ')),     key ([sup], ' Q ', Lazy.spawn (' QQ ')),     key ([Sup ], ' Z ', Lazy.spawn (' Zim ')),     #Audio     key ([sup], ' F8 ', Lazy.spawn (' Amixer --quiet&nBsp;set master mute '),     key ([sup], ' F9 ', Lazy.spawn (' amixer --quiet  Set master unmute '),     key ([Alt], ' minus ', Lazy.spawn (' amixer --quiet  set master 2db-'),     key ([Alt, ' Shift '], ' equal ', Lazy.spawn (' Amixer --quiet  set master 2db+ '),     #restart  qtile    key ([Sup ], ' R ', Lazy.restart ()),     #shutdown     key ([SUP, ' shift '], ' Q ', Lazy.spawn (' Shutdown -h now ')),     #interact  with prompts:     key ([sup], ' s ', Lazy.spawncmd ()),     ]mouse=[    drag ([SUP], "Button1", lazy.window.set_position_floating (),         start= Lazy.window.get_position ()),     drag ([sup], "Button3", lazy.window.set_size_floating (),          start=lazy.window.get_size ()),] #建立groupsgroup_names =[     ("Code1", {' Layout ': ' Tile '}),     ("Code2", {"layout": ' Tile '}),     ("Web", {"Layout": "Max"}),      ("VBox", {"Layout": "Max"}),     (' music ', {' layout ': ' Max '}),      (' Doc ', {' layout ': ' Max '}),     (' chat ', {' layout ': ' Max '})]groups=[group ( Name,**kwargs)  for name,kwargs in group_names]for i ,  (Name,kwargs)  in  enumerate (group_names,1):     keys.append (Key ([Sup],str (i), Lazy.group[name].toscreen ( ))     keys.append (Key ([SUP, ' Shift '],str (i), Lazy.window.togroup (name))) #建立layoutslayouts =[     layout. Tile (border_focus= ' #196ff2 ', border_width=1),     layout. Max ()]font= ' Wenquanyi micro hei ' fontsize=16foreground= ' #FFFFFF ' background= ' #000000 ' def humanize _bytes (value):     suff=[' B ', ' K ', ' M ', ' G ', ' T ']    while value > 1024.  And len (Suff) >1:        value/=1024.         suff.pop (0)     return  "% 3s%s"  % ('%.3s '%value,suff[ 0]) #本来这个是用来显示CPU, Mem, net, and later somehow unable to show class metrics (Base._textbox):         defaults=[         (' font ', ' Arial ', ' Metrics font '),          (' FontSize ', None, ' metircs pixel size '),          (' pading ', None, ' metrics padding '),          (' background ', ' 00000 ', ' Background color '),          (' foreground ', ' ffffff ', ' Foreground color ')         ]     def __init__ (Self,**kwargs):         base._textbox.__init__ (Self,**kwargs)         self.cpu_usage,self.cpu_total=self.get_cpu_stat ()          self.interfaces={}         Self.idle_ifaces={}    def _configure (Self,qtile,bar):         base._textbox._configure (Self,qtile,bar)          Self.timeout_add (0,self._update)     def get_cpu_stat (self):         stat=[int (i)  for i in open ('/proc/stat '). ReadLine (). Split () [1:]]         return sum (Stat[:3]), SUM (STAT)     def  get_cpu_usage (self):         new_cpu_usage,new_cput_total= Self.get_cpu_stat ()         cput_usage=new_cpu_usage-self.cpu_usage         cpu_total=new_cpu_total-self.cpu_total        self.cpu_ usage=new_cpu_usage        self.cpu_tptal=new_cpu_total         return  ' cpu: %d%% '  %  (float (cpu_usage)/float (cpu_total ) *100.)     def get_mem_usage (self):         info={}         for line in open ('/proc/meminfo '):             key,val=line.split (': ')              info[key]=int (val.spilt () [0])          mem=info[' memtotal ']        mem-=info[' MemFree ']         mem-=info[' buffers ']        mem-=info[' Cached ']         return  ' mem: %d%% '  %  (float (Mem)/float ( info[' memtotal ') *100)     def get_net_usage (self):         interfaces=[]        basedir= '/sys/class/net '          for iface in os.listdir (Basedir):             j=os.path.join             ifacedir=j (Basedir,iface)              statdir=j (Ifacedir, ' statistics ')              idle=iface in self.idle_ifaces             try:                if int (Open (J ( ifacedir,  ' carrier ')). Read ()):                     rx = int (Open (J (statdir,  ' Rx_bytes ')). Read ())                      tx = int (Open (J (statdir,  ' Tx_bytes ')). Read ())                      if iface not  in self.interfaces:                         self.interfaces[iface] =  (Rx,  TX)                      old_rx, old_tx = self.interfaces[iface]                     self.interfaces[iface] =  (RX, TX)                       rx = rx - old_rx                     tx = tx - old_tx                     if  rx or tx:                         idle = False                          self.idle_ifaces[iface] = 0                         rx = humanize_bytes (RX)                           tx = humanize_bytes (TX)                          interfaces.append ('% s: %s / %s '  %  (IFACE, RX, TX)              except:                 pass            if  idle:                 Interfaces.append ('%s: %-11s '  %  (iface,  ("%ds idle"  % self.idle_ifaces[iface))                  )                  self.idle_ifaces[iface] += 1                 if self.idle_ifaces[iface]  > 30:                     del self.idle_ifaces[iface]        return   " | ". Join (interfaces)         def _update (self):         self.update ()          Self.timeout_add (1, self.update)         return False     Def update (self):         stat = [self.get_cpu_usage (),  self.get_mem_usage ()]        net = self.get_net_usage ( )         if net:             stat.append (NET)         self.text =  " | ". Join (STAT)         self.bar.draw ()          return truescreens=[    screen (Top=bar. Bar ([        widget. TextBox (text= ' ◤  ', fontsize=40,foreground= ' #323335 ', padding=0),         widget. GroupBox (font=font,fontsize=fontsize,active=foreground,inactive= "#808080", borderwidth=3),         widget. Prompt (Font=font,fontsize=fontsize),         widget. Currentlayout (font=font,foreground=foreground,fontsize=fontsize),         widget. Sep (foreground=background,linewidth=3),         widget. Windowname (Font=font,fontsize=fontsize,foreground=foreground),         Widgets. Notify (Font=font,fontsize=fontsize),         metrics (font=font,fontsize =fontsize,foreground=foreground),         widget. Volume (foreground= "#70ff70"),         widget. Batteryicon (),         widget. Systray (icon_size=18),         widget. Clock (font=font,fontsize=fontsize,foreground=foreground,fmt= '%y-%m-%d %a %h:%m '),     ],30)] @hook. subscribe.client_newdef dialogs (window):    if (Window.window.get_wm_type ()  ==  ' dialog '          or window.window.get_wm_transient_for ()):         Window.floating = true


This article from "Lotus's Thoughts" blog, please be sure to keep this source http://liandesinian.blog.51cto.com/7737219/1552667

The first experience of Linux window manager--qtile

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.