19 #include <xcb/xcb_event.h> 21 #include <X11/keysym.h> 31 "To debug this problem, either attach gdb now",
33 "- 'b' to save a backtrace (needs GDB),",
34 "- 'r' to restart i3 in-place or",
35 "- 'f' to forget the current layout and restart"};
45 char *tmpdir = getenv(
"TMPDIR");
49 pid_t pid_parent = getpid();
51 char *filename = NULL;
58 sasprintf(&filename,
"%s/i3-backtrace.%d.%d.txt", tmpdir, pid_parent, suffix);
60 }
while (stat(filename, &bt) == 0);
62 pid_t pid_gdb = fork();
64 DLOG(
"Failed to fork for GDB\n");
66 }
else if (pid_gdb == 0) {
71 if (pipe(stdin_pipe) == -1) {
72 ELOG(
"Failed to init stdin_pipe\n");
75 if (pipe(stdout_pipe) == -1) {
76 ELOG(
"Failed to init stdout_pipe\n");
90 dup2(stdin_pipe[0], STDIN_FILENO);
91 dup2(stdout_pipe[1], STDOUT_FILENO);
93 char *pid_s, *gdb_log_cmd;
95 sasprintf(&gdb_log_cmd,
"set logging file %s", filename);
105 "-ex",
"set logging on",
109 execvp(args[0], args);
110 DLOG(
"Failed to exec GDB\n");
115 waitpid(pid_gdb, &status, 0);
118 if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
119 DLOG(
"GDB did not run properly\n");
121 }
else if (stat(filename, &bt) == -1) {
122 DLOG(
"GDB executed successfully, but no backtrace was generated\n");
134 xcb_rectangle_t border = {0, 0,
width, height},
135 inner = {2, 2, width - 4, height - 4};
144 char *bt_colour =
"#FFFFFF";
146 bt_colour =
"#AA0000";
148 bt_colour =
"#00AA00";
150 for (
int i = 0; crash_text_i3strings[i] != NULL; ++i) {
156 8, 5 + i * font_height, width - 16);
175 uint16_t
state =
event->state;
182 xcb_keysym_t sym = xcb_key_press_lookup_keysym(
keysyms, event, state);
185 DLOG(
"User issued core-dump command.\n");
209 xcb_window_t win = xcb_generate_id(conn);
214 mask |= XCB_CW_BACK_PIXEL;
217 mask |= XCB_CW_OVERRIDE_REDIRECT;
221 uint32_t
x = screen_rect.
x + ((screen_rect.
width / 2) - (width / 2)),
222 y = screen_rect.
y + ((screen_rect.
height / 2) - (height / 2));
224 xcb_create_window(conn,
225 XCB_COPY_FROM_PARENT,
230 XCB_WINDOW_CLASS_INPUT_OUTPUT,
231 XCB_WINDOW_CLASS_COPY_FROM_PARENT,
236 xcb_map_window(conn, win);
243 int crash_text_num =
sizeof(
crash_text) /
sizeof(
char *);
246 int crash_text_length =
sizeof(
crash_text) /
sizeof(
char *);
249 for (
int i = 0; i < crash_text_length; ++i) {
252 crash_text_i3strings[crash_text_length] = NULL;
255 int width = font_width + 20;
272 xcb_grab_keyboard(
conn,
false, win, XCB_CURRENT_TIME, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
275 xcb_grab_pointer(
conn,
false, win, XCB_NONE, XCB_GRAB_MODE_ASYNC,
276 XCB_GRAB_MODE_ASYNC, win, XCB_NONE, XCB_CURRENT_TIME);
290 DLOG(
"i3 crashed. SIG: %d\n", sig);
292 struct sigaction action;
293 action.sa_handler = SIG_DFL;
294 sigaction(sig, &action, NULL);
299 xcb_generic_event_t *event;
301 while ((event = xcb_wait_for_event(
conn))) {
303 int type = (
event->response_type & 0x7F);
304 if (type == XCB_KEY_PRESS) {
316 struct sigaction action;
319 action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
320 sigemptyset(&action.sa_mask);
323 if (sigaction(SIGQUIT, &action, NULL) == -1 ||
324 sigaction(SIGILL, &action, NULL) == -1 ||
325 sigaction(SIGABRT, &action, NULL) == -1 ||
326 sigaction(SIGFPE, &action, NULL) == -1 ||
327 sigaction(SIGSEGV, &action, NULL) == -1)
328 ELOG(
"Could not setup signal handler.\n");
void draw_text(i3String *text, xcb_drawable_t drawable, xcb_gcontext_t gc, xcb_visualtype_t *visual, int x, int y, int max_width)
Draws text onto the specified X drawable (normally a pixmap) at the specified coordinates (from the t...
uint32_t get_colorpixel(const char *hex) __attribute__((const))
Returns the colorpixel to use for the given hex color (think of HTML).
struct outputs_head outputs
static int crash_text_longest
static void open_popups(void)
void set_font_colors(xcb_gcontext_t gc, color_t foreground, color_t background)
Defines the colors to be used for the forthcoming draw_text calls.
static char * crash_text[]
xcb_key_symbols_t * keysyms
int height
The height of the font, built from font_ascent + font_descent.
An Output is a physical output on your graphics driver.
i3String * i3string_from_utf8(const char *from_utf8)
Build an i3String from an UTF-8 encoded string.
Stores a rectangle, for example the size of a window, the child window etc.
static xcb_window_t open_input_window(xcb_connection_t *conn, Rect screen_rect, uint32_t width, uint32_t height)
Rect rect
x, y, width, height
xcb_connection_t * conn
XCB connection and root screen.
#define TAILQ_FOREACH(var, head, field)
int sasprintf(char **strp, const char *fmt,...)
Safe-wrapper around asprintf which exits if it returns -1 (meaning that there is no more memory avail...
bool active
Whether the output is currently active (has a CRTC attached with a valid mode)
color_t draw_util_hex_to_color(const char *color)
Parses the given color in hex format to an internal color representation.
static int backtrace_string_index
unsigned int xcb_numlock_mask
static int sig_draw_window(xcb_window_t win, int width, int height, int font_height, i3String **crash_text_i3strings)
int predict_text_width(i3String *text)
Predict the text width in pixels for the given text.
void * smalloc(size_t size)
Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there is no more memory a...
static int sig_handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press_event_t *event)
static xcb_gcontext_t pixmap_gc
void i3_restart(bool forget_layout)
Restart i3 in-place appends -a to argument list to disable autostart.
void handle_signal(int sig, siginfo_t *info, void *data)
static int backtrace(void)
struct _i3String i3String
Opaque data structure for storing strings.
static int backtrace_done
void setup_signal_handler(void)
Setup signal handlers to safely handle SIGSEGV and SIGFPE.
static xcb_pixmap_t pixmap