Browse Source

Only output text when in debug mode (fixes problems with xautolock)

master
Michael Stapelberg 13 years ago
parent
commit
be21951062
  1. 24
      i3lock.c
  2. 13
      i3lock.h
  3. 9
      xinerama.c

24
i3lock.c

@ -32,6 +32,7 @@
#include <cairo/cairo-xcb.h> #include <cairo/cairo-xcb.h>
#endif #endif
#include "i3lock.h"
#include "keysym2ucs.h" #include "keysym2ucs.h"
#include "ucs2_to_utf8.h" #include "ucs2_to_utf8.h"
#include "xcb.h" #include "xcb.h"
@ -55,7 +56,7 @@ static int numlockmask;
static int shiftlockmask; static int shiftlockmask;
static int capslockmask; static int capslockmask;
static bool beep = false; static bool beep = false;
static bool debug_mode = false; bool debug_mode = false;
static bool dpms = false; static bool dpms = false;
bool unlock_indicator = true; bool unlock_indicator = true;
static bool dont_fork = false; static bool dont_fork = false;
@ -64,11 +65,6 @@ static struct ev_timer *clear_pam_wrong_timeout;
extern unlock_state_t unlock_state; extern unlock_state_t unlock_state;
extern pam_state_t pam_state; extern pam_state_t pam_state;
#define DEBUG(fmt, ...) do { \
if (debug_mode) \
printf("[i3lock-debug] " fmt, ##__VA_ARGS__); \
} while (0)
#ifndef NOLIBCAIRO #ifndef NOLIBCAIRO
cairo_surface_t *img = NULL; cairo_surface_t *img = NULL;
bool tile = false; bool tile = false;
@ -123,12 +119,13 @@ static void input_done() {
redraw_screen(); redraw_screen();
if (pam_authenticate(pam_handle, 0) == PAM_SUCCESS) { if (pam_authenticate(pam_handle, 0) == PAM_SUCCESS) {
printf("successfully authenticated\n"); DEBUG("successfully authenticated\n");
clear_password_memory(); clear_password_memory();
exit(0); exit(0);
} }
fprintf(stderr, "Authentication failure\n"); if (debug_mode)
fprintf(stderr, "Authentication failure\n");
pam_state = STATE_PAM_WRONG; pam_state = STATE_PAM_WRONG;
redraw_screen(); redraw_screen();
@ -349,7 +346,8 @@ static void handle_key_press(xcb_key_press_event_t *event) {
/* convert the keysym to UCS */ /* convert the keysym to UCS */
uint16_t ucs = keysym2ucs(sym); uint16_t ucs = keysym2ucs(sym);
if ((int16_t)ucs == -1) { if ((int16_t)ucs == -1) {
fprintf(stderr, "Keysym could not be converted to UCS, skipping\n"); if (debug_mode)
fprintf(stderr, "Keysym could not be converted to UCS, skipping\n");
return; return;
} }
@ -495,8 +493,9 @@ static void xcb_check_cb(EV_P_ ev_check *w, int revents) {
while ((event = xcb_poll_for_event(conn)) != NULL) { while ((event = xcb_poll_for_event(conn)) != NULL) {
if (event->response_type == 0) { if (event->response_type == 0) {
xcb_generic_error_t *error = (xcb_generic_error_t*)event; xcb_generic_error_t *error = (xcb_generic_error_t*)event;
fprintf(stderr, "X11 Error received! sequence 0x%x, error_code = %d\n", if (debug_mode)
error->sequence, error->error_code); fprintf(stderr, "X11 Error received! sequence 0x%x, error_code = %d\n",
error->sequence, error->error_code);
free(event); free(event);
continue; continue;
} }
@ -671,7 +670,8 @@ int main(int argc, char *argv[]) {
xcb_dpms_capable_reply_t *dpmsr; xcb_dpms_capable_reply_t *dpmsr;
if ((dpmsr = xcb_dpms_capable_reply(conn, dpmsc, NULL))) { if ((dpmsr = xcb_dpms_capable_reply(conn, dpmsc, NULL))) {
if (!dpmsr->capable) { if (!dpmsr->capable) {
fprintf(stderr, "Disabling DPMS, X server not DPMS capable\n"); if (debug_mode)
fprintf(stderr, "Disabling DPMS, X server not DPMS capable\n");
dpms = false; dpms = false;
} }
free(dpmsr); free(dpmsr);

13
i3lock.h

@ -0,0 +1,13 @@
#ifndef _I3LOCK_H
#define _I3LOCK_H
/* This macro will only print debug output when started with --debug.
* This is important because xautolock (for example) closes stdout/stderr by
* default, so just printing something to stdout will lead to the data ending
* up on the X11 socket (!). */
#define DEBUG(fmt, ...) do { \
if (debug_mode) \
printf("[i3lock-debug] " fmt, ##__VA_ARGS__); \
} while (0)
#endif

9
xinerama.c

@ -13,6 +13,7 @@
#include <xcb/xcb.h> #include <xcb/xcb.h>
#include <xcb/xinerama.h> #include <xcb/xinerama.h>
#include "i3lock.h"
#include "xcb.h" #include "xcb.h"
#include "xinerama.h" #include "xinerama.h"
@ -23,10 +24,11 @@ int xr_screens = 0;
Rect *xr_resolutions; Rect *xr_resolutions;
static bool xinerama_active; static bool xinerama_active;
extern bool debug_mode;
void xinerama_init() { void xinerama_init() {
if (!xcb_get_extension_data(conn, &xcb_xinerama_id)->present) { if (!xcb_get_extension_data(conn, &xcb_xinerama_id)->present) {
printf("Xinerama extension not found, disabling.\n"); DEBUG("Xinerama extension not found, disabling.\n");
return; return;
} }
@ -57,7 +59,8 @@ void xinerama_query_screens() {
cookie = xcb_xinerama_query_screens_unchecked(conn); cookie = xcb_xinerama_query_screens_unchecked(conn);
reply = xcb_xinerama_query_screens_reply(conn, cookie, NULL); reply = xcb_xinerama_query_screens_reply(conn, cookie, NULL);
if (!reply) { if (!reply) {
fprintf(stderr, "Couldn't get Xinerama screens\n"); if (debug_mode)
fprintf(stderr, "Couldn't get Xinerama screens\n");
return; return;
} }
screen_info = xcb_xinerama_query_screens_screen_info(reply); screen_info = xcb_xinerama_query_screens_screen_info(reply);
@ -77,7 +80,7 @@ void xinerama_query_screens() {
xr_resolutions[screen].y = screen_info[screen].y_org; xr_resolutions[screen].y = screen_info[screen].y_org;
xr_resolutions[screen].width = screen_info[screen].width; xr_resolutions[screen].width = screen_info[screen].width;
xr_resolutions[screen].height = screen_info[screen].height; xr_resolutions[screen].height = screen_info[screen].height;
printf("found Xinerama screen: %d x %d at %d x %d\n", DEBUG("found Xinerama screen: %d x %d at %d x %d\n",
screen_info[screen].width, screen_info[screen].height, screen_info[screen].width, screen_info[screen].height,
screen_info[screen].x_org, screen_info[screen].y_org); screen_info[screen].x_org, screen_info[screen].y_org);
} }

Loading…
Cancel
Save