1 /*
2                                     __
3                                    / _|
4   __ _ _   _ _ __ ___  _ __ __ _  | |_ ___  ___ ___
5  / _` | | | | '__/ _ \| '__/ _` | |  _/ _ \/ __/ __|
6 | (_| | |_| | | | (_) | | | (_| | | || (_) \__ \__ \
7  \__,_|\__,_|_|  \___/|_|  \__,_| |_| \___/|___/___/
8 
9 Copyright (C) 2018-2019 Aurora Free Open Source Software.
10 
11 This file is part of the Aurora Free Open Source Software. This
12 organization promote free and open source software that you can
13 redistribute and/or modify under the terms of the GNU Lesser General
14 Public License Version 3 as published by the Free Software Foundation or
15 (at your option) any later version approved by the Aurora Free Open Source
16 Software Organization. The license is available in the package root path
17 as 'LICENSE' file. Please review the following information to ensure the
18 GNU Lesser General Public License version 3 requirements will be met:
19 https://www.gnu.org/licenses/lgpl.html .
20 
21 Alternatively, this file may be used under the terms of the GNU General
22 Public License version 3 or later as published by the Free Software
23 Foundation. Please review the following information to ensure the GNU
24 General Public License requirements will be met:
25 http://www.gnu.org/licenses/gpl-3.0.html.
26 
27 NOTE: All products, services or anything associated to trademarks and
28 service marks used or referenced on this file are the property of their
29 respective companies/owners or its subsidiaries. Other names and brands
30 may be claimed as the property of others.
31 
32 For more info about intellectual property visit: aurorafoss.org or
33 directly send an email to: contact (at) aurorafoss.org .
34 */
35 
36 module aurorafw.gui.api.x11.window;
37 
38 import aurorafw.gui.window : Window;
39 import X = aurorafw.gui.platform.x11;
40 
41 class X11Window : Window {
42 	struct VisualPreferences
43 	{
44 		X.Visual* visual = null;
45 		uint depth;
46 	}
47 
48 	import aurorafw.gui.api.backend : Backend;
49 	import aurorafw.gui.api.x11.backend : X11Backend;
50 	this(VisualPreferences vpref = VisualPreferences())
51 	{
52 		_backend = cast(X11Backend)Backend.get();
53 
54 		if(vpref.visual is null)
55 			vpref.visual = X.XDefaultVisual(_backend.display, _backend.screen);
56 
57 		{
58 			X.XSetWindowAttributes _watt;
59 			_watt.border_pixel = 0;
60 			_watt.event_mask = X.StructureNotifyMask | X.KeyPressMask | X.KeyReleaseMask |
61 				X.PointerMotionMask | X.ButtonPressMask | X.ButtonReleaseMask |
62 				X.ExposureMask | X.FocusChangeMask | X.VisibilityChangeMask |
63 				X.EnterWindowMask | X.LeaveWindowMask | X.PropertyChangeMask;
64 
65 			_handle = X.XCreateWindow(
66 					_backend.display,
67 					_backend.root,
68 					0,
69 					0,
70 					_wp.width,
71 					_wp.height,
72 					0,
73 					_wp.depth,
74 					X.InputOutput,
75 					vpref.visual,
76 					(X.CWBorderPixel | X.CWColormap | X.CWEventMask),
77 					&_watt);
78 		}
79 		X.XSelectInput(_backend.display, _handle, X.ExposureMask | X.KeyPressMask);
80 		X.XMapWindow(_backend.display, _handle);
81 		import std.string;
82 		X.XStoreName(_backend.display, _handle, _name.toStringz());
83 	}
84 
85 	import aurorafw.core.input.manager;
86 	override void pollEvents(InputManager inmanager = InputManager())
87 	{
88 		X.XPending(_backend.display);
89 		while (X.XQLength(_backend.display))
90 		{
91 			X.XEvent e;
92 			X.XNextEvent(_backend.display, &e);
93 
94 			import aurorafw.core.input.events;
95 			import aurorafw.gui.api.x11.input;
96 			switch(e.type)
97 			{
98 				case X.KeyPress:
99 					inmanager.keyPressed(KeyboardEvent(translateKeycodeX11(e.xkey.keycode), translateInputModifierX11(e.xkey.state)));
100 					break;
101 
102 				case X.KeyRelease:
103 					inmanager.keyReleased(KeyboardEvent(translateKeycodeX11(e.xkey.keycode), translateInputModifierX11(e.xkey.state)));
104 					break;
105 
106 				case X.ButtonPress:
107 					inmanager.mousePressed(MouseButtonEvent(translateInputButtonX11(e.xbutton.state), translateInputModifierX11(e.xbutton.state)));
108 					break;
109 
110 				case X.ButtonRelease:
111 					inmanager.mouseReleased(MouseButtonEvent(translateInputButtonX11(e.xbutton.state), translateInputModifierX11(e.xbutton.state)));
112 					break;
113 
114 				default: break;
115 			}
116 		}
117 	}
118 
119 	~this()
120 	{
121 
122 	}
123 
124 private:
125 	X.Window _handle;
126 	X.Colormap _colormap;
127 	X11Backend _backend;
128 }