diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-08-16 08:09:59 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-08-16 08:09:59 -0400 |
commit | 76ec9422a66c4ff59dc0590d80f7f6e931fd8e1a (patch) | |
tree | 914b01d7f01ea8b90397041dce2437305453aba2 | |
parent | Merge pull request #37 from Luminarys/master (diff) | |
parent | set userdata for handler to swayc_t container (diff) | |
download | sway-76ec9422a66c4ff59dc0590d80f7f6e931fd8e1a.tar.gz sway-76ec9422a66c4ff59dc0590d80f7f6e931fd8e1a.tar.zst sway-76ec9422a66c4ff59dc0590d80f7f6e931fd8e1a.zip |
Merge pull request #38 from taiyu-len/master
get/set_userdata stores swayc_t *, fixed memory leak, minor changes.
-rw-r--r-- | sway/container.c | 9 | ||||
-rw-r--r-- | sway/handlers.c | 28 | ||||
-rw-r--r-- | sway/layout.c | 6 | ||||
-rw-r--r-- | sway/log.h | 9 | ||||
-rw-r--r-- | sway/stringop.c | 27 | ||||
-rw-r--r-- | sway/workspace.c | 2 |
6 files changed, 49 insertions, 32 deletions
diff --git a/sway/container.c b/sway/container.c index 98941b2c..ff9c983a 100644 --- a/sway/container.c +++ b/sway/container.c | |||
@@ -31,6 +31,9 @@ static void free_swayc(swayc_t *c) { | |||
31 | } | 31 | } |
32 | remove_child(c->parent, c); | 32 | remove_child(c->parent, c); |
33 | } | 33 | } |
34 | if (c->name) { | ||
35 | free(c->name); | ||
36 | } | ||
34 | free(c); | 37 | free(c); |
35 | } | 38 | } |
36 | 39 | ||
@@ -51,8 +54,10 @@ swayc_t *new_output(wlc_handle handle) { | |||
51 | output->height = size->h; | 54 | output->height = size->h; |
52 | output->handle = handle; | 55 | output->handle = handle; |
53 | 56 | ||
54 | add_child(&root_container, output); | 57 | //link this to handler |
58 | wlc_handle_set_user_data(handle, output); | ||
55 | 59 | ||
60 | add_child(&root_container, output); | ||
56 | //TODO something with this | 61 | //TODO something with this |
57 | int total_width = 0; | 62 | int total_width = 0; |
58 | container_map(&root_container, add_output_widths, &total_width); | 63 | container_map(&root_container, add_output_widths, &total_width); |
@@ -135,6 +140,8 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) { | |||
135 | view->name = strdup(title); | 140 | view->name = strdup(title); |
136 | view->visible = true; | 141 | view->visible = true; |
137 | 142 | ||
143 | //Link view to handle | ||
144 | wlc_handle_set_user_data(handle, view); | ||
138 | //Case of focused workspace, just create as child of it | 145 | //Case of focused workspace, just create as child of it |
139 | if (sibling->type == C_WORKSPACE) { | 146 | if (sibling->type == C_WORKSPACE) { |
140 | add_child(sibling, view); | 147 | add_child(sibling, view); |
diff --git a/sway/handlers.c b/sway/handlers.c index 9944be33..af1fc98c 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -69,7 +69,7 @@ static void handle_output_destroyed(wlc_handle output) { | |||
69 | 69 | ||
70 | static void handle_output_resolution_change(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to) { | 70 | static void handle_output_resolution_change(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to) { |
71 | sway_log(L_DEBUG, "Output %d resolution changed to %d x %d", output, to->w, to->h); | 71 | sway_log(L_DEBUG, "Output %d resolution changed to %d x %d", output, to->w, to->h); |
72 | swayc_t *c = get_swayc_for_handle(output, &root_container); | 72 | swayc_t *c = wlc_handle_get_user_data(output); |
73 | if (!c) return; | 73 | if (!c) return; |
74 | c->width = to->w; | 74 | c->width = to->w; |
75 | c->height = to->h; | 75 | c->height = to->h; |
@@ -77,7 +77,7 @@ static void handle_output_resolution_change(wlc_handle output, const struct wlc_ | |||
77 | } | 77 | } |
78 | 78 | ||
79 | static void handle_output_focused(wlc_handle output, bool focus) { | 79 | static void handle_output_focused(wlc_handle output, bool focus) { |
80 | swayc_t *c = get_swayc_for_handle(output, &root_container); | 80 | swayc_t *c = wlc_handle_get_user_data(output); |
81 | if (!c) return; | 81 | if (!c) return; |
82 | if (focus) { | 82 | if (focus) { |
83 | unfocus_all(&root_container); | 83 | unfocus_all(&root_container); |
@@ -88,28 +88,28 @@ static void handle_output_focused(wlc_handle output, bool focus) { | |||
88 | static bool handle_view_created(wlc_handle handle) { | 88 | static bool handle_view_created(wlc_handle handle) { |
89 | swayc_t *focused = get_focused_container(&root_container); | 89 | swayc_t *focused = get_focused_container(&root_container); |
90 | swayc_t *view = new_view(focused, handle); | 90 | swayc_t *view = new_view(focused, handle); |
91 | //Leave unamanaged windows alone | ||
91 | if (view) { | 92 | if (view) { |
92 | //Set maximize flag for windows. | ||
93 | //TODO: floating windows have this unset | ||
94 | wlc_view_set_state(handle, WLC_BIT_MAXIMIZED, true); | ||
95 | unfocus_all(&root_container); | ||
96 | focus_view(view); | ||
97 | arrange_windows(view->parent, -1, -1); | 93 | arrange_windows(view->parent, -1, -1); |
98 | } else { //Unmanaged view | 94 | wlc_view_set_state(handle, WLC_BIT_MAXIMIZED, true); |
95 | if (!(wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN)) { | ||
96 | unfocus_all(&root_container); | ||
97 | focus_view(view); | ||
98 | } | ||
99 | else { | ||
100 | wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true); | ||
101 | wlc_view_focus(handle); | ||
102 | } | ||
103 | } else { | ||
99 | wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true); | 104 | wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true); |
100 | wlc_view_focus(handle); | 105 | wlc_view_focus(handle); |
101 | } | 106 | } |
102 | if (wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN) { | ||
103 | unfocus_all(&root_container); | ||
104 | focus_view(focused); | ||
105 | arrange_windows(focused, -1, -1); | ||
106 | } | ||
107 | return true; | 107 | return true; |
108 | } | 108 | } |
109 | 109 | ||
110 | static void handle_view_destroyed(wlc_handle handle) { | 110 | static void handle_view_destroyed(wlc_handle handle) { |
111 | sway_log(L_DEBUG, "Destroying window %d", handle); | 111 | sway_log(L_DEBUG, "Destroying window %d", handle); |
112 | swayc_t *view = get_swayc_for_handle(handle, &root_container); | 112 | swayc_t *view = wlc_handle_get_user_data(handle); |
113 | swayc_t *parent; | 113 | swayc_t *parent; |
114 | swayc_t *focused = get_focused_container(&root_container); | 114 | swayc_t *focused = get_focused_container(&root_container); |
115 | 115 | ||
diff --git a/sway/layout.c b/sway/layout.c index 918da9f0..8cf88be3 100644 --- a/sway/layout.c +++ b/sway/layout.c | |||
@@ -215,10 +215,10 @@ swayc_t *get_swayc_for_handle(wlc_handle handle, swayc_t *parent) { | |||
215 | } | 215 | } |
216 | 216 | ||
217 | swayc_t *get_focused_container(swayc_t *parent) { | 217 | swayc_t *get_focused_container(swayc_t *parent) { |
218 | if (parent->focused == NULL) { | 218 | while (parent->focused) { |
219 | return parent; | 219 | parent = parent->focused; |
220 | } | 220 | } |
221 | return get_focused_container(parent->focused); | 221 | return parent; |
222 | } | 222 | } |
223 | 223 | ||
224 | void unfocus_all(swayc_t *container) { | 224 | void unfocus_all(swayc_t *container) { |
@@ -1,6 +1,10 @@ | |||
1 | #ifndef _SWAY_LOG_H | 1 | #ifndef _SWAY_LOG_H |
2 | #define _SWAY_LOG_H | 2 | #define _SWAY_LOG_H |
3 | 3 | ||
4 | #ifndef __GNUC__ | ||
5 | # define __attribute__(x) | ||
6 | #endif | ||
7 | |||
4 | typedef enum { | 8 | typedef enum { |
5 | L_SILENT = 0, | 9 | L_SILENT = 0, |
6 | L_ERROR = 1, | 10 | L_ERROR = 1, |
@@ -8,9 +12,10 @@ typedef enum { | |||
8 | L_DEBUG = 3, | 12 | L_DEBUG = 3, |
9 | } log_importance_t; | 13 | } log_importance_t; |
10 | 14 | ||
15 | |||
11 | void init_log(int verbosity); | 16 | void init_log(int verbosity); |
12 | void sway_log_colors(int mode); | 17 | void sway_log_colors(int mode); |
13 | void sway_log(int verbosity, char* format, ...); | 18 | void sway_log(int verbosity, char* format, ...)__attribute__((format (printf,2,3))); |
14 | void sway_abort(char* format, ...); | 19 | void sway_abort(char* format, ...) __attribute__((format (printf,1,2))); |
15 | 20 | ||
16 | #endif | 21 | #endif |
diff --git a/sway/stringop.c b/sway/stringop.c index bbc0bcdf..450d5cd0 100644 --- a/sway/stringop.c +++ b/sway/stringop.c | |||
@@ -53,8 +53,9 @@ char *strip_comments(char *str) { | |||
53 | list_t *split_string(const char *str, const char *delims) { | 53 | list_t *split_string(const char *str, const char *delims) { |
54 | list_t *res = create_list(); | 54 | list_t *res = create_list(); |
55 | int i, j; | 55 | int i, j; |
56 | for (i = 0, j = 0; i < strlen(str) + 1; ++i) { | 56 | int len = strlen(str); |
57 | if (strchr(delims, str[i]) || i == strlen(str)) { | 57 | for (i = 0, j = 0; i < len + 1; ++i) { |
58 | if (strchr(delims, str[i]) || i == len) { | ||
58 | if (i - j == 0) { | 59 | if (i - j == 0) { |
59 | continue; | 60 | continue; |
60 | } | 61 | } |
@@ -63,7 +64,7 @@ list_t *split_string(const char *str, const char *delims) { | |||
63 | left[i - j] = 0; | 64 | left[i - j] = 0; |
64 | list_add(res, left); | 65 | list_add(res, left); |
65 | j = i + 1; | 66 | j = i + 1; |
66 | while (j <= strlen(str) && str[j] && strchr(delims, str[j])) { | 67 | while (j <= len && str[j] && strchr(delims, str[j])) { |
67 | j++; | 68 | j++; |
68 | i++; | 69 | i++; |
69 | } | 70 | } |
@@ -110,40 +111,44 @@ int unescape_string(char *string) { | |||
110 | for (i = 0; string[i]; ++i) { | 111 | for (i = 0; string[i]; ++i) { |
111 | if (string[i] == '\\') { | 112 | if (string[i] == '\\') { |
112 | --len; | 113 | --len; |
114 | int shift = 0; | ||
113 | switch (string[++i]) { | 115 | switch (string[++i]) { |
114 | case '0': | 116 | case '0': |
115 | string[i - 1] = '\0'; | 117 | string[i - 1] = '\0'; |
116 | memmove(string + i, string + i + 1, len - i); | 118 | shift = 1; |
117 | break; | 119 | break; |
118 | case 'a': | 120 | case 'a': |
119 | string[i - 1] = '\a'; | 121 | string[i - 1] = '\a'; |
120 | memmove(string + i, string + i + 1, len - i); | 122 | shift = 1; |
121 | break; | 123 | break; |
122 | case 'b': | 124 | case 'b': |
123 | string[i - 1] = '\b'; | 125 | string[i - 1] = '\b'; |
124 | memmove(string + i, string + i + 1, len - i); | 126 | shift = 1; |
125 | break; | 127 | break; |
126 | case 't': | 128 | case 't': |
127 | string[i - 1] = '\t'; | 129 | string[i - 1] = '\t'; |
128 | memmove(string + i, string + i + 1, len - i); | 130 | shift = 1; |
129 | break; | 131 | break; |
130 | case 'n': | 132 | case 'n': |
131 | string[i - 1] = '\n'; | 133 | string[i - 1] = '\n'; |
132 | memmove(string + i, string + i + 1, len - i); | 134 | shift = 1; |
133 | break; | 135 | break; |
134 | case 'v': | 136 | case 'v': |
135 | string[i - 1] = '\v'; | 137 | string[i - 1] = '\v'; |
136 | memmove(string + i, string + i + 1, len - i); | 138 | shift = 1; |
137 | break; | 139 | break; |
138 | case 'f': | 140 | case 'f': |
139 | string[i - 1] = '\f'; | 141 | string[i - 1] = '\f'; |
140 | memmove(string + i, string + i + 1, len - i); | 142 | shift = 1; |
141 | break; | 143 | break; |
142 | case 'r': | 144 | case 'r': |
143 | string[i - 1] = '\r'; | 145 | string[i - 1] = '\r'; |
144 | memmove(string + i, string + i + 1, len - i); | 146 | shift = 1; |
145 | break; | 147 | break; |
146 | } | 148 | } |
149 | if (shift) { | ||
150 | memmove(string + i, string + i + shift, len - i); | ||
151 | } | ||
147 | } | 152 | } |
148 | } | 153 | } |
149 | return len; | 154 | return len; |
diff --git a/sway/workspace.c b/sway/workspace.c index 49a1224f..a08877be 100644 --- a/sway/workspace.c +++ b/sway/workspace.c | |||
@@ -26,7 +26,7 @@ char *workspace_next_name(void) { | |||
26 | list_t *args = split_string(command, " "); | 26 | list_t *args = split_string(command, " "); |
27 | 27 | ||
28 | if (strcmp("workspace", args->items[0]) == 0 && args->length > 1) { | 28 | if (strcmp("workspace", args->items[0]) == 0 && args->length > 1) { |
29 | sway_log(L_DEBUG, "Got valid workspace command for target: '%s'", args->items[1]); | 29 | sway_log(L_DEBUG, "Got valid workspace command for target: '%s'", (char *)args->items[1]); |
30 | char* target = malloc(strlen(args->items[1]) + 1); | 30 | char* target = malloc(strlen(args->items[1]) + 1); |
31 | strcpy(target, args->items[1]); | 31 | strcpy(target, args->items[1]); |
32 | while (*target == ' ' || *target == '\t') | 32 | while (*target == ' ' || *target == '\t') |