use otk objects in the ob scripts by importing otk

This commit is contained in:
Dana Jansens 2003-01-27 13:42:41 +00:00
parent 5168a8add5
commit 5face4c6f3
12 changed files with 106 additions and 148 deletions

View file

@ -1,4 +1,5 @@
buttonsdir = $(pkgdatadir)/buttons buttonsdir = $(pkgdatadir)/buttons
scriptdir = $(libdir)/openbox/python
CXXFLAGS=$(XFT_CFLAGS) $(PYTHON_CFLAGS) @CXXFLAGS@ \ CXXFLAGS=$(XFT_CFLAGS) $(PYTHON_CFLAGS) @CXXFLAGS@ \
-DBUTTONSDIR=\"$(buttonsdir)\" -DBUTTONSDIR=\"$(buttonsdir)\"
@ -6,7 +7,7 @@ CXXFLAGS=$(XFT_CFLAGS) $(PYTHON_CFLAGS) @CXXFLAGS@ \
INCLUDES= -I../src INCLUDES= -I../src
#noinst_LIBRARIES=libotk.a #noinst_LIBRARIES=libotk.a
noinst_LTLIBRARIES=libotk.la lib_LTLIBRARIES=libotk.la
libotk_la_SOURCES=rendercontrol.cc truerendercontrol.cc surface.cc \ libotk_la_SOURCES=rendercontrol.cc truerendercontrol.cc surface.cc \
renderstyle.cc rendercolor.cc \ renderstyle.cc rendercolor.cc \
@ -15,13 +16,17 @@ libotk_la_SOURCES=rendercontrol.cc truerendercontrol.cc surface.cc \
timer.cc \ timer.cc \
configuration.cc util.cc widget.cc focuswidget.cc \ configuration.cc util.cc widget.cc focuswidget.cc \
button.cc eventhandler.cc eventdispatcher.cc ustring.cc \ button.cc eventhandler.cc eventdispatcher.cc ustring.cc \
label.cc focuslabel.cc application.cc appwidget.cc label.cc focuslabel.cc application.cc appwidget.cc \
# otk_wrap.cc otk_wrap.cc
libotk_la_LDFLAGS = $(XFT_LIBS) $(PYTHON_LIBS) @LIBS@ libotk_la_LDFLAGS = $(XFT_LIBS) $(PYTHON_LIBS) @LIBS@
MAINTAINERCLEANFILES= Makefile.in MAINTAINERCLEANFILES= Makefile.in
script_DATA = otk.py
EXTRA_DIST = $(script_DATA)
distclean-local: distclean-local:
rm -f *\~ *.orig *.rej .\#* rm -f *\~ *.orig *.rej .\#*
@ -31,68 +36,10 @@ otk_test: libotk.la otk_test.cc
rendertest: libotk.la rendertest.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@ $(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) otk.i: $(wildcard *.hh)
# touch $@ touch $@
#otk_wrap.cc: otk.i %_wrap.cc: %.i
# swig $(filter -I%,$(CXXFLAGS)) -python -shadow -c++ -o $@ $< swig -c $(filter -I%,$(CXXFLAGS)) -python -shadow -c++ -nodefault -o $@ $<
# local dependencies # 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

View file

