Skip to content

Commit

Permalink
#775 some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Jan 25, 2021
1 parent a5feed0 commit d8926f9
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 53 deletions.
17 changes: 10 additions & 7 deletions src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ void display_serialize(FILE *rsp, uint32_t did)
int count;
uint64_t *space_list = display_space_list(did, &count);
if (space_list) {
int first_mci = space_manager_mission_control_index(space_list[0]);
for (int i = 0; i < count; ++i) {
if (i < count - 1) {
bytes_written = snprintf(cursor, buffer_size, "%d, ", space_manager_mission_control_index(space_list[i]));
bytes_written = snprintf(cursor, buffer_size, "%d, ", first_mci + i);
} else {
bytes_written = snprintf(cursor, buffer_size, "%d", space_manager_mission_control_index(space_list[i]));
bytes_written = snprintf(cursor, buffer_size, "%d", first_mci + i);
}

cursor += bytes_written;
Expand All @@ -53,12 +54,14 @@ void display_serialize(FILE *rsp, uint32_t did)
"\t\"id\":%d,\n"
"\t\"uuid\":\"%s\",\n"
"\t\"index\":%d,\n"
"\t\"spaces\":[%s],\n"
"\t\"frame\":{\n\t\t\"x\":%.4f,\n\t\t\"y\":%.4f,\n\t\t\"w\":%.4f,\n\t\t\"h\":%.4f\n\t}\n"
"\t\"frame\":{\n\t\t\"x\":%.4f,\n\t\t\"y\":%.4f,\n\t\t\"w\":%.4f,\n\t\t\"h\":%.4f\n\t},\n"
"\t\"spaces\":[%s]\n"
"}",
did, uuid ? uuid : "<unknown>", display_arrangement(did), buffer,
frame.origin.x, frame.origin.y,
frame.size.width, frame.size.height);
did,
uuid ? uuid : "<unknown>",
display_arrangement(did),
frame.origin.x, frame.origin.y, frame.size.width, frame.size.height,
buffer);
}

CFStringRef display_uuid(uint32_t did)
Expand Down
4 changes: 2 additions & 2 deletions src/event_signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,15 @@ static void event_signal_serialize(FILE *rsp, struct signal *signal, enum signal
"\t\"label\":\"%s\",\n"
"\t\"app\":\"%s\",\n"
"\t\"title\":\"%s\",\n"
"\t\"active\":\"%d\",\n"
"\t\"active\":%s,\n"
"\t\"event\":\"%s\",\n"
"\t\"action\":\"%s\"\n"
"}",
index,
signal->label ? signal->label : "",
signal->app ? signal->app : "",
signal->title ? signal->title : "",
signal_prop[signal->active],
json_optional_bool(signal->active),
signal_type_str[type],
escaped_action ? escaped_action : signal->command ? signal->command : "");
}
Expand Down
7 changes: 0 additions & 7 deletions src/event_signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,6 @@ static const char *signal_type_str[] =
#define SIGNAL_PROP_YES 1
#define SIGNAL_PROP_NO 2

static int signal_prop[] =
{
[SIGNAL_PROP_UD] = -1,
[SIGNAL_PROP_NO] = 0,
[SIGNAL_PROP_YES] = 1,
};

