common.h: general clean up

Remove unused functions and definitions. Move some macros into the files
they belong.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-05-06 01:24:38 +01:00
parent e330464126
commit 939f2fb602
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
7 changed files with 24 additions and 167 deletions

View File

@ -4,9 +4,6 @@
#include "common.h"
#include "utils.h"
/**
* Wrapper of XInternAtom() for convenience.
*/
static inline void *atom_getter(void *ud, const char *atom_name, int *err) {
xcb_connection_t *c = ud;
xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(
@ -25,7 +22,7 @@ static inline void *atom_getter(void *ud, const char *atom_name, int *err) {
}
/**
* Fetch all required atoms and save them to a session.
* Create a new atom structure and fetch all predefined atoms
*/
struct atom *init_atoms(xcb_connection_t *c) {
auto atoms = ccalloc(1, struct atom);

View File

@ -277,17 +277,14 @@ void paint_all_new(session_t *ps, struct managed_win *t, bool ignore_damage) {
}
#ifdef DEBUG_REPAINT
print_timestamp(ps);
struct timespec now = get_time_timespec();
struct timespec diff = {0};
timespec_subtract(&diff, &now, &last_paint);
printf("[ %5ld:%09ld ] ", diff.tv_sec, diff.tv_nsec);
log_trace("[ %5ld:%09ld ] ", diff.tv_sec, diff.tv_nsec);
last_paint = now;
printf("paint:");
log_trace("paint:");
for (win *w = t; w; w = w->prev_trans)
printf(" %#010lx", w->id);
putchar('\n');
fflush(stdout);
log_trace(" %#010lx", w->id);
#endif
}

View File

@ -38,7 +38,6 @@
#include <sys/time.h>
#include <time.h>
#include <X11/Xlib.h>
#include <ev.h>
#include <pixman.h>
#include <xcb/composite.h>
@ -51,19 +50,7 @@
#include "uthash_extra.h"
#ifdef CONFIG_OPENGL
// libGL
#include "backend/gl/glx.h"
// Workarounds for missing definitions in some broken GL drivers, thanks to
// douglasp and consolers for reporting
#ifndef GL_TEXTURE_RECTANGLE
#define GL_TEXTURE_RECTANGLE 0x84F5
#endif
#ifndef GLX_BACK_BUFFER_AGE_EXT
#define GLX_BACK_BUFFER_AGE_EXT 0x20F4
#endif
#endif
// === Macros ===
@ -92,26 +79,15 @@
// === Constants ===
/// @brief Length of generic buffers.
#define BUF_LEN 80
#define ROUNDED_PERCENT 0.05
#define ROUNDED_PIXELS 10
#define REGISTER_PROP "_NET_WM_CM_S"
#define TIME_MS_MAX LONG_MAX
#define SWOPTI_TOLERANCE 3000
#define WIN_GET_LEADER_MAX_RECURSION 20
#define NS_PER_SEC 1000000000L
#define US_PER_SEC 1000000L
#define MS_PER_SEC 1000
#define XRFILTER_CONVOLUTION "convolution"
#define XRFILTER_GAUSSIAN "gaussian"
#define XRFILTER_BINOMIAL "binomial"
/// @brief Maximum OpenGL FBConfig depth.
#define OPENGL_MAX_DEPTH 32
@ -173,16 +149,6 @@ typedef void (*GLDEBUGPROC)(GLenum source, GLenum type, GLuint id, GLenum severi
typedef void (*f_DebugMessageCallback)(GLDEBUGPROC, void *userParam);
#endif
#ifdef CONFIG_OPENGL
typedef GLsync (*f_FenceSync)(GLenum condition, GLbitfield flags);
typedef GLboolean (*f_IsSync)(GLsync sync);
typedef void (*f_DeleteSync)(GLsync sync);
typedef GLenum (*f_ClientWaitSync)(GLsync sync, GLbitfield flags, GLuint64 timeout);
typedef void (*f_WaitSync)(GLsync sync, GLbitfield flags, GLuint64 timeout);
typedef GLsync (*f_ImportSyncEXT)(GLenum external_sync_type, GLintptr external_sync,
GLbitfield flags);
#endif
/// @brief Wrapper of a binded GLX texture.
struct _glx_texture {
GLuint texture;
@ -247,29 +213,15 @@ typedef struct {
GLXContext context;
/// Whether we have GL_ARB_texture_non_power_of_two.
bool has_texture_non_power_of_two;
/// Pointer to the glFenceSync() function.
f_FenceSync glFenceSyncProc;
/// Pointer to the glIsSync() function.
f_IsSync glIsSyncProc;
/// Pointer to the glDeleteSync() function.
f_DeleteSync glDeleteSyncProc;
/// Pointer to the glClientWaitSync() function.
f_ClientWaitSync glClientWaitSyncProc;
/// Pointer to the glWaitSync() function.
f_WaitSync glWaitSyncProc;
/// Pointer to the glImportSyncEXT() function.
f_ImportSyncEXT glImportSyncEXT;
/// Current GLX Z value.
int z;
#ifdef CONFIG_OPENGL
glx_blur_pass_t blur_passes[MAX_BLUR_PASS];
#endif
} glx_session_t;
#define CGLX_SESSION_INIT \
{ .context = NULL }
#endif
#endif // CONFIG_OPENGL
/// Structure containing all necessary data for a compton session.
typedef struct session {
@ -523,85 +475,10 @@ typedef enum { WIN_EVMODE_UNKNOWN, WIN_EVMODE_FRAME, WIN_EVMODE_CLIENT } win_evm
extern const char *const WINTYPES[NUM_WINTYPES];
extern session_t *ps_g;
// == Debugging code ==
static inline void print_timestamp(session_t *ps);
void ev_xcb_error(session_t *ps, xcb_generic_error_t *err);
// === Functions ===
/**
* Return whether a struct timeval value is empty.
*/
static inline bool timeval_isempty(struct timeval *ptv) {
if (!ptv)
return false;
return ptv->tv_sec <= 0 && ptv->tv_usec <= 0;
}
/**
* Compare a struct timeval with a time in milliseconds.
*
* @return > 0 if ptv > ms, 0 if ptv == 0, -1 if ptv < ms
*/
static inline int timeval_ms_cmp(struct timeval *ptv, unsigned long ms) {
assert(ptv);
// We use those if statement instead of a - expression because of possible
// truncation problem from long to int.
auto sec = (long)(ms / MS_PER_SEC);
if (ptv->tv_sec > sec) {
return 1;
}
if (ptv->tv_sec < sec) {
return -1;
}
auto usec = (long)(ms % MS_PER_SEC * (US_PER_SEC / MS_PER_SEC));
if (ptv->tv_usec > usec) {
return 1;
}
if (ptv->tv_usec < usec) {
return -1;
}
return 0;
}
/**
* Subtracting two struct timeval values.
*
* Taken from glibc manual.
*
* Subtract the `struct timeval' values X and Y,
* storing the result in RESULT.
* Return 1 if the difference is negative, otherwise 0.
*/
static inline int
timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y) {
/* Perform the carry for the later subtraction by updating y. */
if (x->tv_usec < y->tv_usec) {
long nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
y->tv_usec -= 1000000 * nsec;
y->tv_sec += nsec;
}
if (x->tv_usec - y->tv_usec > 1000000) {
long nsec = (x->tv_usec - y->tv_usec) / 1000000;
y->tv_usec += 1000000 * nsec;
y->tv_sec -= nsec;
}
/* Compute the time remaining to wait.
tv_usec is certainly positive. */
result->tv_sec = x->tv_sec - y->tv_sec;
result->tv_usec = x->tv_usec - y->tv_usec;
/* Return 1 if result is negative. */
return x->tv_sec < y->tv_sec;
}
/**
* Subtracting two struct timespec values.
*
@ -661,21 +538,6 @@ static inline struct timespec get_time_timespec(void) {
return tm;
}
/**
* Print time passed since program starts execution.
*
* Used for debugging.
*/
static inline void print_timestamp(session_t *ps) {
struct timeval tm, diff;
if (gettimeofday(&tm, NULL))
return;
timeval_subtract(&diff, &tm, &ps->time_start);
fprintf(stderr, "[ %5ld.%06ld ] ", diff.tv_sec, diff.tv_usec);
}
/**
* Wrapper of XFree() for convenience.
*
@ -686,11 +548,6 @@ static inline void cxfree(void *data) {
XFree(data);
}
_Noreturn static inline void die(const char *msg) {
puts(msg);
exit(1);
}
/**
* Return the painting target window.
*/
@ -787,10 +644,6 @@ static inline long winprop_get_int(winprop_t prop) {
void force_repaint(session_t *ps);
bool vsync_init(session_t *ps);
void vsync_deinit(session_t *ps);
/** @name DBus handling
*/
///@{

View File

@ -932,18 +932,14 @@ static bool register_cm(session_t *ps) {
// Acquire X Selection _NET_WM_CM_S?
if (!ps->o.no_x_selection) {
unsigned len = strlen(REGISTER_PROP) + 2;
int s = ps->scr;
const char register_prop[] = "_NET_WM_CM_S";
xcb_atom_t atom;
while (s >= 10) {
++len;
s /= 10;
char *buf = NULL;
if (asprintf(&buf, "%s%d", register_prop, ps->scr) < 0) {
log_fatal("Failed to allocate memory");
return false;
}
auto buf = ccalloc(len, char);
snprintf(buf, len, REGISTER_PROP "%d", ps->scr);
buf[len - 1] = '\0';
atom = get_atom(ps->atoms, buf);
free(buf);

View File

@ -30,6 +30,10 @@
#include "opengl.h"
#ifndef GL_TEXTURE_RECTANGLE
#define GL_TEXTURE_RECTANGLE 0x84F5
#endif
static inline XVisualInfo *get_visualinfo_from_visual(session_t *ps, xcb_visualid_t visual) {
XVisualInfo vreq = {.visualid = visual};
int nitems = 0;

View File

@ -15,6 +15,11 @@
#ifdef CONFIG_OPENGL
#include "backend/gl/glx.h"
#include "opengl.h"
#ifndef GLX_BACK_BUFFER_AGE_EXT
#define GLX_BACK_BUFFER_AGE_EXT 0x20F4
#endif
#endif
#include "compiler.h"
@ -31,6 +36,10 @@
#include "backend/backend_common.h"
#include "render.h"
#define XRFILTER_CONVOLUTION "convolution"
#define XRFILTER_GAUSSIAN "gaussian"
#define XRFILTER_BINOMIAL "binomial"
/**
* Bind texture in paint_t if we are using GLX backend.
*/

View File

@ -43,6 +43,7 @@
#include "win.h"
#define OPAQUE 0xffffffff
#define WIN_GET_LEADER_MAX_RECURSION 20
/// Generate a "return by value" function, from a function that returns the
/// region via a region_t pointer argument.