diff options
author | 2015-08-16 08:10:56 -0400 | |
---|---|---|
committer | 2015-08-16 08:10:56 -0400 | |
commit | ae536c21d3bcab7758f4a47cbf4556c518245a7b (patch) | |
tree | cc8ffeb1d52d770548fd99a9d0b7bbef18f90ead /sway | |
parent | Merge pull request #38 from taiyu-len/master (diff) | |
download | sway-ae536c21d3bcab7758f4a47cbf4556c518245a7b.tar.gz sway-ae536c21d3bcab7758f4a47cbf4556c518245a7b.tar.zst sway-ae536c21d3bcab7758f4a47cbf4556c518245a7b.zip |
Revert "get/set_userdata stores swayc_t *, fixed memory leak, minor changes."
Diffstat (limited to 'sway')
-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, 32 insertions, 49 deletions
diff --git a/sway/container.c b/sway/container.c index ff9c983a..98941b2c 100644 --- a/sway/container.c +++ b/sway/container.c | |||
@@ -31,9 +31,6 @@ 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 | } | ||
37 | free(c); | 34 | free(c); |
38 | } | 35 | } |
39 | 36 | ||
@@ -54,10 +51,8 @@ swayc_t *new_output(wlc_handle handle) { | |||
54 | output->height = size->h; | 51 | output->height = size->h; |
55 | output->handle = handle; | 52 | output->handle = handle; |
56 | 53 | ||
57 | //link this to handler | ||
58 | wlc_handle_set_user_data(handle, output); | ||
59 | |||
60 | add_child(&root_container, output); | 54 | add_child(&root_container, output); |
55 | |||
61 | //TODO something with this | 56 | //TODO something with this |
62 | int total_width = 0; | 57 | int total_width = 0; |
63 | container_map(&root_container, add_output_widths, &total_width); | 58 | container_map(&root_container, add_output_widths, &total_width); |
@@ -140,8 +135,6 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) { | |||
140 | view->name = strdup(title); | 135 | view->name = strdup(title); |
141 | view->visible = true; | 136 | view->visible = true; |
142 | 137 | ||
143 | //Link view to handle | ||
144 | wlc_handle_set_user_data(handle, view); | ||
145 | //Case of focused workspace, just create as child of it | 138 | //Case of focused workspace, just create as child of it |
146 | if (sibling->type == C_WORKSPACE) { | 139 | if (sibling->type == C_WORKSPACE) { |
147 | add_child(sibling, view); | 140 | add_child(sibling, view); |
diff --git a/sway/handlers.c b/sway/handlers.c index af1fc98c..9944be33 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 = wlc_handle_get_user_data(output); | 72 | swayc_t *c = get_swayc_for_handle(output, &root_container); |
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 = wlc_handle_get_user_data(output); | 80 | swayc_t *c = get_swayc_for_handle(output, &root_container); |
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 | ||
92 | if (view) { | 91 | if (view) { |
93 | arrange_windows(view->parent, -1, -1); | 92 | //Set maximize flag for windows. |
93 | //TODO: floating windows have this unset | ||
94 | wlc_view_set_state(handle, WLC_BIT_MAXIMIZED, true); | 94 | wlc_view_set_state(handle, WLC_BIT_MAXIMIZED, true); |
95 | if (!(wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN)) { | 95 | unfocus_all(&root_container); |
96 | unfocus_all(&root_container); | 96 | focus_view(view); |
97 | focus_view(view); | 97 | arrange_windows(view->parent, -1, -1); |
98 | } | 98 | } else { //Unmanaged view |
99 | else { | ||
100 | wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true); | ||
101 | wlc_view_focus(handle); | ||
102 | } | ||
103 | } else { | ||
104 | wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true); | 99 | wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true); |
105 | wlc_view_focus(handle); | 100 | wlc_view_focus(handle); |
106 | } | 101 | } |
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 = wlc_handle_get_user_data(handle); | 112 | swayc_t *view = get_swayc_for_handle(handle, &root_container); |
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 8cf88be3..918da9f0 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 | while (parent->focused) { | 218 | if (parent->focused == NULL) { |
219 | parent = parent->focused; | 219 | return parent; |
220 | } | 220 | } |
221 | return parent; | 221 | return get_focused_container(parent->focused); |
222 | } | 222 | } |
223 | 223 | ||
224 | void unfocus_all(swayc_t *container) { | 224 | void unfocus_all(swayc_t *container) { |
@@ -1,10 +1,6 @@ | |||
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 | |||
8 | typedef enum { | 4 | typedef enum { |
9 | L_SILENT = 0, | 5 | L_SILENT = 0, |
10 | L_ERROR = 1, | 6 | L_ERROR = 1, |
@@ -12,10 +8,9 @@ typedef enum { | |||
12 | L_DEBUG = 3, | 8 | L_DEBUG = 3, |
13 | } log_importance_t; | 9 | } log_importance_t; |
14 | 10 | ||
15 | |||
16 | void init_log(int verbosity); | 11 | void init_log(int verbosity); |
17 | void sway_log_colors(int mode); | 12 | void sway_log_colors(int mode); |
18 | void sway_log(int verbosity, char* format, ...)__attribute__((format (printf,2,3))); | 13 | void sway_log(int verbosity, char* format, ...); |
19 | void sway_abort(char* format, ...) __attribute__((format (printf,1,2))); | 14 | void sway_abort(char* format, ...); |
20 | 15 | ||
21 | #endif | 16 | #endif |
diff --git a/sway/stringop.c b/sway/stringop.c index 450d5cd0..bbc0bcdf 100644 --- a/sway/stringop.c +++ b/sway/stringop.c | |||
@@ -53,9 +53,8 @@ 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 | int len = strlen(str); | 56 | for (i = 0, j = 0; i < strlen(str) + 1; ++i) { |
57 | for (i = 0, j = 0; i < len + 1; ++i) { | 57 | if (strchr(delims, str[i]) || i == strlen(str)) { |
58 | if (strchr(delims, str[i]) || i == len) { | ||
59 | if (i - j == 0) { | 58 | if (i - j == 0) { |
60 | continue; | 59 | continue; |
61 | } | 60 | } |
@@ -64,7 +63,7 @@ list_t *split_string(const char *str, const char *delims) { | |||
64 | left[i - j] = 0; | 63 | left[i - j] = 0; |
65 | list_add(res, left); | 64 | list_add(res, left); |
66 | j = i + 1; | 65 | j = i + 1; |
67 | while (j <= len && str[j] && strchr(delims, str[j])) { | 66 | while (j <= strlen(str) && str[j] && strchr(delims, str[j])) { |
68 | j++; | 67 | j++; |
69 | i++; | 68 | i++; |
70 | } | 69 | } |
@@ -111,44 +110,40 @@ int unescape_string(char *string) { | |||
111 | for (i = 0; string[i]; ++i) { | 110 | for (i = 0; string[i]; ++i) { |
112 | if (string[i] == '\\') { | 111 | if (string[i] == '\\') { |
113 | --len; | 112 | --len; |
114 | int shift = 0; | ||
115 | switch (string[++i]) { | 113 | switch (string[++i]) { |
116 | case '0': | 114 | case '0': |
117 | string[i - 1] = '\0'; | 115 | string[i - 1] = '\0'; |
118 | shift = 1; | 116 | memmove(string + i, string + i + 1, len - i); |
119 | break; | 117 | break; |
120 | case 'a': | 118 | case 'a': |
121 | string[i - 1] = '\a'; | 119 | string[i - 1] = '\a'; |
122 | shift = 1; | 120 | memmove(string + i, string + i + 1, len - i); |
123 | break; | 121 | break; |
124 | case 'b': | 122 | case 'b': |
125 | string[i - 1] = '\b'; | 123 | string[i - 1] = '\b'; |
126 | shift = 1; | 124 | memmove(string + i, string + i + 1, len - i); |
127 | break; | 125 | break; |
128 | case 't': | 126 | case 't': |
129 | string[i - 1] = '\t'; | 127 | string[i - 1] = '\t'; |
130 | shift = 1; | 128 | memmove(string + i, string + i + 1, len - i); |
131 | break; | 129 | break; |
132 | case 'n': | 130 | case 'n': |
133 | string[i - 1] = '\n'; | 131 | string[i - 1] = '\n'; |
134 | shift = 1; | 132 | memmove(string + i, string + i + 1, len - i); |
135 | break; | 133 | break; |
136 | case 'v': | 134 | case 'v': |
137 | string[i - 1] = '\v'; | 135 | string[i - 1] = '\v'; |
138 | shift = 1; | 136 | memmove(string + i, string + i + 1, len - i); |
139 | break; | 137 | break; |
140 | case 'f': | 138 | case 'f': |
141 | string[i - 1] = '\f'; | 139 | string[i - 1] = '\f'; |
142 | shift = 1; | 140 | memmove(string + i, string + i + 1, len - i); |
143 | break; | 141 | break; |
144 | case 'r': | 142 | case 'r': |
145 | string[i - 1] = '\r'; | 143 | string[i - 1] = '\r'; |
146 | shift = 1; | 144 | memmove(string + i, string + i + 1, len - i); |
147 | break; | 145 | break; |
148 | } | 146 | } |
149 | if (shift) { | ||
150 | memmove(string + i, string + i + shift, len - i); | ||
151 | } | ||
152 | } | 147 | } |
153 | } | 148 | } |
154 | return len; | 149 | return len; |
diff --git a/sway/workspace.c b/sway/workspace.c index a08877be..49a1224f 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'", (char *)args->items[1]); | 29 | sway_log(L_DEBUG, "Got valid workspace command for target: '%s'", 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') |