aboutsummaryrefslogtreecommitdiff
path: root/src/screen.c
blob: cc2b8fdf545c7150c2ddb1883f0ec28caf4b37db (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
/****************************************************************************
 * Screen functions.
 * Copyright (C) 2005 Joe Wingbermuehle
 ****************************************************************************/

#include "jwm.h"
#include "screen.h"
#include "main.h"
#include "cursor.h"

static ScreenType *screens;
static int screenCount;

/****************************************************************************
 ****************************************************************************/
void InitializeScreens() {
	screens = NULL;
}

/****************************************************************************
 ****************************************************************************/
void StartupScreens() {
#ifdef USE_XINERAMA

	XineramaScreenInfo *info;
	int x;

	if(XineramaIsActive(display)) {

		info = XineramaQueryScreens(display, &screenCount);

		screens = Allocate(sizeof(ScreenType) * screenCount);
		for(x = 0; x < screenCount; x++) {
			screens[x].index = x;
			screens[x].x = info[x].x_org;
			screens[x].y = info[x].y_org;
			screens[x].width = info[x].width;
			screens[x].height = info[x].height;
		}

		JXFree(info);

	} else {

		screenCount = 1;
		screens = Allocate(sizeof(ScreenType));
		screens->index = 0;
		screens->x = 0;
		screens->y = 0;
		screens->width = rootWidth;
		screens->height = rootHeight;

	}

#else

	screenCount = 1;
	screens = Allocate(sizeof(ScreenType));
	screens->index = 0;
	screens->x = 0;
	screens->y = 0;
	screens->width = rootWidth;
	screens->height = rootHeight;

#endif /* USE_XINERAMA */
}

/****************************************************************************
 ****************************************************************************/
void ShutdownScreens() {
	if(screens) {
		Release(screens);
		screens = NULL;
	}
}

/****************************************************************************
 ****************************************************************************/
void DestroyScreens() {
}

/****************************************************************************
 ****************************************************************************/
const ScreenType *GetCurrentScreen(int x, int y) {

	ScreenType *sp;
	int index;

	for(index = 1; index < screenCount; index++) {
		sp = &screens[index];
		if(x >= sp->x && x < sp->x + sp->width) {
			if(y >= sp->y && y <= sp->y + sp->height) {
				return sp;
			}
		}
	}

	return &screens[0];

}

/****************************************************************************
 ****************************************************************************/
const ScreenType *GetMouseScreen() {
#ifdef USE_XINERAMA

	int x, y;

	GetMousePosition(&x, &y);
	return GetCurrentScreen(x, y);

#else

	return &screens[0];

#endif
}

/****************************************************************************
 ****************************************************************************/
const ScreenType *GetScreen(int index) {

	Assert(index >= 0);
	Assert(index < screenCount);

	return &screens[index];

}

/****************************************************************************
 ****************************************************************************/
int GetScreenCount() {

	return screenCount;

}