~ubuntu-branches/ubuntu/precise/libproxy/precise

« back to all changes in this revision

Viewing changes to src/modules/xhasclient.c

  • Committer: Package Import Robot
  • Author(s): Iain Lane, Iain Lane, Ken VanDine
  • Date: 2012-02-15 14:42:54 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20120215144254-j6n30mds0s3solv3
Tags: 0.4.7-0ubuntu1
[ Iain Lane ]
* New upstream release.
* Convert to dh7.
* SONAME bump, rename packages accordingly
* Remove obsolete patches
* Add CLI/Vala bindings.
* Also install vala bindings (in -dev package)
* Update Standards-Version to 3.9.2
* Split modules into individual packages
* Link with --as-needed to avoid unnecessary deps
* Update copyright
* Make library multiarch compatible

[ Ken VanDine ]
* Build against libmozjs185.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *
3
 
 * 
4
 
Copyright 1989, 1998  The Open Group
5
 
 
6
 
Permission to use, copy, modify, distribute, and sell this software and its
7
 
documentation for any purpose is hereby granted without fee, provided that
8
 
the above copyright notice appear in all copies and that both that
9
 
copyright notice and this permission notice appear in supporting
10
 
documentation.
11
 
 
12
 
The above copyright notice and this permission notice shall be included in
13
 
all copies or substantial portions of the Software.
14
 
 
15
 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
18
 
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19
 
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
 
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
 
 
22
 
Except as contained in this notice, the name of The Open Group shall not be
23
 
used in advertising or otherwise to promote the sale, use or other dealings
24
 
in this Software without prior written authorization from The Open Group.
25
 
 * *
26
 
 * Author:  Jim Fulton, MIT X Consortium
27
 
 */
28
 
 
29
 
/*
30
 
 * Concept and some basic code shamelessly stolen from xlsclients... :)
31
 
 * Reworked by Nathaniel McCallum, 2007
32
 
 */
33
 
 
34
 
#include <stdbool.h>
35
 
#include <stdarg.h>
36
 
#include <string.h>
37
 
 
38
 
#include <X11/Xlib.h>
39
 
#include <X11/Xmu/WinUtil.h>
40
 
 
41
 
bool
42
 
x_has_client(char *prog, ...)
43
 
{
44
 
        va_list ap;
45
 
        
46
 
        // Open display
47
 
        Display *display = XOpenDisplay(NULL);
48
 
        if (!display)
49
 
                return false;
50
 
        
51
 
        // For each screen...
52
 
        for (int i=0; i < ScreenCount(display); i++)
53
 
        {
54
 
                Window dummy, *children = NULL;
55
 
                unsigned int nchildren = 0;
56
 
                
57
 
                // Get the root window's children
58
 
                if (!XQueryTree(display, RootWindow(display, i), &dummy, &dummy, &children, &nchildren))
59
 
                        continue;
60
 
                
61
 
                // For each child on the screen...
62
 
            for (int j=0; j < nchildren; j++)
63
 
            {
64
 
                // If we can get their client info...
65
 
                Window client;
66
 
                if ((client = XmuClientWindow(display, children[j])) != None)
67
 
                {
68
 
                        int argc;
69
 
                        char **argv;
70
 
                        
71
 
                        // ... and if we can find out their command ...
72
 
                        if (!XGetCommand (display, client, &argv, &argc) || argc == 0)
73
 
                                continue;
74
 
                        
75
 
                        // ... check the commands against our list
76
 
                        va_start(ap, prog);
77
 
                        for (char *s = prog ; s ; s = va_arg(ap, char *))
78
 
                        {
79
 
                                // We've found a match, return...
80
 
                                if (!strcmp(argv[0], s))
81
 
                                {
82
 
                                        va_end(ap);
83
 
                                        XCloseDisplay(display);
84
 
                                        return true;
85
 
                                }
86
 
                        }
87
 
                        va_end(ap);
88
 
                }
89
 
            }
90
 
        }
91
 
        
92
 
        // Close the display
93
 
        XCloseDisplay(display);
94
 
        return false;
95
 
}