@ -14,35 +14,40 @@
//%include std_list.i //%include std_list.i
%include "ustring.i" %include "ustring.i"
%ignore otk::OBDisplay::display; %ignore otk::display;
%inline %{ %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 { 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_unsigned) Configuration::setValue(const std::string &, unsigned int);
%rename(setValue_long) Configuration::setValue(const std::string &, long); %rename(setValue_long) Configuration::setValue(const std::string &, long);
%rename(setValue_unsignedlong) Configuration::setValue(const std::string &, unsigned long); %rename(setValue_unsignedlong) Configuration::setValue(const std::string &, unsigned long);
%rename(setValue_string) Configuration::setValue(const std::string &, const std::string &); %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_unsigned) itostring(unsigned int);
%rename(itostring_long) itostring(long); %rename(itostring_long) itostring(long);
%rename(itostring_unsigned_long) itostring(unsigned long); %rename(itostring_unsigned_long) itostring(unsigned long);
// these are needed for guile, but not needed for python! // these are needed for guile, but not needed for python!
%rename(equals) BColor::operator==; //%rename(equals) BColor::operator==;
%rename(equals) Rect::operator==; //%rename(equals) Rect::operator==;
%rename(equals) BTexture::operator==; //%rename(equals) BTexture::operator==;
%ignore BColor::operator!=; //%ignore BColor::operator!=;
%ignore BTexture::operator!=; //%ignore BTexture::operator!=;
%ignore Rect::operator!=; %ignore Rect::operator!=;
%ignore Rect::operator|; %ignore Rect::operator|;
%ignore Rect::operator|=; %ignore Rect::operator|=;
%ignore Rect::operator&; %ignore Rect::operator&;
%ignore Rect::operator&=; %ignore Rect::operator&=;
%ignore OBTimer::operator<; //%ignore OBTimer::operator<;
%ignore TimerLessThan; %ignore TimerLessThan;
/* /*
@ -52,8 +57,13 @@ namespace otk {
*/ */
} }
%include "eventdispatcher.hh"
%include "eventhandler.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 "widget.hh"
%include "focuswidget.hh" %include "focuswidget.hh"
%include "focuslabel.hh" %include "focuslabel.hh"
@ -61,23 +71,16 @@ namespace otk {
%include "application.hh" %include "application.hh"
%include "assassin.hh" %include "assassin.hh"
%include "button.hh" %include "button.hh"
%include "color.hh" //%include "configuration.hh"
%include "configuration.hh"
%include "display.hh" %include "display.hh"
%include "font.hh" %include "font.hh"
%include "gccache.hh" %include "rendercontrol.hh"
%include "image.hh"
%include "label.hh" %include "label.hh"
%include "point.hh"
%include "property.hh" %include "property.hh"
%include "rect.hh"
%include "screeninfo.hh" %include "screeninfo.hh"
%include "strut.hh" %include "strut.hh"
%include "style.hh"
%include "texture.hh"
%include "timer.hh" %include "timer.hh"
%include "util.hh" %include "util.hh"
%include "widget.hh"
// for Mod1Mask etc // for Mod1Mask etc
%include "X11/X.h" %include "X11/X.h"

View file

@ -10,20 +10,19 @@ extern "C" {
namespace otk { namespace otk {
class RenderColor { struct RGB {
public: int r;
struct RGB { int g;
int r; int b;
int g; RGB(int red, int green, int blue) : r(red), g(green), b(blue) {}
int b; // color is in ARGB format
RGB(int red, int green, int blue) : r(red), g(green), b(blue) {} RGB(unsigned long color)
// color is in ARGB format : r((color >> 16) & 0xff),
RGB(unsigned long color) g((color >> 8) & 0xff),
: r((color >> 16) & 0xff), b((color) & 0xff) {}
g((color >> 8) & 0xff), };
b((color) & 0xff) {}
};
class RenderColor {
private: private:
struct CacheItem { struct CacheItem {
GC gc; GC gc;

View file

@ -70,10 +70,10 @@ public:
RenderTexture(int screen, RenderTexture(int screen,
bool parent_relative, ReliefType relief, BevelType bevel, bool parent_relative, ReliefType relief, BevelType bevel,
bool border, GradientType gradient, bool interlaced, bool border, GradientType gradient, bool interlaced,
const RenderColor::RGB &color, const RGB &color,
const RenderColor::RGB &secondary_color, const RGB &secondary_color,
const RenderColor::RGB &border_color, const RGB &border_color,
const RenderColor::RGB &interlace_color) const RGB &interlace_color)
: _screen(screen), : _screen(screen),
_parent_relative(parent_relative), _parent_relative(parent_relative),
_relief(relief), _relief(relief),

View file

@ -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 ob
import otk
def state_above(data, add=2): def state_above(data, add=2):
"""Toggles, adds or removes the 'above' state on a window.""" """Toggles, adds or removes the 'above' state on a window."""
if not data.client: return if not data.client: return
ob.send_client_msg(ob.display.screenInfo(data.screen).rootWindow(), ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
ob.Property_atoms().net_wm_state, data.client.window(), otk.Property_atoms().net_wm_state, data.client.window(),
add, ob.Property_atoms().net_wm_state_above) add, otk.Property_atoms().net_wm_state_above)
def state_below(data, add=2): def state_below(data, add=2):
"""Toggles, adds or removes the 'below' state on a window.""" """Toggles, adds or removes the 'below' state on a window."""
if not data.client: return if not data.client: return
ob.send_client_msg(ob.display.screenInfo(data.screen).rootWindow(), ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
ob.Property_atoms().net_wm_state, data.client.window(), otk.Property_atoms().net_wm_state, data.client.window(),
add, ob.Property_atoms().net_wm_state_below) add, otk.Property_atoms().net_wm_state_below)
def state_shaded(data, add=2): def state_shaded(data, add=2):
"""Toggles, adds or removes the 'shaded' state on a window.""" """Toggles, adds or removes the 'shaded' state on a window."""
if not data.client: return if not data.client: return
ob.send_client_msg(ob.display.screenInfo(data.screen).rootWindow(), ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
ob.Property_atoms().net_wm_state, data.client.window(), otk.Property_atoms().net_wm_state, data.client.window(),
add, ob.Property_atoms().net_wm_state_shaded) add, otk.Property_atoms().net_wm_state_shaded)
def iconify(data): def iconify(data):
"""Iconifies the window on which the event occured""" """Iconifies the window on which the event occured"""
if not data.client: return if not data.client: return
ob.send_client_msg(ob.display.screenInfo(data.screen).rootWindow(), ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
ob.Property_atoms().wm_change_state, otk.Property_atoms().wm_change_state,
data.client.window(), 3) # IconicState data.client.window(), 3) # IconicState
def restore(data): def restore(data):
@ -37,15 +47,15 @@ def restore(data):
if. If you want to focus the window too, it is recommended that you if. If you want to focus the window too, it is recommended that you
use the activate() function.""" use the activate() function."""
if not data.client: return if not data.client: return
ob.send_client_msg(ob.display.screenInfo(data.screen).rootWindow(), ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
ob.Property_atoms().wm_change_state, otk.Property_atoms().wm_change_state,
data.client.window(), 1) # NormalState data.client.window(), 1) # NormalState
def close(data): def close(data):
"""Closes the window on which the event occured""" """Closes the window on which the event occured"""
if not data.client: return if not data.client: return
ob.send_client_msg(ob.display.screenInfo(data.screen).rootWindow(), ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
ob.Property_atoms().net_close_window, otk.Property_atoms().net_close_window,
data.client.window(), 0) data.client.window(), 0)
def focus(data): def focus(data):
@ -83,23 +93,23 @@ def resize(data):
# pick a corner to anchor # pick a corner to anchor
if not (resize_nearest or data.context == MC_Grip): if not (resize_nearest or data.context == MC_Grip):
corner = Client.TopLeft corner = ob.Client.TopLeft
else: else:
x = px - data.press_clientx x = px - data.press_clientx
y = py - data.press_clienty y = py - data.press_clienty
if y < data.press_clientheight / 2: if y < data.press_clientheight / 2:
if x < data.press_clientwidth / 2: if x < data.press_clientwidth / 2:
corner = Client.BottomRight corner = ob.Client.BottomRight
dx *= -1 dx *= -1
else: else:
corner = Client.BottomLeft corner = ob.Client.BottomLeft
dy *= -1 dy *= -1
else: else:
if x < data.press_clientwidth / 2: if x < data.press_clientwidth / 2:
corner = Client.TopRight corner = ob.Client.TopRight
dx *= -1 dx *= -1
else: else:
corner = Client.TopLeft corner = ob.Client.TopLeft
data.client.resize(corner, data.client.resize(corner,
data.press_clientwidth + dx, data.press_clientwidth + dx,
@ -133,8 +143,8 @@ def unshade(data):
def change_desktop(data, num): def change_desktop(data, num):
"""Switches to a specified desktop""" """Switches to a specified desktop"""
root = ob.display.screenInfo(data.screen).rootWindow() root = otk.display.screenInfo(data.screen).rootWindow()
ob.send_client_msg(root, ob.Property_atoms().net_current_desktop, ob.send_client_msg(root, otk.Property_atoms().net_current_desktop,
root, num) root, num)
def next_desktop(data, no_wrap=0): def next_desktop(data, no_wrap=0):
@ -164,8 +174,8 @@ def prev_desktop(data, no_wrap=0):
def send_to_desktop(data, num): def send_to_desktop(data, num):
"""Sends a client to a specified desktop""" """Sends a client to a specified desktop"""
if not data.client: return if not data.client: return
ob.send_client_msg(ob.display.screenInfo(data.screen).rootWindow(), ob.send_client_msg(otk.display.screenInfo(data.screen).rootWindow(),
ob.Property_atoms().net_wm_desktop, otk.Property_atoms().net_wm_desktop,
data.client.window(),num) data.client.window(),num)
def toggle_all_desktops(data): def toggle_all_desktops(data):

View file

@ -30,15 +30,5 @@ desktop_names = ["one", "two", "three", "four", "five", "six", "seven", \
# between. # between.
number_of_desktops = 4 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" print "Loaded config.py"

View file

@ -3,6 +3,7 @@
### ob.EventAction.PlaceWindow event. ### ### ob.EventAction.PlaceWindow event. ###
############################################################################ ############################################################################
import otk
import ob import ob
import random import random
@ -13,6 +14,8 @@ def random(data):
client_area = data.client.area() client_area = data.client.area()
frame_size = data.client.frame.size() frame_size = data.client.frame.size()
screen_area = ob.openbox.screen(data.screen).area() 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() + width = screen_area.width() - (client_area.width() +
frame_size.left + frame_size.right) frame_size.left + frame_size.right)
height = screen_area.height() - (client_area.height() + height = screen_area.height() - (client_area.height() +

View file

@ -15,7 +15,7 @@ INCLUDES= -I..
bin_PROGRAMS= openbox3 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 \ openbox3_SOURCES= actions.cc client.cc frame.cc openbox.cc screen.cc \
main.cc backgroundwidget.cc labelwidget.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 openbox.i: openbox.hh screen.hh client.hh python.hh frame.hh
touch $@ touch $@
openbox_wrap.cc: openbox.i %_wrap.cc: %.i
swig -I../otk $(filter -I%,$(CXXFLAGS)) -python -shadow -c++ -nodefault -o $@ $< swig -c -I../otk $(filter -I%,$(CXXFLAGS)) -python -shadow -c++ -nodefault -o $@ $<
# local dependencies # local dependencies

View file

@ -110,6 +110,7 @@ void python_callback(PyObject *func, KeyData *data)
} }
}; };
/*
%include "../otk/ustring.i" %include "../otk/ustring.i"
%ignore otk::display; %ignore otk::display;
@ -133,6 +134,9 @@ void python_callback(PyObject *func, KeyData *data)
%include "../otk/eventdispatcher.hh" %include "../otk/eventdispatcher.hh"
%import "../otk/widget.hh" %import "../otk/widget.hh"
*/
%import "../otk/otk.i"
%import "widgetbase.hh" %import "widgetbase.hh"
%import "actions.hh" %import "actions.hh"

View file

@ -9,8 +9,9 @@
#include "otk/util.hh" #include "otk/util.hh"
extern "C" { 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_ob(void);
extern void init_otk(void);
} }
namespace ob { namespace ob {
@ -23,6 +24,7 @@ void python_init(char *argv0)
Py_SetProgramName(argv0); Py_SetProgramName(argv0);
Py_Initialize(); Py_Initialize();
// initialize the C python module // initialize the C python module
init_otk();
init_ob(); init_ob();
// include the openbox directories for python scripts in the sys path // include the openbox directories for python scripts in the sys path
PyRun_SimpleString("import sys"); PyRun_SimpleString("import sys");
@ -30,10 +32,10 @@ void python_init(char *argv0)
otk::expandTilde("~/.openbox/python") + otk::expandTilde("~/.openbox/python") +
"')").c_str())); "')").c_str()));
PyRun_SimpleString("sys.path.append('" SCRIPTDIR "')"); PyRun_SimpleString("sys.path.append('" SCRIPTDIR "')");
PyRun_SimpleString("import ob;"); PyRun_SimpleString("import ob; import otk;");
// set up convenience global variables // set up convenience global variables
PyRun_SimpleString("ob.openbox = ob.Openbox_instance()"); 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 // set up access to the python global variables
PyObject *obmodule = PyImport_AddModule("config"); PyObject *obmodule = PyImport_AddModule("config");

View file

@ -261,7 +261,7 @@ void Screen::calcArea()
#endif // XINERAMA #endif // XINERAMA
*/ */
if (old_area != _area) //if (old_area != _area)
// XXX: re-maximize windows // XXX: re-maximize windows
changeWorkArea(); changeWorkArea();