-
Notifications
You must be signed in to change notification settings - Fork 1
/
gstwlutils.c
149 lines (135 loc) · 3.62 KB
/
gstwlutils.c
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
139
140
141
142
143
144
145
146
147
148
149
/* GStreamer Wayland video sink
*
* Copyright 2018 NXP
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <math.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <ctype.h>
#include "gstwlutils.h"
#define WESTON_INI "/etc/xdg/weston/weston.ini"
gboolean
gst_wl_init_surface_state (GstWlDisplay * display, GstWlWindow * self)
{
gchar path[] = WESTON_INI;
gchar line[512], *p, *section = NULL, *size = NULL;
gint fd, n, i;
gint desktop_width, desktop_height;
gint display_width, display_height;
gboolean found_config = FALSE;
gboolean ret = TRUE;
struct stat filestat;
FILE *fp;
if ((fd = open (path, O_RDONLY)) == -1) {
return FALSE;
}
if (fstat (fd, &filestat) < 0 || !S_ISREG (filestat.st_mode)) {
close (fd);
return FALSE;
}
fp = fdopen (fd, "r");
if (fp == NULL) {
close (fd);
return FALSE;
}
while (fgets (line, sizeof line, fp)) {
if (found_config)
break;
switch (line[0]) {
case '#':
case '\n':
continue;
case '[':
p = strchr (&line[1], ']');
if (!p || p[1] != '\n') {
continue;
}
p[0] = '\0';
if (section)
g_free (section);
section = g_strdup (&line[1]);
continue;
default:
if (section && strcmp (section, "shell") == 0) {
p = strchr (line, '=');
if (!p || p == line) {
continue;
}
p[0] = '\0';
if (strcmp (&line[0], "size") == 0) {
p++;
while (isspace (*p))
p++;
i = strlen (p);
while (i > 0 && isspace (p[i - 1])) {
p[i - 1] = '\0';
i--;
}
if (strlen (p) > 0) {
if (size)
g_free (size);
size = g_strdup (p);
found_config = TRUE;
}
}
}
continue;
}
}
if (found_config && size) {
n = sscanf (size, "%dx%d\n", &desktop_width, &desktop_height);
if (n != 2) {
ret = FALSE;
goto out;
}
} else {
ret = FALSE;
goto out;
}
/* FIXME: only support buffer scale 2 and 1 */
display_width = gst_wl_display_get_width (display);
display_height = gst_wl_display_get_height (display);
if (display_width > 0 && display_height > 0) {
gst_wl_window_set_scale (self, display_width / desktop_width);
if (gst_wl_window_get_scale (self) != 1 && gst_wl_window_get_scale (self) != 2) {
ret = FALSE;
goto out;
}
gst_wl_window_set_fullscreen_width (self, desktop_width);
gst_wl_window_set_fullscreen_height (self, desktop_height - PANEL_HEIGH);
} else {
ret = FALSE;
goto out;
}
out:
if (section)
g_free (section);
if (size)
g_free (size);
fclose (fp);
return ret;
}