2
Copyright 2014 Canonical Ltd.
4
This program is free software: you can redistribute it and/or modify it
5
under the terms of the GNU General Public License version 3, as published
6
by the Free Software Foundation.
8
This program is distributed in the hope that it will be useful, but
9
WITHOUT ANY WARRANTY; without even the implied warranties of
10
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along
14
with this program. If not, see <http://www.gnu.org/licenses/>.
17
// Package windowstack retrieves information about the windowstack
18
// using Unity's dbus interface
22
"launchpad.net/ubuntu-push/bus"
23
"launchpad.net/ubuntu-push/click"
24
"launchpad.net/ubuntu-push/logger"
27
// Well known address for the WindowStack API
28
var BusAddress bus.Address = bus.Address{
29
Interface: "com.canonical.Unity.WindowStack",
30
Path: "/com/canonical/Unity/WindowStack",
31
Name: "com.canonical.Unity.WindowStack",
34
type WindowsInfo struct {
36
AppId string // in the form "com.ubuntu.calendar_calendar" or "webbrowser-app"
41
// WindowStack encapsulates info needed to call out to the WindowStack API
42
type WindowStack struct {
47
// New returns a new WindowStack that'll use the provided bus.Endpoint
48
func New(endp bus.Endpoint, log logger.Logger) *WindowStack {
49
return &WindowStack{endp, log}
52
// GetWindowStack returns the window stack state
53
func (stack *WindowStack) GetWindowStack() []WindowsInfo {
54
var wstack []WindowsInfo
55
err := stack.bus.Call("GetWindowStack", bus.Args(), &wstack)
57
stack.log.Errorf("GetWindowStack call returned %v", err)
62
func (stack *WindowStack) IsAppFocused(AppId *click.AppId) bool {
63
for _, winfo := range stack.GetWindowStack() {
64
if winfo.Focused && winfo.AppId == AppId.Base() {