summaryrefslogtreecommitdiff
path: root/src/wireframe.c
blob: e97fe46be2a2a4312173f1ec73abb86f3c09e0b8 (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
/*      $Id$

        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, 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.

        You should have received a copy of the GNU General Public License
        along with this program; if not, write to the Free Software
        Foundation, Inc., Inc., 51 Franklin Street, Fifth Floor, Boston,
        MA 02110-1301, USA.


        metacity - (c) 2001 Anders Carlsson, Havoc Pennington
        xfwm4    - (c) 2002-2010 Olivier Fourdan

 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/extensions/shape.h>
#include <glib.h>
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
#include <libxfce4util/libxfce4util.h>

#include "screen.h"
#include "client.h"
#include "frame.h"
#include "wireframe.h"

#ifndef OUTLINE_WIDTH
#define OUTLINE_WIDTH 5
#endif

void
wireframeUpdate (Client *c, Window xwindow)
{
    ScreenInfo *screen_info;

    g_return_if_fail (c != NULL);
    g_return_if_fail (xwindow != None);

    TRACE ("entering wireframeUpdate 0x%lx", xwindow);
    screen_info = c->screen_info;
    XUnmapWindow (clientGetXDisplay (c), xwindow);
    XMoveResizeWindow (clientGetXDisplay (c), xwindow,
                       frameX (c), frameY (c), frameWidth (c), frameHeight (c));

    if ((frameWidth (c) > OUTLINE_WIDTH * 2) && (frameHeight (c) > OUTLINE_WIDTH * 2))
    {
        XRectangle xrect;
        Region inner_xregion;
        Region outer_xregion;

        inner_xregion = XCreateRegion ();
        outer_xregion = XCreateRegion ();

        xrect.x = 0;
        xrect.y = 0;
        xrect.width = frameWidth (c);
        xrect.height = frameHeight (c);
        XUnionRectWithRegion (&xrect, outer_xregion, outer_xregion);

        xrect.x += OUTLINE_WIDTH;
        xrect.y += OUTLINE_WIDTH;
        xrect.width -= OUTLINE_WIDTH * 2;
        xrect.height -= OUTLINE_WIDTH * 2;

        XUnionRectWithRegion (&xrect, inner_xregion, inner_xregion);

        XSubtractRegion (outer_xregion, inner_xregion, outer_xregion);

        XShapeCombineRegion (clientGetXDisplay (c), xwindow, ShapeBounding,
                             0, 0, outer_xregion, ShapeSet);

        XDestroyRegion (outer_xregion);
        XDestroyRegion (inner_xregion);
        XMapWindow (clientGetXDisplay (c), xwindow);

        XDrawRectangle (clientGetXDisplay (c), xwindow,
                        gdk_x11_gc_get_xgc (screen_info->white_gc),
                        0, 0, frameWidth (c) - 1, frameHeight (c) - 1);

        XDrawRectangle (clientGetXDisplay (c), xwindow,
                        gdk_x11_gc_get_xgc (screen_info->white_gc),
                        OUTLINE_WIDTH - 1, OUTLINE_WIDTH - 1,
                        frameWidth (c) - 2 * (OUTLINE_WIDTH - 1) - 1,
                        frameHeight (c)- 2 * (OUTLINE_WIDTH - 1) - 1);
    }
    else
    {
        /* Unset the shape */
        XShapeCombineMask (clientGetXDisplay (c), xwindow,
                           ShapeBounding, 0, 0, None, ShapeSet);
        XMapWindow (clientGetXDisplay (c), xwindow);

        XDrawRectangle (clientGetXDisplay (c), xwindow,
                        gdk_x11_gc_get_xgc (screen_info->white_gc),
                        0, 0, frameWidth (c) - 1, frameHeight (c) - 1);
    }
    XFlush (clientGetXDisplay (c));
}

Window
wireframeCreate (Client *c)
{
    ScreenInfo *screen_info;
    XSetWindowAttributes attrs;
    Window xwindow;

    g_return_val_if_fail (c != NULL, None);

    TRACE ("entering wireframeCreate");

    screen_info = c->screen_info;
    attrs.override_redirect = True;
    attrs.background_pixel = BlackPixel (clientGetXDisplay (c),
                                         screen_info->screen);
    xwindow = XCreateWindow (clientGetXDisplay (c),
                             screen_info->xroot,
                             frameX (c), frameY (c),
                             frameWidth (c), frameHeight (c),
                             0, CopyFromParent, CopyFromParent,
                             (Visual *) CopyFromParent,
                             CWOverrideRedirect | CWBackPixel, &attrs);
    wireframeUpdate (c, xwindow);

    return (xwindow);
}

void
wireframeDelete (ScreenInfo *screen_info, Window xwindow)
{
    g_return_if_fail (screen_info != NULL);
    g_return_if_fail (xwindow != None);

    TRACE ("entering wireframeDelete 0x%lx", xwindow);
    XUnmapWindow (myScreenGetXDisplay (screen_info), xwindow);
    XDestroyWindow (myScreenGetXDisplay (screen_info), xwindow);
}