Skip to content

Instantly share code, notes, and snippets.

@SergKolo
Created July 3, 2016 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SergKolo/4c7201789df7b32b6c07015ca76ad051 to your computer and use it in GitHub Desktop.
Save SergKolo/4c7201789df7b32b6c07015ca76ad051 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from gi.repository import Gio,Notify
import dbus
import sys
import os
import time
import subprocess
def get_dbus(bus_type,obj,path,interface,method,arg):
# Reusable function for accessing dbus
# This basically works the same as
# dbus-send or qdbus. Just give it
# all the info, and it will spit out output
if bus_type == "session":
bus = dbus.SessionBus()
if bus_type == "system":
bus = dbus.SystemBus()
proxy = bus.get_object(obj,path)
method = proxy.get_dbus_method(method,interface)
return method(arg)
def run_sh(cmd):
# run shell commands
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
out = p.stdout.read().strip()
return out
# Ayatana display numbers start at 0
# Assuming there's at least one display active
# We get window stack at least once,for display 0.
# To find out if there is more displays , we need
# to test if any window stack is reported for them
# Basically this code below is a do-while loop.
counter = 0
window_list = get_dbus('session', 'org.ayatana.bamf',\
'/org/ayatana/bamf/matcher',\
'org.ayatana.bamf.matcher','WindowStackForMonitor',counter )
monitors = []
while window_list :
monitors.append(window_list)
#print "___Monitor #",counter,"____"
#print window_list
counter+=1
window_list = get_dbus('session', 'org.ayatana.bamf',\
'/org/ayatana/bamf/matcher',\
'org.ayatana.bamf.matcher','WindowStackForMonitor',counter )
print monitors
select_window = "xdotool selectwindow"
user_selection = run_sh(select_window)
count = 0
user_monitor = 0
for monitor in monitors:
#print "MONITOR #",count,":"
for window in monitor:
# extract XID of each window
# from the full path reported
# by the window string
if user_selection == window.split('/')[-1]:
user_monitor = count
#print
count+=1
print "User selected window on monitor", user_monitor
#monitors.pop(user_monitor)
#for monitor in monitors:
for window in monitors[user_monitor]:
run_sh( "xdotool windowminimize " + window.split('/')[-1] )
#print get_dbus('session', 'org.ayatana.bamf',\
# '/org/ayatana/bamf/matcher',\
# 'org.ayatana.bamf.matcher','WindowPaths', None )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment