From: Dana Jansens Date: Mon, 23 Jul 2007 21:42:08 +0000 (-0400) Subject: look mom, I made an openbox toolkit X-Git-Url: https://git.dogcows.com/gitweb?a=commitdiff_plain;h=ebce321a72331697287838b864735e7b81e60b33;p=chaz%2Fopenbox look mom, I made an openbox toolkit --- diff --git a/Makefile.am b/Makefile.am index 6b474a65..4d12d4ce 100644 --- a/Makefile.am +++ b/Makefile.am @@ -25,7 +25,8 @@ check_PROGRAMS = \ lib_LTLIBRARIES = \ parser/libobparser.la \ - render/libobrender.la + render/libobrender.la \ + obt/libobt.la bin_PROGRAMS = \ openbox/openbox \ @@ -109,6 +110,24 @@ parser_libobparser_la_SOURCES = \ parser/parse.h \ parser/parse.c +## obt ## + +obt_libobt_la_CPPFLAGS = \ + $(GLIB_CFLAGS) \ + $(XML_CFLAGS) \ + -DG_LOG_DOMAIN=\"Obt\" \ + -DLOCALEDIR=\"$(localedir)\" \ + -DDATADIR=\"$(datadir)\" \ + -DCONFIGDIR=\"$(configdir)\" +obt_libobt_la_LDFLAGS = \ + -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) +obt_libobt_la_LIBADD = \ + $(GLIB_LIBS) \ + $(XML_LIBS) +obt_libobt_la_SOURCES = \ + obt/obt.h \ + obt/instance.c + ## openbox ## openbox_openbox_CPPFLAGS = \ @@ -144,7 +163,8 @@ openbox_openbox_LDADD = \ $(EFENCE_LIBS) \ $(LIBINTL) \ render/libobrender.la \ - parser/libobparser.la + parser/libobparser.la \ + obt/libobt.la openbox_openbox_LDFLAGS = -export-dynamic openbox_openbox_SOURCES = \ gettext.h \ @@ -379,14 +399,16 @@ pubinclude_HEADERS = \ render/mask.h \ render/render.h \ render/theme.h \ - parser/parse.h + parser/parse.h \ + obt/obt.h nodist_pubinclude_HEADERS = \ version.h nodist_pkgconfig_DATA = \ render/obrender-3.0.pc \ - parser/obparser-3.0.pc + parser/obparser-3.0.pc \ + obt/obt-4.0.pc ## data ## @@ -447,6 +469,7 @@ dist_noinst_DATA = \ doc/openbox-kde-session.1.in \ render/obrender-3.0.pc.in \ parser/obparser-3.0.pc.in \ + obt/obt-4.0.pc.in \ tools/themeupdate/themeupdate.py \ tests/hideshow.py \ tests/Makefile \ @@ -502,7 +525,7 @@ CLEANFILES = \ # $(MAKE) -$(MAKEFLAGS) -C doc/doxygen doc distclean-local: - for d in . m4 po render; do \ + for d in . m4 po render parser obt openbox; do \ for p in core core.* gmon.out *\~ *.orig *.rej .\#*; do \ rm -f "$$d/$$p"; \ done \ diff --git a/configure.ac b/configure.ac index 53e50013..eef3d554 100644 --- a/configure.ac +++ b/configure.ac @@ -156,6 +156,7 @@ AC_CONFIG_FILES([ po/Makefile.in render/obrender-3.0.pc parser/obparser-3.0.pc + obt/obt-4.0.pc version.h ]) AC_CONFIG_COMMANDS([doc], diff --git a/obt/instance.c b/obt/instance.c new file mode 100644 index 00000000..8299eb85 --- /dev/null +++ b/obt/instance.c @@ -0,0 +1,56 @@ +#include "obt/obt.h" + +#ifdef HAVE_STRING_H +# include +#endif +#ifdef HAVE_FCNTL_H +# include +#endif +#ifdef HAVE_UNISTD_H +# include +#endif + +struct _ObtInstance +{ + gint ref; + Display *d; +}; + +ObtInstance* obt_instance_new(const char *display_name) +{ + gchar *n; + Display *d; + ObtInstance *inst = NULL; + + n = display_name ? g_strdup(display_name) : NULL; + d = XOpenDisplay(n); + if (d) { + if (fcntl(ConnectionNumber(d), F_SETFD, 1) == -1) + g_message("Failed to set display as close-on-exec"); + + inst = g_new(ObtInstance, 1); + inst->ref = 1; + inst->d = d; + } + g_free(n); + + return inst; +} + +void obt_instance_ref(ObtInstance *inst) +{ + ++inst->ref; +} + +void obt_instance_unref(ObtInstance *inst) +{ + if (inst && --inst->ref == 0) { + XCloseDisplay(inst->d); + obt_free0(inst, ObtInstance, 1); + } +} + +Display* obt_display(const ObtInstance *inst) +{ + return inst->d; +} diff --git a/obt/obt-4.0.pc b/obt/obt-4.0.pc new file mode 100644 index 00000000..34aad6dc --- /dev/null +++ b/obt/obt-4.0.pc @@ -0,0 +1,14 @@ +prefix=/opt/openbox +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + +xcflags= +xlibs= -lSM -lICE -lX11 + +Name: ObRender +Description: Openbox Toolkit Library +Version: 3.999.0 +Requires: glib-2.0 +Libs: -L${libdir} -lobrender ${xlibs} +Cflags: -I${includedir}/openbox/3.4 ${xcflags} diff --git a/obt/obt-4.0.pc.in b/obt/obt-4.0.pc.in new file mode 100644 index 00000000..1d2b6685 --- /dev/null +++ b/obt/obt-4.0.pc.in @@ -0,0 +1,14 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +xcflags=@X_CFLAGS@ +xlibs=@X_LIBS@ + +Name: ObRender +Description: Openbox Toolkit Library +Version: @VERSION@ +Requires: glib-2.0 +Libs: -L${libdir} -lobrender ${xlibs} +Cflags: -I${includedir}/openbox/@OB_VERSION@ ${xcflags} diff --git a/obt/obt.h b/obt/obt.h new file mode 100644 index 00000000..7fb59d2c --- /dev/null +++ b/obt/obt.h @@ -0,0 +1,46 @@ +/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- + + obt.h for the Openbox window manager + Copyright (c) 2007 Dana Jansens + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + See the COPYING file for a copy of the GNU General Public License. +*/ + +#ifndef __obt_h +#define __obt_h + +#include +#include + +#ifdef HAVE_STRING_H +# include /* for memset() */ +#endif + +G_BEGIN_DECLS + +typedef struct _ObtInstance ObtInstance; + +/* Instance funcs */ +ObtInstance* obt_instance_new (const char *display_name); +void obt_instance_ref (ObtInstance *inst); +void obt_instance_unref (ObtInstance *inst); + +Display* obt_display (const ObtInstance *inst); + +/* Util funcs */ +#define obt_free g_free +#define obt_free0(p, type, num) memset((p), 0, sizeof(type) * (num)), g_free(p) + +G_END_DECLS + +#endif /*__obt_h*/ diff --git a/openbox/openbox.c b/openbox/openbox.c index 48f31f91..c768bdf4 100644 --- a/openbox/openbox.c +++ b/openbox/openbox.c @@ -49,6 +49,7 @@ #include "parser/parse.h" #include "render/render.h" #include "render/theme.h" +#include "obt/obt.h" #ifdef HAVE_FCNTL_H # include @@ -83,18 +84,18 @@ #include #include - -RrInstance *ob_rr_inst; -RrTheme *ob_rr_theme; -ObMainLoop *ob_main_loop; -Display *ob_display; -gint ob_screen; -gboolean ob_replace_wm = FALSE; -gboolean ob_sm_use = TRUE; -gchar *ob_sm_id = NULL; -gchar *ob_sm_save_file = NULL; -gboolean ob_sm_restore = TRUE; -gboolean ob_debug_xinerama = FALSE; +ObtInstance *obt_inst; +RrInstance *ob_rr_inst; +RrTheme *ob_rr_theme; +ObMainLoop *ob_main_loop; +Display *ob_display; +gint ob_screen; +gboolean ob_replace_wm = FALSE; +gboolean ob_sm_use = TRUE; +gchar *ob_sm_id = NULL; +gchar *ob_sm_save_file = NULL; +gboolean ob_sm_restore = TRUE; +gboolean ob_debug_xinerama = FALSE; static ObState state; static gboolean xsync = FALSE; @@ -144,12 +145,10 @@ gint main(gint argc, gchar **argv) session_startup(argc, argv); } - - ob_display = XOpenDisplay(NULL); - if (ob_display == NULL) + obt_inst = obt_instance_new(NULL); + if (obt_inst == NULL) ob_exit_with_error(_("Failed to open the display from the DISPLAY environment variable.")); - if (fcntl(ConnectionNumber(ob_display), F_SETFD, 1) == -1) - ob_exit_with_error("Failed to set display as close-on-exec"); + ob_display = obt_display(obt_inst); if (remote_control) { prop_startup(); @@ -159,7 +158,7 @@ gint main(gint argc, gchar **argv) * remote_control = 2 -> restart */ PROP_MSG(RootWindow(ob_display, ob_screen), ob_control, remote_control, 0, 0, 0); - XCloseDisplay(ob_display); + obt_instance_unref(obt_inst); exit(EXIT_SUCCESS); } @@ -386,7 +385,7 @@ gint main(gint argc, gchar **argv) session_shutdown(being_replaced); - XCloseDisplay(ob_display); + obt_instance_unref(obt_inst); parse_paths_shutdown();