From: Dana Jansens Date: Mon, 27 Jan 2003 13:42:41 +0000 (+0000) Subject: use otk objects in the ob scripts by importing otk X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=5face4c6f35172761367f63ac0b6eaf62d84e532;p=chaz%2Fopenbox use otk objects in the ob scripts by importing otk --- diff --git a/otk/Makefile.am b/otk/Makefile.am index c714f472..29b35442 100644 --- a/otk/Makefile.am +++ b/otk/Makefile.am @@ -1,4 +1,5 @@ buttonsdir = $(pkgdatadir)/buttons +scriptdir = $(libdir)/openbox/python CXXFLAGS=$(XFT_CFLAGS) $(PYTHON_CFLAGS) @CXXFLAGS@ \ -DBUTTONSDIR=\"$(buttonsdir)\" @@ -6,7 +7,7 @@ CXXFLAGS=$(XFT_CFLAGS) $(PYTHON_CFLAGS) @CXXFLAGS@ \ INCLUDES= -I../src #noinst_LIBRARIES=libotk.a -noinst_LTLIBRARIES=libotk.la +lib_LTLIBRARIES=libotk.la libotk_la_SOURCES=rendercontrol.cc truerendercontrol.cc surface.cc \ renderstyle.cc rendercolor.cc \ @@ -15,13 +16,17 @@ libotk_la_SOURCES=rendercontrol.cc truerendercontrol.cc surface.cc \ timer.cc \ configuration.cc util.cc widget.cc focuswidget.cc \ button.cc eventhandler.cc eventdispatcher.cc ustring.cc \ - label.cc focuslabel.cc application.cc appwidget.cc -# otk_wrap.cc + label.cc focuslabel.cc application.cc appwidget.cc \ + otk_wrap.cc libotk_la_LDFLAGS = $(XFT_LIBS) $(PYTHON_LIBS) @LIBS@ MAINTAINERCLEANFILES= Makefile.in +script_DATA = otk.py + +EXTRA_DIST = $(script_DATA) + distclean-local: rm -f *\~ *.orig *.rej .\#* @@ -31,68 +36,10 @@ otk_test: libotk.la otk_test.cc rendertest: libotk.la rendertest.cc $(CXX) $(CXXFLAGS) -DHAVE_CONFIG_H -I. -I. -I.. -I../src $(XFT_CFLAGS) -Wall -W -pedantic -DNDEBUG -g -O2 -o $@ rendertest.cc $(XFT_LIBS) .libs/libotk.al @LIBS@ -#otk.i: $(wildcard *.hh) -# touch $@ +otk.i: $(wildcard *.hh) + touch $@ -#otk_wrap.cc: otk.i -# swig $(filter -I%,$(CXXFLAGS)) -python -shadow -c++ -o $@ $< +%_wrap.cc: %.i + swig -c $(filter -I%,$(CXXFLAGS)) -python -shadow -c++ -nodefault -o $@ $< # local dependencies -application.o: application.cc application.hh eventdispatcher.hh \ - eventhandler.hh display.hh configuration.hh \ - timer.hh image.hh color.hh screeninfo.hh rect.hh \ - point.hh style.hh font.hh texture.hh util.hh widget.hh -appwidget.o: appwidget.cc appwidget.hh widget.hh rect.hh point.hh \ - texture.hh color.hh util.hh style.hh font.hh image.hh screeninfo.hh \ - timer.hh configuration.hh eventdispatcher.hh eventhandler.hh \ - application.hh display.hh -button.o: button.cc button.hh focuslabel.hh focuswidget.hh widget.hh \ - rect.hh point.hh texture.hh color.hh util.hh style.hh font.hh \ - image.hh screeninfo.hh timer.hh configuration.hh eventdispatcher.hh \ - eventhandler.hh application.hh display.hh -color.o: color.cc color.hh display.hh screeninfo.hh rect.hh point.hh -configuration.o: configuration.cc configuration.hh util.hh -eventdispatcher.o: eventdispatcher.cc eventdispatcher.hh \ - eventhandler.hh display.hh -eventhandler.o: eventhandler.cc eventhandler.hh -focuslabel.o: focuslabel.cc focuslabel.hh focuswidget.hh widget.hh \ - rect.hh point.hh texture.hh color.hh util.hh style.hh font.hh \ - image.hh screeninfo.hh timer.hh configuration.hh eventdispatcher.hh \ - eventhandler.hh application.hh display.hh -focuswidget.o: focuswidget.cc focuswidget.hh widget.hh rect.hh \ - point.hh texture.hh color.hh util.hh style.hh font.hh image.hh \ - screeninfo.hh timer.hh configuration.hh eventdispatcher.hh \ - eventhandler.hh application.hh display.hh -font.o: font.cc font.hh util.hh display.hh color.hh screeninfo.hh \ - rect.hh point.hh -gccache.o: gccache.cc gccache.hh display.hh color.hh assassin.hh \ - screeninfo.hh rect.hh point.hh -image.o: image.cc display.hh gccache.hh color.hh image.hh \ - screeninfo.hh rect.hh point.hh timer.hh texture.hh util.hh -imagecontrol.o: imagecontrol.cc display.hh color.hh image.hh \ - screeninfo.hh rect.hh point.hh timer.hh texture.hh util.hh -label.o: label.cc label.hh widget.hh rect.hh point.hh texture.hh \ - color.hh util.hh style.hh font.hh image.hh screeninfo.hh timer.hh \ - configuration.hh eventdispatcher.hh eventhandler.hh application.hh \ - display.hh -otk_test.o: otk_test.cc application.hh eventdispatcher.hh \ - eventhandler.hh display.hh configuration.hh \ - timer.hh image.hh color.hh screeninfo.hh rect.hh \ - point.hh style.hh font.hh texture.hh util.hh focuswidget.hh widget.hh \ - appwidget.hh button.hh focuslabel.hh -property.o: property.cc property.hh screeninfo.hh rect.hh point.hh \ - display.hh -rect.o: rect.cc rect.hh point.hh -screeninfo.o: screeninfo.cc screeninfo.hh rect.hh point.hh display.hh \ - util.hh -style.o: style.cc display.hh util.hh style.hh color.hh font.hh \ - texture.hh image.hh screeninfo.hh rect.hh point.hh timer.hh \ - configuration.hh -texture.o: texture.cc texture.hh color.hh util.hh display.hh image.hh \ - screeninfo.hh rect.hh point.hh timer.hh -timer.o: timer.cc timer.hh -util.o: util.cc util.hh -widget.o: widget.cc widget.hh rect.hh point.hh texture.hh color.hh \ - util.hh style.hh font.hh image.hh screeninfo.hh timer.hh \ - configuration.hh eventdispatcher.hh eventhandler.hh application.hh \ - display.hh assassin.hh diff --git a/otk/otk.i b/otk/otk.i index bda7ce97..ed666e56 100644 --- a/otk/otk.i +++ b/otk/otk.i @@ -14,35 +14,40 @@ //%include std_list.i %include "ustring.i" -%ignore otk::OBDisplay::display; +%ignore otk::display; %inline %{ - Display *OBDisplay_display() { return otk::OBDisplay::display; } + otk::Display *Display_instance() { return otk::display; } +%}; + +%ignore otk::Property::atoms; +%inline %{ + const otk::Atoms& Property_atoms() { return otk::Property::atoms; } %}; namespace otk { -%rename(setValue_bool) Configuration::setValue(std::string const &,bool); +/*%rename(setValue_bool) Configuration::setValue(std::string const &,bool); %rename(setValue_unsigned) Configuration::setValue(const std::string &, unsigned int); %rename(setValue_long) Configuration::setValue(const std::string &, long); %rename(setValue_unsignedlong) Configuration::setValue(const std::string &, unsigned long); %rename(setValue_string) Configuration::setValue(const std::string &, const std::string &); -%rename(setValue_charptr) Configuration::setValue(const std::string &, const char *); +%rename(setValue_charptr) Configuration::setValue(const std::string &, const char *);*/ %rename(itostring_unsigned) itostring(unsigned int); %rename(itostring_long) itostring(long); %rename(itostring_unsigned_long) itostring(unsigned long); // these are needed for guile, but not needed for python! -%rename(equals) BColor::operator==; -%rename(equals) Rect::operator==; -%rename(equals) BTexture::operator==; -%ignore BColor::operator!=; -%ignore BTexture::operator!=; +//%rename(equals) BColor::operator==; +//%rename(equals) Rect::operator==; +//%rename(equals) BTexture::operator==; +//%ignore BColor::operator!=; +//%ignore BTexture::operator!=; %ignore Rect::operator!=; %ignore Rect::operator|; %ignore Rect::operator|=; %ignore Rect::operator&; %ignore Rect::operator&=; -%ignore OBTimer::operator<; +//%ignore OBTimer::operator<; %ignore TimerLessThan; /* @@ -52,8 +57,13 @@ namespace otk { */ } -%include "eventdispatcher.hh" %include "eventhandler.hh" +%include "eventdispatcher.hh" +%include "point.hh" +%include "rect.hh" +%include "rendercolor.hh" +%include "rendertexture.hh" +%include "renderstyle.hh" %include "widget.hh" %include "focuswidget.hh" %include "focuslabel.hh" @@ -61,23 +71,16 @@ namespace otk { %include "application.hh" %include "assassin.hh" %include "button.hh" -%include "color.hh" -%include "configuration.hh" +//%include "configuration.hh" %include "display.hh" %include "font.hh" -%include "gccache.hh" -%include "image.hh" +%include "rendercontrol.hh" %include "label.hh" -%include "point.hh" %include "property.hh" -%include "rect.hh" %include "screeninfo.hh" %include "strut.hh" -%include "style.hh" -%include "texture.hh" %include "timer.hh" %include "util.hh" -%include "widget.hh" // for Mod1Mask etc %include "X11/X.h" diff --git a/otk/rendercolor.hh b/otk/rendercolor.hh index c5835385..8ed8ce58 100644 --- a/otk/rendercolor.hh +++ b/otk/rendercolor.hh @@ -10,20 +10,19 @@ extern "C" { namespace otk { -class RenderColor { -public: - struct RGB { - int r; - int g; - int b; - RGB(int red, int green, int blue) : r(red), g(green), b(blue) {} - // color is in ARGB format - RGB(unsigned long color) - : r((color >> 16) & 0xff), - g((color >> 8) & 0xff), - b((color) & 0xff) {} - }; +struct RGB { + int r; + int g; + int b; + RGB(int red, int green, int blue) : r(red), g(green), b(blue) {} + // color is in ARGB format + RGB(unsigned long color) + : r((color >> 16) & 0xff), + g((color >> 8) & 0xff), + b((color) & 0xff) {} +}; +class RenderColor { private: struct CacheItem { GC gc; diff --git a/otk/rendertexture.hh b/otk/rendertexture.hh index 8e588558..54fbd9c2 100644 --- a/otk/rendertexture.hh +++ b/otk/rendertexture.hh @@ -70,10 +70,10 @@ public: RenderTexture(int screen, bool parent_relative, ReliefType relief, BevelType bevel, bool border, GradientType gradient, bool interlaced, - const RenderColor::RGB &color, - const RenderColor::RGB &secondary_color, - const RenderColor::RGB &border_color, - const RenderColor::RGB &interlace_color) + const RGB &color, + const RGB &secondary_color, + const RGB &border_color, + const RGB &interlace_color) : _screen(screen), _parent_relative(parent_relative), _relief(relief), diff --git a/scripts/callbacks.py b/scripts/callbacks.py index caea7586..1289a7bb 100644 --- a/scripts/callbacks.py +++ b/scripts/callbacks.py @@ -1,35 +1,45 @@ -########################################################################### -### Functions that can be used as callbacks for mouse/keyboard bindings ### -########################################################################### +############################################################################ +### Functions that can be used as callbacks for mouse/keyboard bindings ### +############################################################################ + +############################################################################# +### Options that can be modified to change the default hooks' behaviors. ### +### ### +# resize_nearest - 1 to resize from the corner nearest where the mouse ### +### is, 0 to resize always from the bottom right corner. ### +resize_nearest = 1 ### +### ### +############################################################################# import ob +import otk def state_above(data, add=2): """Toggles, adds or removes the 'above' state on a window.""" if not data.client: return - ob.send_client_msg(ob.display.screenInfo(data.screen).rootWindow(), - ob.Property_atoms().net_wm_state, data.client.window(), - add, ob.Property_atoms().net_wm_state_above) + ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(), + otk.Property_atoms().net_wm_state, data.client.window(), + add, otk.Property_atoms().net_wm_state_above) def state_below(data, add=2): """Toggles, adds or removes the 'below' state on a window.""" if not data.client: return - ob.send_client_msg(ob.display.screenInfo(data.screen).rootWindow(), - ob.Property_atoms().net_wm_state, data.client.window(), - add, ob.Property_atoms().net_wm_state_below) + ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(), + otk.Property_atoms().net_wm_state, data.client.window(), + add, otk.Property_atoms().net_wm_state_below) def state_shaded(data, add=2): """Toggles, adds or removes the 'shaded' state on a window.""" if not data.client: return - ob.send_client_msg(ob.display.screenInfo(data.screen).rootWindow(), - ob.Property_atoms().net_wm_state, data.client.window(), - add, ob.Property_atoms().net_wm_state_shaded) + ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(), + otk.Property_atoms().net_wm_state, data.client.window(), + add, otk.Property_atoms().net_wm_state_shaded) def iconify(data): """Iconifies the window on which the event occured""" if not data.client: return - ob.send_client_msg(ob.display.screenInfo(data.screen).rootWindow(), - ob.Property_atoms().wm_change_state, + ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(), + otk.Property_atoms().wm_change_state, data.client.window(), 3) # IconicState def restore(data): @@ -37,15 +47,15 @@ def restore(data): if. If you want to focus the window too, it is recommended that you use the activate() function.""" if not data.client: return - ob.send_client_msg(ob.display.screenInfo(data.screen).rootWindow(), - ob.Property_atoms().wm_change_state, + ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(), + otk.Property_atoms().wm_change_state, data.client.window(), 1) # NormalState def close(data): """Closes the window on which the event occured""" if not data.client: return - ob.send_client_msg(ob.display.screenInfo(data.screen).rootWindow(), - ob.Property_atoms().net_close_window, + ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(), + otk.Property_atoms().net_close_window, data.client.window(), 0) def focus(data): @@ -83,23 +93,23 @@ def resize(data): # pick a corner to anchor if not (resize_nearest or data.context == MC_Grip): - corner = Client.TopLeft + corner = ob.Client.TopLeft else: x = px - data.press_clientx y = py - data.press_clienty if y < data.press_clientheight / 2: if x < data.press_clientwidth / 2: - corner = Client.BottomRight + corner = ob.Client.BottomRight dx *= -1 else: - corner = Client.BottomLeft + corner = ob.Client.BottomLeft dy *= -1 else: if x < data.press_clientwidth / 2: - corner = Client.TopRight + corner = ob.Client.TopRight dx *= -1 else: - corner = Client.TopLeft + corner = ob.Client.TopLeft data.client.resize(corner, data.press_clientwidth + dx, @@ -133,8 +143,8 @@ def unshade(data): def change_desktop(data, num): """Switches to a specified desktop""" - root = ob.display.screenInfo(data.screen).rootWindow() - ob.send_client_msg(root, ob.Property_atoms().net_current_desktop, + root = otk.display.screenInfo(data.screen).rootWindow() + ob.send_client_msg(root, otk.Property_atoms().net_current_desktop, root, num) def next_desktop(data, no_wrap=0): @@ -164,8 +174,8 @@ def prev_desktop(data, no_wrap=0): def send_to_desktop(data, num): """Sends a client to a specified desktop""" if not data.client: return - ob.send_client_msg(ob.display.screenInfo(data.screen).rootWindow(), - ob.Property_atoms().net_wm_desktop, + ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(), + otk.Property_atoms().net_wm_desktop, data.client.window(),num) def toggle_all_desktops(data): diff --git a/scripts/config.py b/scripts/config.py index e59360be..823d9d3f 100644 --- a/scripts/config.py +++ b/scripts/config.py @@ -30,15 +30,5 @@ desktop_names = ["one", "two", "three", "four", "five", "six", "seven", \ # between. number_of_desktops = 4 -############################################################################# -### Options that can be modified by the user to change the default hooks' ### -### behaviors. ### -############################################################################# - -# resize_nearest - 1 to resize from the corner nearest where the mouse is, 0 -# to resize always from the bottom right corner. -resize_nearest = 1 - - print "Loaded config.py" diff --git a/scripts/windowplacement.py b/scripts/windowplacement.py index 127cd2ad..81d260e8 100644 --- a/scripts/windowplacement.py +++ b/scripts/windowplacement.py @@ -3,6 +3,7 @@ ### ob.EventAction.PlaceWindow event. ### ############################################################################ +import otk import ob import random @@ -13,6 +14,8 @@ def random(data): client_area = data.client.area() frame_size = data.client.frame.size() screen_area = ob.openbox.screen(data.screen).area() + print str(screen_area.x()) + " " + str(screen_area.y()) + " " + \ + str(screen_area.width()) + " " + str(screen_area.height()) width = screen_area.width() - (client_area.width() + frame_size.left + frame_size.right) height = screen_area.height() - (client_area.height() + diff --git a/src/Makefile.am b/src/Makefile.am index e697fc45..0b35f72a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -15,7 +15,7 @@ INCLUDES= -I.. bin_PROGRAMS= openbox3 -openbox3_LDADD=-L../otk -lotk @LIBINTL@ +openbox3_LDADD=-L../otk -lotk -lswigpy @LIBINTL@ openbox3_SOURCES= actions.cc client.cc frame.cc openbox.cc screen.cc \ main.cc backgroundwidget.cc labelwidget.cc \ @@ -35,7 +35,7 @@ distclean-local: openbox.i: openbox.hh screen.hh client.hh python.hh frame.hh touch $@ -openbox_wrap.cc: openbox.i - swig -I../otk $(filter -I%,$(CXXFLAGS)) -python -shadow -c++ -nodefault -o $@ $< +%_wrap.cc: %.i + swig -c -I../otk $(filter -I%,$(CXXFLAGS)) -python -shadow -c++ -nodefault -o $@ $< # local dependencies diff --git a/src/client.cc b/src/client.cc index 2c3d3ad3..eeb09a37 100644 --- a/src/client.cc +++ b/src/client.cc @@ -575,8 +575,8 @@ void Client::updateStrut() _strut.left = data[0]; _strut.right = data[1]; _strut.top = data[2]; - _strut.bottom = data[3]; - + _strut.bottom = data[3]; + openbox->screen(_screen)->updateStrut(); } diff --git a/src/openbox.i b/src/openbox.i index 7ab588e1..b3d1a9ed 100644 --- a/src/openbox.i +++ b/src/openbox.i @@ -110,6 +110,7 @@ void python_callback(PyObject *func, KeyData *data) } }; +/* %include "../otk/ustring.i" %ignore otk::display; @@ -133,6 +134,9 @@ void python_callback(PyObject *func, KeyData *data) %include "../otk/eventdispatcher.hh" %import "../otk/widget.hh" +*/ +%import "../otk/otk.i" + %import "widgetbase.hh" %import "actions.hh" diff --git a/src/python.cc b/src/python.cc index f95d4723..a7e2eada 100644 --- a/src/python.cc +++ b/src/python.cc @@ -9,8 +9,9 @@ #include "otk/util.hh" extern "C" { -// The initializer in openbox_wrap.cc +// The initializer in openbox_wrap.cc / otk_wrap.cc extern void init_ob(void); +extern void init_otk(void); } namespace ob { @@ -23,6 +24,7 @@ void python_init(char *argv0) Py_SetProgramName(argv0); Py_Initialize(); // initialize the C python module + init_otk(); init_ob(); // include the openbox directories for python scripts in the sys path PyRun_SimpleString("import sys"); @@ -30,10 +32,10 @@ void python_init(char *argv0) otk::expandTilde("~/.openbox/python") + "')").c_str())); PyRun_SimpleString("sys.path.append('" SCRIPTDIR "')"); - PyRun_SimpleString("import ob;"); + PyRun_SimpleString("import ob; import otk;"); // set up convenience global variables PyRun_SimpleString("ob.openbox = ob.Openbox_instance()"); - PyRun_SimpleString("ob.display = ob.Display_instance()"); + PyRun_SimpleString("otk.display = otk.Display_instance()"); // set up access to the python global variables PyObject *obmodule = PyImport_AddModule("config"); diff --git a/src/screen.cc b/src/screen.cc index 51a6f76e..6c1551b5 100644 --- a/src/screen.cc +++ b/src/screen.cc @@ -261,7 +261,7 @@ void Screen::calcArea() #endif // XINERAMA */ - if (old_area != _area) + //if (old_area != _area) // XXX: re-maximize windows changeWorkArea();