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
|
/*
* Trivial GL demo; switches surface states. Showing how simple life is with eglapp.
*
* Copyright © 2014 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* 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, see <http://www.gnu.org/licenses/>.
*
* Author: Alan Griffiths <alan@octopull.co.uk>
*/
#include "eglapp.h"
#include <mir_toolkit/mir_client_library.h>
#include <stdio.h>
#include <unistd.h>
#include <GLES2/gl2.h>
static void toggle_surface_state(MirSurface* const surface, MirSurfaceState* state);
typedef struct Color
{
GLfloat r, g, b, a;
} Color;
int main(int argc, char *argv[])
{
float const opacity = mir_eglapp_background_opacity;
Color const orange = {0.866666667f, 0.282352941f, 0.141414141f, opacity};
unsigned int width = 120, height = 120;
if (!mir_eglapp_init(argc, argv, &width, &height, NULL))
return 1;
MirSurface* const surface = mir_eglapp_native_surface();
MirSurfaceState state = mir_surface_get_state(surface);
/* This is probably the simplest GL you can do */
while (mir_eglapp_running())
{
glClearColor(orange.r, orange.g, orange.b, orange.a);
glClear(GL_COLOR_BUFFER_BIT);
mir_eglapp_swap_buffers();
sleep(2);
toggle_surface_state(surface, &state);
}
mir_eglapp_cleanup();
return 0;
}
#define NEW_STATE(new_state)\
puts("Requesting state: " #new_state);\
*state = new_state
#define PRINT_STATE(state)\
case state:\
puts("Current state: " #state);\
break
void toggle_surface_state(MirSurface* const surface, MirSurfaceState* state)
{
switch (mir_surface_get_state(surface))
{
PRINT_STATE(mir_surface_state_unknown);
PRINT_STATE(mir_surface_state_restored);
PRINT_STATE(mir_surface_state_minimized);
PRINT_STATE(mir_surface_state_fullscreen);
PRINT_STATE(mir_surface_state_maximized);
PRINT_STATE(mir_surface_state_vertmaximized);
PRINT_STATE(mir_surface_state_horizmaximized);
default:
puts("Current state: unknown");
}
switch (*state)
{
case mir_surface_state_restored:
NEW_STATE(mir_surface_state_unknown);
break;
case mir_surface_state_minimized:
NEW_STATE(mir_surface_state_restored);
break;
case mir_surface_state_fullscreen:
NEW_STATE(mir_surface_state_vertmaximized);
break;
case mir_surface_state_maximized:
NEW_STATE(mir_surface_state_fullscreen);
break;
case mir_surface_state_vertmaximized:
NEW_STATE(mir_surface_state_horizmaximized);
break;
case mir_surface_state_horizmaximized:
NEW_STATE(mir_surface_state_minimized);
break;
default:
NEW_STATE(mir_surface_state_maximized);
break;
}
mir_surface_set_state(surface, *state);
}
|