all repos — openbox @ eeba44c0d42131e8d6ac1265ce38a74e86ac5ae0

openbox fork - make it a bit more like ryudo

openbox/propwin.c (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
   
   propwin.c for the Openbox window manager
   Copyright (c) 2006        Mikael Magnusson
   Copyright (c) 2003-2007   Dana Jansens

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   See the COPYING file for a copy of the GNU General Public License.
*/

#include "propwin.h"
#include "openbox.h"
#include "client.h"
#include "debug.h"

typedef struct _ObPropWin     ObPropWin;
typedef struct _ObPropWinData ObPropWinData;

struct _ObPropWinData
{
    GSList *clients;
};

struct _ObPropWin
{
    Window win;
    ObPropWinData data[OB_NUM_PROPWIN_TYPES];
};

/*! A hash table that maps a window to an ObPropWin */
static GHashTable *propwin_map;

static guint window_hash(Window *w) { return *w; }
static gboolean window_comp(Window *w1, Window *w2) { return *w1 == *w2; }

void propwin_startup(gboolean reconfig)
{
    if (!reconfig)
        propwin_map = g_hash_table_new_full((GHashFunc)window_hash,
                                             (GEqualFunc)window_comp,
                                             NULL,
                                             g_free);
}

void propwin_shutdown(gboolean reconfig)
{
    if (!reconfig)
        g_hash_table_destroy(propwin_map);
    else
        g_assert(g_hash_table_size(propwin_map) == 0);
}

void propwin_add(Window win, ObPropWinType type, ObClient *client)
{
    ObPropWin *p;

    if (!win) return;

    g_assert(client);
    g_assert(type < OB_NUM_PROPWIN_TYPES);

    p = g_hash_table_lookup(propwin_map, &win);
    if (!p) {
        p = g_new0(ObPropWin, 1);
        p->win = win;
        g_hash_table_insert(propwin_map, &p->win, p);
        /* get property changes on this window */
        XSelectInput(ob_display, win, PropertyChangeMask);
    } else
        g_assert(g_slist_find(p->data[type].clients, client) == NULL);

    if (p->data[type].clients != NULL)
        ob_debug("Client %s is using a property window 0x%x that is already "
                 "in use\n", client->title, win);

    /* add it to the clients list */
    p->data[type].clients = g_slist_prepend(p->data[type].clients, client);
}

void propwin_remove(Window win, ObPropWinType type, ObClient *client)
{
    ObPropWin *p;

    if (!win) return;

    p = g_hash_table_lookup(propwin_map, &win);
    g_assert(p);

    /* remove it to the clients list */
    g_assert(g_slist_find(p->data[type].clients, client) != NULL);
    p->data[type].clients = g_slist_remove(p->data[type].clients, client);

    /* no more clients left for this type */
    if (p->data[type].clients == NULL) {
        guint i;
        gboolean none = TRUE;

        for (i = 0; i < OB_NUM_PROPWIN_TYPES; ++i)
            if (p->data[i].clients != NULL)
                none = FALSE; /* another type still has a client for this
                                 window */

        if (none) {
            /* don't get events for this window any more */
            XSelectInput(ob_display, win, NoEventMask);
            g_hash_table_remove(propwin_map, &win);
        }
    }
}

GSList* propwin_get_clients(Window win, ObPropWinType type)
{
    ObPropWin *p = g_hash_table_lookup(propwin_map, &win);
    if (p)
        return p->data[type].clients;
    else
        return NULL;
}