-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti_screen.c
More file actions
132 lines (117 loc) · 4.03 KB
/
multi_screen.c
File metadata and controls
132 lines (117 loc) · 4.03 KB
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
/*
* GLOMP - transparent multipipe OpenGL
* Copyright (C) 2007 the GLOMP team (see AUTHORS)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "init.h"
#include "multi_screen.h"
#include "lib_funcs.h"
#include <X11/extensions/xf86vmode.h>
void multi_screen_init()
{
// nothing needed here
}
typedef struct {
Display *dpy;
int screen;
Window win;
GLXContext ctx;
XSetWindowAttributes attr;
Bool fs;
Bool doubleBuffered;
XF86VidModeModeInfo deskMode;
int x, y;
unsigned int width, height;
unsigned int depth;
} GLWindow;
static GLWindow GLWin;
void multi_screen_init_window(int* glxattribs)
{
if (client_num>0)
{
// create a window
// voir nehe lesson 02
XVisualInfo *vi;
Colormap cmap;
int glxMajorVersion, glxMinorVersion;
int vidModeMajorVersion, vidModeMinorVersion;
XF86VidModeModeInfo **modes;
int modeNum;
char envDisplay[16];
printf("creating win\n");
sprintf(envDisplay,":0.%d",client_num);
if (getenv("FORCE_GPU"))
sprintf(envDisplay,":0.0");
GLWin.fs = 0;
/* get a connection */
GLWin.dpy = lib_XOpenDisplay(envDisplay);
GLWin.screen = DefaultScreen(GLWin.dpy);
lib_XF86VidModeQueryVersion(GLWin.dpy, &vidModeMajorVersion,
&vidModeMinorVersion);
printf("XF86VidModeExtension-Version %d.%d\n", vidModeMajorVersion,
vidModeMinorVersion);
lib_XF86VidModeGetAllModeLines(GLWin.dpy, GLWin.screen, &modeNum, &modes);
/* use the desktop resolution */
GLWin.deskMode = *modes[0];
if (!getenv("FORCE_GPU"))
{
width=modes[0]->hdisplay;
height=modes[0]->vdisplay;
}
/* get an appropriate visual */
vi = lib_glXChooseVisual(GLWin.dpy, GLWin.screen, glxattribs);
lib_glXQueryVersion(GLWin.dpy, &glxMajorVersion, &glxMinorVersion);
printf("glX-Version %d.%d\n", glxMajorVersion, glxMinorVersion);
/* create a GLX context */
GLWin.ctx = lib_glXCreateContext(GLWin.dpy, vi, 0, GL_TRUE);
/* create a color map */
cmap = lib_XCreateColormap(GLWin.dpy, RootWindow(GLWin.dpy, vi->screen),
vi->visual, AllocNone);
GLWin.attr.colormap = cmap;
GLWin.attr.border_pixel = 0;
/* create a fullscreen window */
GLWin.attr.override_redirect = True;
GLWin.attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask |
StructureNotifyMask;
if (!getenv("FORCE_GPU"))
GLWin.win = lib_XCreateWindow(GLWin.dpy, RootWindow(GLWin.dpy, vi->screen),
0, 0, width, height, 0, vi->depth, InputOutput, vi->visual,
CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect, &GLWin.attr);
else
GLWin.win = lib_XCreateWindow(GLWin.dpy, RootWindow(GLWin.dpy, vi->screen),
0, 0, width, height, 0, vi->depth, InputOutput, vi->visual,
CWBorderPixel | CWColormap | CWEventMask, &GLWin.attr);
/* only set window title and handle wm_delete_events if in windowed mode */
//wmDelete = XInternAtom(GLWin.dpy, "WM_DELETE_WINDOW", True);
//XSetWMProtocols(GLWin.dpy, GLWin.win, &wmDelete, 1);
//XSetStandardProperties(GLWin.dpy, GLWin.win, title,
// title, None, NULL, 0, NULL);
lib_XMapRaised(GLWin.dpy, GLWin.win);
/* connect the glx-context to the window */
lib_glXMakeCurrent(GLWin.dpy, GLWin.win, GLWin.ctx);
}
}
void multi_screen_swap(Display *dpy, GLXDrawable drawable)
{
if (client_num>0)
lib_glXSwapBuffers(GLWin.dpy, GLWin.win);
else
lib_glXSwapBuffers(dpy, drawable);
}
void multi_screen_close()
{
lib_XCloseDisplay(GLWin.dpy);
}