-
Notifications
You must be signed in to change notification settings - Fork 136
/
mode.c
41 lines (36 loc) · 863 Bytes
/
mode.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
#include <stdlib.h>
#include <string.h>
#include <wayland-util.h>
#include "mako.h"
#include "mode.h"
bool has_mode(struct mako_state *state, const char *mode) {
const char **mode_ptr;
wl_array_for_each(mode_ptr, &state->current_modes) {
if (strcmp(*mode_ptr, mode) == 0) {
return true;
}
}
return false;
}
void set_modes(struct mako_state *state, const char **modes, size_t modes_len) {
char **mode_ptr;
wl_array_for_each(mode_ptr, &state->current_modes) {
free(*mode_ptr);
}
state->current_modes.size = 0;
for (size_t i = 0; i < modes_len; i++) {
// Drop duplicate entries
bool dup = false;
for (size_t j = 0; j < i; j++) {
if (strcmp(modes[i], modes[j]) == 0) {
dup = true;
break;
}
}
if (dup) {
continue;
}
char **dst = wl_array_add(&state->current_modes, sizeof(char *));
*dst = strdup(modes[i]);
}
}