Improvement #74: Use libevent for main loop

- Use libevent for main loop. I will explain the reasons in #56 later.
  The preferred libevent version is 2.x, yet 1.4.x should work as well.

- As a result, compton now should build fine on *BSD. Thanks to
  DachiChang for the FreeBSD build issue report.

- Another consequence is we now use microsecond-level timing all the
  way. Nanosecond-level code will be dropped soon. Start using long
  instead of unsigned long to represent time in milliseconds, as both
  can't hold the full epoch time in ms, anyway, and a signed type
  requires less care in subtraction. Wrap the epoch time in ms to 15
  days.

- Fix broken NO_VSYNC_DRM and NO_VSYNC_OPENGL compile-time options.

- Use git revision number for versioning in Makefile, and other small
  improvements.

- Reorganize struct _win. Drop unused w->damaged_sequence. w->damaged is
  turned to bool.

- Add type and format to winprop_t, as preparation for the new condition
  format.

- Add w->shadow_force and w->focus_force, to prepare for D-Bus support.

- Rename wid_get_prop() to wid_get_prop_adv() with more options. Add
  wrapper function wid_get_prop().

- Add some extra helper functions, for D-Bus support later.

- Make some functions return a bool value to indicate if it's
  successful.

- Modify add_win(), use a static const structure to initialize the new
  struct _win.

- Add some helper macros, like printf_err(f)(q). Make some errors fatal.

- Rename some types, constants, and functions. Code clean-up.

- Check for time disorder in paint_preprocess() when calculating fading
  steps.

- Rename evpoll() to swopti_handle_timeout(), and partially rewrite it.

- Make -h / --help legal.

- Known issue: compton segfaults on FreeBSD with nvidia-drivers, unless
  NO_VSYNC_OPENGL is used. Will look into it later. Thamls to DachiChang
  for reporting.
This commit is contained in:
Richard Grenville
2013-01-08 08:50:58 +08:00
parent 75aec17a85
commit 3521f10a97
4 changed files with 614 additions and 286 deletions

View File

@ -1,3 +1,6 @@
# Use tab to indent recipe lines, spaces to indent other lines, otherwise
# GNU make may get unhappy.
CC ?= gcc
PREFIX ?= /usr
@ -8,44 +11,79 @@ PACKAGES = x11 xcomposite xfixes xdamage xrender xext xrandr
LIBS = -lm -lrt
INCS =
# Parse configuration flags
# === Configuration flags ===
CFG =
# ==== libevent ====
# Seemingly, libevent1 has no pkg-config file!
# FreeBSD 9.1 probably has issues handling --atleast-version in pkg-config.
ifeq "$(shell pkg-config --modversion --print-errors libevent)" ""
$(warning libevent-2.0 not found, assuming libevent-1.4.x.)
CFG += -DCONFIG_LIBEVENT_LEGACY
LIBS += -levent
else
# Using pkg-config for linking with libevent will result in linking with
# libevent.so instead of the smaller libevent_core.so. But FreeBSD keeps
# libevent2 .so files at a separate place, and we must learn it from
# pkg-config.
LIBS += $(shell pkg-config --libs libevent)
INCS += $(shell pkg-config --cflags libevent)
endif
# ==== libconfig ====
ifeq "$(NO_LIBCONFIG)" ""
CFG += -DCONFIG_LIBCONFIG
PACKAGES += libconfig
CFG += -DCONFIG_LIBCONFIG
PACKAGES += libconfig
# libconfig-1.3* does not define LIBCONFIG_VER* macros, so we use
# pkg-config to determine its version here
CFG += $(shell pkg-config --atleast-version=1.4 libconfig || echo '-DCONFIG_LIBCONFIG_LEGACY')
# libconfig-1.3* does not define LIBCONFIG_VER* macros, so we use
# pkg-config to determine its version here
CFG += $(shell pkg-config --atleast-version=1.4 libconfig || echo '-DCONFIG_LIBCONFIG_LEGACY')
endif
# ==== PCRE regular expression ====
ifeq "$(NO_REGEX_PCRE)" ""
CFG += -DCONFIG_REGEX_PCRE
LIBS += $(shell pcre-config --libs)
INCS += $(shell pcre-config --cflags)
ifeq "$(NO_REGEX_PCRE_JIT)" ""
CFG += -DCONFIG_REGEX_PCRE_JIT
endif
CFG += -DCONFIG_REGEX_PCRE
LIBS += $(shell pcre-config --libs)
INCS += $(shell pcre-config --cflags)
ifeq "$(NO_REGEX_PCRE_JIT)" ""
CFG += -DCONFIG_REGEX_PCRE_JIT
endif
endif
# ==== DRM VSync ====
ifeq "$(NO_VSYNC_DRM)" ""
CFG += -DCONFIG_VSYNC_DRM
CFG += -DCONFIG_VSYNC_DRM
endif
# ==== OpenGL VSync ====
ifeq "$(NO_VSYNC_OPENGL)" ""
CFG += -DCONFIG_VSYNC_OPENGL
LIBS += -lGL
CFG += -DCONFIG_VSYNC_OPENGL
LIBS += -lGL
endif
CFLAGS ?= -DNDEBUG -O2 -D_FORTIFY_SOURCE=2
# ==== D-Bus ====
# ifeq "$(NO_DBUS)" ""
# CFG += -DCONFIG_DBUS
# PACKAGES += dbus-1
# endif
# === Version string ===
COMPTON_VERSION ?= git-$(shell git describe --always)
CFG += -DCOMPTON_VERSION="\"$(COMPTON_VERSION)\""
LDFLAGS ?= -Wl,-O1 -Wl,--as-needed
CFLAGS ?= -DNDEBUG -O2 -D_FORTIFY_SOURCE=2 $(LDFLAGS)
CFLAGS += $(CFG)
LIBS += $(shell pkg-config --libs $(PACKAGES))
INCS += $(shell pkg-config --cflags $(PACKAGES))
CFLAGS += -Wall -std=c99
OBJS = compton.o
# === Recipes ===
.DEFAULT_GOAL := compton
%.o: src/%.c src/%.h
$(CC) $(CFLAGS) $(INCS) -c src/$*.c
@ -75,4 +113,4 @@ uninstall:
clean:
@rm -f $(OBJS) compton
.PHONY: uninstall clean
.PHONY: uninstall clean docs