| 1 |
/* |
| 2 |
* vim:ts=4:sw=4:expandtab |
| 3 |
* |
| 4 |
* i3bar - an xcb-based status- and ws-bar for i3 |
| 5 |
* © 2010 Axel Wagner and contributors (see also: LICENSE) |
| 6 |
* |
| 7 |
* child.c: Getting input for the statusline |
| 8 |
* |
| 9 |
*/ |
| 10 |
#pragma once |
| 11 |
|
| 12 |
#include <config.h> |
| 13 |
|
| 14 |
#include <ev.h> |
| 15 |
|
| 16 |
#define STDIN_CHUNK_SIZE 1024 |
| 17 |
|
| 18 |
typedef struct { |
| 19 |
pid_t pid; |
| 20 |
|
| 21 |
/** |
| 22 |
* The version number is an uint32_t to avoid machines with different sizes of |
| 23 |
* 'int' to allow different values here. It’s highly unlikely we ever exceed |
| 24 |
* even an int8_t, but still… |
| 25 |
*/ |
| 26 |
uint32_t version; |
| 27 |
|
| 28 |
bool stopped; |
| 29 |
/** |
| 30 |
* The signal requested by the client to inform it of the hidden state of i3bar |
| 31 |
*/ |
| 32 |
int stop_signal; |
| 33 |
/** |
| 34 |
* The signal requested by the client to inform it of the unhidden state of i3bar |
| 35 |
*/ |
| 36 |
int cont_signal; |
| 37 |
|
| 38 |
/** |
| 39 |
* Enable click events |
| 40 |
*/ |
| 41 |
bool click_events; |
| 42 |
bool click_events_init; |
| 43 |
|
| 44 |
/** |
| 45 |
* stdin- and SIGCHLD-watchers |
| 46 |
*/ |
| 47 |
ev_io *stdin_io; |
| 48 |
ev_child *child_sig; |
| 49 |
int stdin_fd; |
| 50 |
|
| 51 |
/** |
| 52 |
* Line read from child that did not include a newline character. |
| 53 |
*/ |
| 54 |
char *pending_line; |
| 55 |
} i3bar_child; |
| 56 |
|
| 57 |
/* |
| 58 |
* Remove all blocks from the given statusline. |
| 59 |
* If free_resources is set, the fields of each status block will be free'd. |
| 60 |
*/ |
| 61 |
void clear_statusline(struct statusline_head *head, bool free_resources); |
| 62 |
|
| 63 |
/* |
| 64 |
* Start a child process with the specified command and reroute stdin. |
| 65 |
* We actually start a shell to execute the command so we don't have to care |
| 66 |
* about arguments and such. |
| 67 |
* |
| 68 |
* If `command' is NULL, such as in the case when no `status_command' is given |
| 69 |
* in the bar config, no child will be started. |
| 70 |
* |
| 71 |
*/ |
| 72 |
void start_child(char *command); |
| 73 |
|
| 74 |
/* |
| 75 |
* Same as start_child but starts the configured client that manages workspace |
| 76 |
* buttons. |
| 77 |
* |
| 78 |
*/ |
| 79 |
void start_ws_child(char *command); |
| 80 |
|
| 81 |
/* |
| 82 |
* Returns true if the status child process is alive. |
| 83 |
* |
| 84 |
*/ |
| 85 |
bool status_child_is_alive(void); |
| 86 |
|
| 87 |
/* |
| 88 |
* Returns true if the workspace child process is alive. |
| 89 |
* |
| 90 |
*/ |
| 91 |
bool ws_child_is_alive(void); |
| 92 |
|
| 93 |
/* |
| 94 |
* kill()s the child process (if any). Called when exit()ing. |
| 95 |
* |
| 96 |
*/ |
| 97 |
void kill_children_at_exit(void); |
| 98 |
|
| 99 |
/* |
| 100 |
* kill()s the child process (if any) and closes and free()s the stdin- and |
| 101 |
* SIGCHLD-watchers |
| 102 |
* |
| 103 |
*/ |
| 104 |
void kill_child(void); |
| 105 |
|
| 106 |
/* |
| 107 |
* kill()s the workspace child process (if any) and closes and free()s the |
| 108 |
* stdin- and SIGCHLD-watchers. |
| 109 |
* Similar to kill_child. |
| 110 |
* |
| 111 |
*/ |
| 112 |
void kill_ws_child(void); |
| 113 |
|
| 114 |
/* |
| 115 |
* Sends a SIGSTOP to the child process (if existent) |
| 116 |
* |
| 117 |
*/ |
| 118 |
void stop_children(void); |
| 119 |
|
| 120 |
/* |
| 121 |
* Sends a SIGCONT to the child process (if existent) |
| 122 |
* |
| 123 |
*/ |
| 124 |
void cont_children(void); |
| 125 |
|
| 126 |
/* |
| 127 |
* Whether or not the child want click events |
| 128 |
* |
| 129 |
*/ |
| 130 |
bool child_want_click_events(void); |
| 131 |
|
| 132 |
/* |
| 133 |
* Generates a click event, if enabled. |
| 134 |
* |
| 135 |
*/ |
| 136 |
void send_block_clicked(int button, const char *name, const char *instance, int x, int y, int x_rel, int y_rel, int out_x, int out_y, int width, int height, int mods); |
| 137 |
|
| 138 |
/* |
| 139 |
* When workspace_command is enabled this function is used to re-parse the |
| 140 |
* latest received JSON from the client. |
| 141 |
*/ |
| 142 |
void repeat_last_ws_json(void); |
| 143 |
|
| 144 |
/* |
| 145 |
* Replaces the workspace buttons with an error message. |
| 146 |
*/ |
| 147 |
void set_workspace_button_error(const char *message); |