summaryrefslogtreecommitdiff
path: root/toggledeco.c
blob: 31b2d92a8289a644b6f044ae9c625db320fd13f8 (plain)
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
 * Compiz Fusion Toggle-decoration plugin
 *
 * Copyright (c) 2008 Marco Diego Aurélio Mesquita <marcodiegomesquita@gmail.com>
 *
 * 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.
 *
 * Author(s):
 * Eduardo Gurgel Pinho <edgurgel@gmail.com>
 * Marco Diego Mesquita <marcodiegomesquita@gmail.com>
 *
 * Description:
 *
 * Toggles decorations of windows on/off.
 *
 */

#include <compiz-core.h>
#include "toggledeco_options.h"

/* 
 * Initially triggered keybinding.
 * Fetch the window and toggles its decoration.
 */
static Bool
toggledecoTrigger(CompDisplay     *d,
		  CompAction      *action,
		  CompActionState state,
		  CompOption      *option,
		  int             nOption)
{
    Window     xid;
    CompWindow *w;

    xid = getIntOptionNamed (option, nOption, "window", 0);
    w   = findWindowAtDisplay (d, xid);
    if (w)
    {
	w->mwmDecor = w->mwmDecor ^ MwmDecorAll;
	(*w->screen->windowStateChangeNotify) (w, w->state);
    }

    return TRUE;
}

/*
 * Testing if two windows are on the same viewport
 */

static Bool
toggledecoSameViewport(CompWindow* w1,
		       CompWindow* w2)
{
    int x1,x2,y1,y2;

    defaultViewportForWindow (w1,&x1,&y1);
    defaultViewportForWindow (w2,&x2,&y2);
    return ((x1 == x2) && (y1 == y2));
}

/* 
 * Initially triggered keybinding.
 * Fetch the every window and toggles its decoration.
 */
static Bool
toggledecoAllTrigger(CompDisplay     *d,
		     CompAction      *action,
		     CompActionState state,
		     CompOption      *option,
		     int             nOption)
{
    Window     xid;
    CompWindow *w;

    xid = getIntOptionNamed (option, nOption, "window", 0);
    w   = findWindowAtDisplay (d, xid);
    if (w)
    {
	CompScreen *s = w->screen;
	CompWindow *window;
	for (window = s->windows; window; window = window->next)
    	{
	    if(!toggledecoSameViewport (window,w)) continue;
	       window->mwmDecor = window->mwmDecor ^ MwmDecorAll;
	       (*window->screen->windowStateChangeNotify) (window, window->state);
	}
    }

    return TRUE;
}

/* Configuration, initialization, boring stuff. --------------------- */
static Bool
toggledecoInitDisplay (CompPlugin  *p,
		       CompDisplay *d)
{
    if (!checkPluginABI ("core", CORE_ABIVERSION))
	return FALSE;

    toggledecoSetTriggerKeyInitiate (d, toggledecoTrigger);
    toggledecoSetTriggerAllKeyInitiate (d, toggledecoAllTrigger);

    return TRUE;
}

static CompBool
toggledecoInitObject (CompPlugin *p,
		      CompObject *o)
{
    static InitPluginObjectProc dispTab[] = {
	(InitPluginObjectProc) 0, /* InitCore */
	(InitPluginObjectProc) toggledecoInitDisplay,
	0, 
	0 
    };

    RETURN_DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), TRUE, (p, o));
}

static void
toggledecoFiniObject (CompPlugin *p,
		      CompObject *o)
{
    static FiniPluginObjectProc dispTab[] = {
	(FiniPluginObjectProc) 0, /* FiniCore */
	0, 
	0, 
	0 
    };

    DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), (p, o));
}

CompPluginVTable toggledecoVTable = {
    "toggledeco",
    0,
    0,
    0,
    toggledecoInitObject,
    toggledecoFiniObject,
    0,
    0
};

CompPluginVTable*
getCompPluginInfo (void)
{
    return &toggledecoVTable;
}