struct event_signal
{
enum signal_type type;
Expand Down
15 changes: 13 additions & 2 deletions src/misc/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@

const CFStringRef kAXEnhancedUserInterface = CFSTR("AXEnhancedUserInterface");

static inline char *json_optional_bool(int value)
{
if (value == 0) return "null";
if (value == 1) return "true";

return "false";
}

static inline char *json_bool(bool value)
{
return value ? "true" : "false";
}

static const char *bool_str[] = { "off", "on" };

static const char *layer_str[] =
Expand Down Expand Up @@ -145,7 +158,6 @@ static inline char *ts_cfstring_copy(CFStringRef string)
{
CFIndex num_bytes = CFStringGetMaximumSizeForEncoding(CFStringGetLength(string), kCFStringEncodingUTF8);
char *result = ts_alloc(num_bytes + 1);
if (!result) return NULL;

if (!CFStringGetCString(string, result, num_bytes + 1, kCFStringEncodingUTF8)) {
result = NULL;
Expand All @@ -172,7 +184,6 @@ static inline char *ts_string_copy(char *s)
{
int length = strlen(s);
char *result = ts_alloc(length + 1);
if (!result) return NULL;

memcpy(result, s, length);
result[length] = '\0';
Expand Down
32 changes: 16 additions & 16 deletions src/rule.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,32 @@ void rule_serialize(FILE *rsp, struct rule *rule, int index)
"\t\"label\":\"%s\",\n"
"\t\"app\":\"%s\",\n"
"\t\"title\":\"%s\",\n"
"\t\"display_id\":%d,\n"
"\t\"space_id\":%lld,\n"
"\t\"follow_space\":%d,\n"
"\t\"display\":%d,\n"
"\t\"space\":%d,\n"
"\t\"follow_space\":%s,\n"
"\t\"opacity\":%.4f,\n"
"\t\"manage\":%d,\n"
"\t\"sticky\":%d,\n"
"\t\"mouse_follows_focus\":%d,\n"
"\t\"manage\":%s,\n"
"\t\"sticky\":%s,\n"
"\t\"mouse_follows_focus\":%s,\n"
"\t\"layer\":\"%s\",\n"
"\t\"border\":%d,\n"
"\t\"native-fullscreen\":%d,\n"
"\t\"border\":%s,\n"
"\t\"native-fullscreen\":%s,\n"
"\t\"grid\":\"%d:%d:%d:%d:%d:%d\"\n"
"}",
index,
rule->label ? rule->label : "",
rule->app ? rule->app : "",
rule->title ? rule->title : "",
rule->did,
rule->sid,
rule->follow_space,
display_arrangement(rule->did),
space_manager_mission_control_index(rule->sid),
json_bool(rule->follow_space),
rule->alpha,
rule_prop[rule->manage],
rule_prop[rule->sticky],
rule_prop[rule->mff],
json_optional_bool(rule->manage),
json_optional_bool(rule->sticky),
json_optional_bool(rule->mff),
layer_str[rule->layer],
rule_prop[rule->border],
rule_prop[rule->fullscreen],
json_optional_bool(rule->border),
json_optional_bool(rule->fullscreen),
rule->grid[0], rule->grid[1],
rule->grid[2], rule->grid[3],
rule->grid[4], rule->grid[5]);
Expand Down
7 changes: 0 additions & 7 deletions src/rule.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
#define RULE_PROP_ON 1
#define RULE_PROP_OFF 2

static int rule_prop[] =
{
[RULE_PROP_UD] = -1,
[RULE_PROP_OFF] = 0,
[RULE_PROP_ON] = 1,
};

struct rule
{
char *label;
Expand Down
27 changes: 15 additions & 12 deletions src/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ void view_flush(struct view *view)

void view_serialize(FILE *rsp, struct view *view)
{
char *uuid = ts_cfstring_copy(view->suuid);
int buffer_size = MAXLEN;
size_t bytes_written = 0;
char buffer[MAXLEN] = {};
Expand Down Expand Up @@ -761,28 +762,30 @@ void view_serialize(FILE *rsp, struct view *view)
fprintf(rsp,
"{\n"
"\t\"id\":%lld,\n"
"\t\"label\":\"%s\",\n"
"\t\"uuid\":\"%s\",\n"
"\t\"index\":%d,\n"
"\t\"label\":\"%s\",\n"
"\t\"type\":\"%s\",\n"
"\t\"display\":%d,\n"
"\t\"windows\":[%s],\n"
"\t\"type\":\"%s\",\n"
"\t\"visible\":%d,\n"
"\t\"focused\":%d,\n"
"\t\"native-fullscreen\":%d,\n"
"\t\"first-window\":%d,\n"
"\t\"last-window\":%d\n"
"\t\"last-window\":%d,\n"
"\t\"has-focus\":%s,\n"
"\t\"is-visible\":%s,\n"
"\t\"is-native-fullscreen\":%s\n"
"}",
view->sid,
space_label ? space_label->label : "",
uuid ? uuid : "<unknown>",
space_manager_mission_control_index(view->sid),
space_label ? space_label->label : "",
view_type_str[view->layout],
display_arrangement(space_display_id(view->sid)),
buffer,
view_type_str[view->layout],
space_is_visible(view->sid),
view->sid == g_space_manager.current_space_id,
space_is_fullscreen(view->sid),
first_leaf ? first_leaf->window_order[0] : 0,
last_leaf ? last_leaf->window_order[0] : 0);
last_leaf ? last_leaf->window_order[0] : 0,
json_bool(space_is_visible(view->sid)),
json_bool(view->sid == g_space_manager.current_space_id),
json_bool(space_is_fullscreen(view->sid)));
}

void view_update(struct view *view)
Expand Down

0 comments on commit d8926f9

Please sign in to comment.