Skip to content

Commit

Permalink
Merge pull request yshui#201 from yshui/debug-mode
Browse files Browse the repository at this point in the history
Debug mode
  • Loading branch information
yshui authored Jul 7, 2019
2 parents 640b4b1 + d31e9da commit 3cd61c9
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 24 deletions.
8 changes: 3 additions & 5 deletions src/backend/gl/glx.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "backend/gl/gl_common.h"
#include "backend/gl/glx.h"
#include "common.h"
#include "compton.h"
#include "compiler.h"
#include "config.h"
#include "log.h"
Expand Down Expand Up @@ -221,7 +222,7 @@ static backend_t *glx_init(session_t *ps) {

gd->display = ps->dpy;
gd->screen = ps->scr;
gd->target_win = ps->overlay != XCB_NONE ? ps->overlay : ps->root;
gd->target_win = session_get_target_window(ps);

XVisualInfo *pvis = NULL;

Expand Down Expand Up @@ -310,10 +311,7 @@ static backend_t *glx_init(session_t *ps) {
}

// Attach GLX context
GLXDrawable tgt = ps->overlay;
if (!tgt) {
tgt = ps->root;
}
GLXDrawable tgt = gd->target_win;
if (!glXMakeCurrent(ps->dpy, tgt, gd->ctx)) {
log_error("Failed to attach GLX context.");
goto end;
Expand Down
19 changes: 7 additions & 12 deletions src/backend/xrender/xrender.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "backend/backend.h"
#include "backend/backend_common.h"
#include "common.h"
#include "compton.h"
#include "config.h"
#include "kernel.h"
#include "log.h"
Expand Down Expand Up @@ -532,18 +533,12 @@ backend_t *backend_xrender_init(session_t *ps) {
xd->black_pixel = solid_picture(ps->c, ps->root, true, 1, 0, 0, 0);
xd->white_pixel = solid_picture(ps->c, ps->root, true, 1, 1, 1, 1);

if (ps->overlay != XCB_NONE) {
xd->target = x_create_picture_with_visual_and_pixmap(
ps->c, ps->vis, ps->overlay, 0, NULL);
xd->target_win = ps->overlay;
} else {
xcb_render_create_picture_value_list_t pa = {
.subwindowmode = XCB_SUBWINDOW_MODE_INCLUDE_INFERIORS,
};
xd->target = x_create_picture_with_visual_and_pixmap(
ps->c, ps->vis, ps->root, XCB_RENDER_CP_SUBWINDOW_MODE, &pa);
xd->target_win = ps->root;
}
xd->target_win = session_get_target_window(ps);
xcb_render_create_picture_value_list_t pa = {
.subwindowmode = XCB_SUBWINDOW_MODE_INCLUDE_INFERIORS,
};
xd->target = x_create_picture_with_visual_and_pixmap(
ps->c, ps->vis, xd->target_win, XCB_RENDER_CP_SUBWINDOW_MODE, &pa);

auto pictfmt = x_get_pictform_for_visual(ps->c, ps->vis);
if (!pictfmt) {
Expand Down
2 changes: 2 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ typedef struct session {
// Damage root_damage;
/// X Composite overlay window. Used if <code>--paint-on-overlay</code>.
xcb_window_t overlay;
/// The target window for debug mode
xcb_window_t debug_window;
/// Whether the root tile is filled by compton.
bool root_tile_fill;
/// Picture of the root window background.
Expand Down
67 changes: 61 additions & 6 deletions src/compton.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,10 @@ static struct managed_win *paint_preprocess(session_t *ps, bool *fade_running) {
to_paint = false;
}

if (w->base.id == ps->debug_window || w->client_win == ps->debug_window) {
to_paint = false;
}

if ((w->flags & WIN_FLAGS_IMAGE_ERROR) != 0) {
to_paint = false;
}
Expand Down Expand Up @@ -798,7 +802,7 @@ void configure_root(session_t *ps, int width, int height) {
} else {
if (!initialize_backend(ps)) {
log_fatal("Failed to re-initialize backend after root "
"change, aborting...");
"change, aborting...");
ps->quit = true;
// TODO only event handlers should request ev_break,
// otherwise it's too hard to keep track of what can break
Expand Down Expand Up @@ -902,7 +906,9 @@ static bool register_cm(session_t *ps) {
// Unredirect the window if it's redirected, just in case
if (ps->redirected)
xcb_composite_unredirect_window(ps->c, ps->reg_win,
XCB_COMPOSITE_REDIRECT_MANUAL);
ps->o.debug_mode
? XCB_COMPOSITE_REDIRECT_AUTOMATIC
: XCB_COMPOSITE_REDIRECT_MANUAL);

{
XClassHint *h = XAllocClassHint();
Expand Down Expand Up @@ -1094,6 +1100,45 @@ static bool init_overlay(session_t *ps) {
return true;
}

static bool init_debug_window(session_t *ps) {
xcb_colormap_t colormap = x_new_id(ps->c);
ps->debug_window = x_new_id(ps->c);

auto err = xcb_request_check(
ps->c, xcb_create_colormap_checked(ps->c, XCB_COLORMAP_ALLOC_NONE, colormap,
ps->root, ps->vis));
if (err) {
goto err_out;
}

err = xcb_request_check(
ps->c, xcb_create_window_checked(ps->c, (uint8_t)ps->depth, ps->debug_window,
ps->root, 0, 0, to_u16_checked(ps->root_width),
to_u16_checked(ps->root_height), 0,
XCB_WINDOW_CLASS_INPUT_OUTPUT, ps->vis,
XCB_CW_COLORMAP, (uint32_t[]){colormap, 0}));
if (err) {
goto err_out;
}

err = xcb_request_check(ps->c, xcb_map_window(ps->c, ps->debug_window));
if (err) {
goto err_out;
}
return true;

err_out:
free(err);
return false;
}

xcb_window_t session_get_target_window(session_t *ps) {
if (ps->o.debug_mode) {
return ps->debug_window;
}
return ps->overlay != XCB_NONE ? ps->overlay : ps->root;
}

/**
* Redirect all windows.
*
Expand All @@ -1109,7 +1154,9 @@ static bool redir_start(session_t *ps) {
xcb_map_window(ps->c, ps->overlay);
}

xcb_composite_redirect_subwindows(ps->c, ps->root, XCB_COMPOSITE_REDIRECT_MANUAL);
xcb_composite_redirect_subwindows(ps->c, ps->root,
ps->o.debug_mode ? XCB_COMPOSITE_REDIRECT_AUTOMATIC
: XCB_COMPOSITE_REDIRECT_MANUAL);

x_sync(ps->c);

Expand Down Expand Up @@ -1155,7 +1202,9 @@ static void redir_stop(session_t *ps) {

destroy_backend(ps);

xcb_composite_unredirect_subwindows(ps->c, ps->root, XCB_COMPOSITE_REDIRECT_MANUAL);
xcb_composite_unredirect_subwindows(ps->c, ps->root,
ps->o.debug_mode ? XCB_COMPOSITE_REDIRECT_AUTOMATIC
: XCB_COMPOSITE_REDIRECT_MANUAL);
// Unmap overlay window
if (ps->overlay)
xcb_unmap_window(ps->c, ps->overlay);
Expand Down Expand Up @@ -1791,8 +1840,14 @@ static session_t *session_init(int argc, char **argv, Display *dpy,

// Overlay must be initialized before double buffer, and before creation
// of OpenGL context.
if (!init_overlay(ps)) {
goto err;
if (!ps->o.debug_mode) {
if (!init_overlay(ps)) {
goto err;
}
} else {
if (!init_debug_window(ps)) {
goto err;
}
}

ps->drivers = detect_driver(ps->c, ps->backend_data, ps->root);
Expand Down
2 changes: 2 additions & 0 deletions src/compton.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ void discard_ignore(session_t *ps, unsigned long sequence);

void set_root_flags(session_t *ps, uint64_t flags);

xcb_window_t session_get_target_window(session_t *);

/**
* Set a <code>switch_t</code> array of all unset wintypes to true.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ typedef struct options {
// === Debugging ===
bool monitor_repaint;
bool print_diagnostics;
/// Render to a separate window instead of taking over the screen
bool debug_mode;
// === General ===
/// Use the experimental new backends?
bool experimental_backends;
Expand Down
9 changes: 8 additions & 1 deletion src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,14 @@ static void usage(int ret) {
"--benchmark-wid window-id\n"
" Specify window ID to repaint in benchmark mode. If omitted or is 0,\n"
" the whole screen is repainted.\n"
"\n"
"--monitor-repaint\n"
" Highlight the updated area of the screen. For debugging the xrender\n"
" backend only.\n";
" backend only.\n"
"\n"
"--debug-mode\n"
" Render into a separate window, and don't take over the screen. Useful\n"
" when you want to attach a debugger to compton\n";
FILE *f = (ret ? stderr : stdout);
fputs(usage_text, f);
#undef WARNING_DISABLED
Expand Down Expand Up @@ -406,6 +411,7 @@ static const struct option longopts[] = {
{"experimental-backends", no_argument, NULL, 733},
{"monitor-repaint", no_argument, NULL, 800},
{"diagnostics", no_argument, NULL, 801},
{"debug-mode", no_argument, NULL, 802},
// Must terminate with a NULL entry
{NULL, 0, NULL, 0},
};
Expand Down Expand Up @@ -777,6 +783,7 @@ void get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable,
P_CASEBOOL(733, experimental_backends);
P_CASEBOOL(800, monitor_repaint);
case 801: opt->print_diagnostics = true; break;
P_CASEBOOL(802, debug_mode);
default: usage(1); break;
#undef P_CASEBOOL
}
Expand Down

0 comments on commit 3cd61c9

Please sign in to comment.