summaryrefslogtreecommitdiff
path: root/src/mywindow.c
blob: b7e7d3e6da584a28873ae571001edb0dc743ac3a (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
/*
        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; You may only use version 2 of the License,
        you have no option to use any other 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., 675 Mass Ave, Cambridge, MA 02139, USA.
 
        xfwm4    - (c) 2003 Olivier Fourdan
 
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <glib.h>
#include <stdlib.h>
#include <stdio.h>
#include <glib.h>
#include "mywindow.h"
#include "main.h"
#include "debug.h"

void myWindowCreate(Display * dpy, Window parent, myWindow * win, Cursor cursor)
{
    DBG("entering myWindowCreate\n");

    win->window = XCreateSimpleWindow(dpy, parent, 0, 0, 1, 1, 0, 0, 0);
    DBG("Created XID 0x%lx\n", win->window);
    if(cursor != None)
    {
        XDefineCursor(dpy, win->window, cursor);
    }
    win->map = FALSE;
    win->dpy = dpy;
    win->x = 0;
    win->y = 0;
    win->w = 1;
    win->h = 1;
}

void myWindowDelete(myWindow * win)
{
    DBG("entering myWindowDelete\n");

    if(win->window != None)
    {
        XDestroyWindow(win->dpy, win->window);
        win->window = None;
    }
    win->map = FALSE;
}

void myWindowShow(myWindow * win, int x, int y, int width, int height, gboolean refresh)
{
    DBG("entering myWindowShow\n");

    if(!(win->window))
    {
        return;
    }
    if((width < 1) || (height < 1))
    {
        myWindowHide(win);
        return;
    }
    if(!(win->map))
    {
        XMapWindow(win->dpy, win->window);
        win->map = TRUE;
    }
    DBG("Showing XID 0x%lx\n", win->window);
    if(((x != win->x) || (y != win->y)) && ((width != win->w) || (height != win->h)))
    {
        XMoveResizeWindow(win->dpy, win->window, x, y, (unsigned int)width, (unsigned int)height);
        win->x = x;
        win->y = y;
        win->w = width;
        win->h = height;
    }
    else if((x != win->x) || (y != win->y))
    {
        XMoveWindow(win->dpy, win->window, x, y);
        if(refresh)
        {
            XClearWindow(win->dpy, win->window);
        }
        win->x = x;
        win->y = y;
    }
    else if((width != win->w) || (height != win->h))
    {
        XResizeWindow(win->dpy, win->window, (unsigned int)width, (unsigned int)height);
        win->w = width;
        win->h = height;
    }
    else if(refresh)
    {
        XClearWindow(win->dpy, win->window);
    }
}

void myWindowHide(myWindow * win)
{
    DBG("entering myWindowHide\n");

    if(win->map)
    {
        XUnmapWindow(win->dpy, win->window);
        win->map = FALSE;
    }
}