aboutsummaryrefslogtreecommitdiff
path: root/src/window.c
blob: fb0ae90c0d38caf9e32237091f3bbc769190dc10 (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
/* See LICENSE file for copyright and license details. */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "application.h"
#include "window.h"

CherryWindow *
cherry_window_new(void)
{
	CherryWindow *w = malloc(sizeof(*w));
	w->title = NULL;
	w->dimension = cherry_dimension_new();
	w->x = 0;
	w->y = 0;

	CherryApplication *app = cherry_application_get_running_app();

	int offset = 10;
	int border_width = 5;
	XSizeHints hints;
	hints.x      = w->x + offset;
	hints.y      = w->y + offset;
	hints.width  = w->dimension->width  + offset;
	hints.height = w->dimension->height + offset;
	hints.flags  = PPosition|PSize;

	XSetWindowAttributes attributes;
	attributes.background_pixel = XWhitePixel(app->display, app->screen);

	w->window_handler = XCreateWindow(app->display,
	                                  XRootWindow(app->display, app->screen),
	                                  hints.x,     hints.y,
	                                  hints.width, hints.height,
	                                  border_width,
	                                  app->depth,
	                                  InputOutput,
	                                  app->visual,
	                                  CWBackPixel,
	                                  &attributes);
	char window_name[] = "";
	char icon_name[]   = "";
	XSetStandardProperties(app->display,
	                       w->window_handler,
	                       window_name,
	                       icon_name,
	                       None, NULL, 0,
	                       &hints);

	clist_add(&(app->windows), w, sizeof(*w));

	return w;
}

char *
cherry_window_get_title(CherryWindow *w)
{
	char *wnd_name;
	CherryApplication *app = cherry_application_get_running_app();
	XFetchName(app->display, w->window_handler, &wnd_name);

	return wnd_name;
}

void
cherry_window_set_title(CherryWindow *w, char *title)
{
	w->title = strdup(title);

	CherryApplication *app = cherry_application_get_running_app();
	XStoreName(app->display, w->window_handler, w->title);
}

void
cherry_window_set_dimension(CherryWindow *w, int width, int height)
{
	w->dimension->width  = width;
	w->dimension->height = height;
}

void
cherry_window_set_position(CherryWindow *w, int x, int y)
{
	w->x = x;
	w->y = y;
}

void
cherry_window_set_visible(CherryWindow *w, int visible)
{
	CherryApplication *app = cherry_application_get_running_app();

	if (visible) {
		XMapRaised(app->display, w->window_handler);
	}
}