Check-in [471330b4ef]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Centralized Boost.Python converter registration in python.cc because, for example, both minxlib::display and minxlib::window return STL vectors of window objects and we would like to avoid registering duplicate converters for the same types, a situation more likely to arise when the converters are registered from the pythonize() functions of the different classes.
Timelines: family | ancestors | descendants | both | dev1.x
Files: files | file ages | folders
SHA1:471330b4ef5a3e469d60078cef49ba79a62bb3a0
User & Date: manuv 2013-07-28 12:49:27
Context
2013-07-28
13:06
  • Forgotten to register exception translators for protocol errors.
  • Add exception handler for generic protocol errors in minx.core.wm event loop.
check-in: fa872bf983 user: manuv tags: dev1.x
12:49
Centralized Boost.Python converter registration in python.cc because, for example, both minxlib::display and minxlib::window return STL vectors of window objects and we would like to avoid registering duplicate converters for the same types, a situation more likely to arise when the converters are registered from the pythonize() functions of the different classes. check-in: 471330b4ef user: manuv tags: dev1.x
12:14
Fixed the sporadic recognitions of key bindings, especially the ones with modifiers. The problem turned out to be a lack of additional grabs with the various combinations of the lock modifiers; without these, the Caps Lock, Num Lock, etc. totally screw up the key binding logic because the X server doesn't even recognize them and, therefore, doesn't generate the necessary keyboard events.

Got the idea for this from a cursory perusal of the code for xbindkeys. And now (at long last) key bindings work flawlessly! Getting close to the 0.2.0 release... check-in: 17ccc163e4 user: manuv tags: dev1.x

Changes

Changes to minxlib/display.cc.

262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
    XEvent e ;
    XNextEvent(m_display, &e) ;
    return event::create(e, m_display) ;
}

//------------------------ PYTHON INTERFACE ----------------------------

// Register Boost.Python converters to convert C++ objects to their
// Python equivalents so that things like std::vector become Python
// lists.
static void register_converters()
{
    typedef std::vector<window> window_list ;
    py::to_python_converter<window_list,
                            universal_converter<window_list> >() ;

    typedef std::vector<root_window> root_window_list ;
    py::to_python_converter<root_window_list,
                            universal_converter<root_window_list> >() ;

    typedef std::vector<std::string> string_list ;
    py::to_python_converter<string_list, universal_converter<string_list> >() ;
}

// Export display class to Python
void display::pythonize()
{
    register_converters() ;

    py::class_<display, boost::noncopyable>("display",
        py::init<std::string, bool>((py::arg("name") = std::string(""),
                                     py::arg("sync") = false ))).
        def("create_window",         &display::create_window   ).
        def("get_root_windows",      &display::get_root_windows).
        def("get_top_level_windows", &display::get_top_level_windows).
        def("get_focused_window",    &display::get_focused_window   ).







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<



<
<







262
263
264
265
266
267
268

















269
270
271


272
273
274
275
276
277
278
    XEvent e ;
    XNextEvent(m_display, &e) ;
    return event::create(e, m_display) ;
}

//------------------------ PYTHON INTERFACE ----------------------------


















// Export display class to Python
void display::pythonize()
{


    py::class_<display, boost::noncopyable>("display",
        py::init<std::string, bool>((py::arg("name") = std::string(""),
                                     py::arg("sync") = false ))).
        def("create_window",         &display::create_window   ).
        def("get_root_windows",      &display::get_root_windows).
        def("get_top_level_windows", &display::get_top_level_windows).
        def("get_focused_window",    &display::get_focused_window   ).

Changes to minxlib/python.cc.

55
56
57
58
59
60
61



























62
63
64
65
66
67
68
69
70
71


72
73
74
75
76
77
78
#include "keymap.hh"
#ifdef MINXLIB_HAS_VERSION_API
#include "version.hh"
#endif
#include "python.hh"

//------------------------ PYTHON INTERFACE ----------------------------




























// Standard Boost.Python idiom for exporting C++ classes and functions
// as part of a Python module. In this case, we expose the relevant
// parts of minxlib as a Python module named "minxlib".
//
// DEVNOTE: The order in which we call the initialization functions
// matters! For example, since root_window is derived from window, we
// must setup the window class's Python wrapper before root_window.
BOOST_PYTHON_MODULE(minxlib)
{


    using namespace minxlib ;
    exception  ::pythonize();
    display    ::pythonize();
    window     ::pythonize();
    root_window::pythonize();
    event      ::pythonize();
    keymap     ::pythonize();







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>










>
>







55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "keymap.hh"
#ifdef MINXLIB_HAS_VERSION_API
#include "version.hh"
#endif
#include "python.hh"

//------------------------ PYTHON INTERFACE ----------------------------

// Register Boost.Python converters to convert C++ objects to their
// Python equivalents and vice versa (so that things like std::vector
// become Python lists and vice versa).
static void register_converters()
{
    using namespace minxlib ;

    typedef std::vector<int> int_list ;
    py::to_python_converter<int_list, universal_converter<int_list> >() ;

    typedef std::vector<std::string> string_list ;
    py::to_python_converter<string_list, universal_converter<string_list> >() ;

    typedef std::vector<window> window_list ;
    py::to_python_converter<window_list,
                            universal_converter<window_list> >() ;

    typedef std::vector<root_window> root_window_list ;
    py::to_python_converter<root_window_list,
                            universal_converter<root_window_list> >() ;

    typedef std::map<std::string, std::string> window_properties ;
    py::to_python_converter<window_properties,
                            universal_converter<window_properties> >() ;
    iterable_converter().from_python<window_properties>() ;
}

// Standard Boost.Python idiom for exporting C++ classes and functions
// as part of a Python module. In this case, we expose the relevant
// parts of minxlib as a Python module named "minxlib".
//
// DEVNOTE: The order in which we call the initialization functions
// matters! For example, since root_window is derived from window, we
// must setup the window class's Python wrapper before root_window.
BOOST_PYTHON_MODULE(minxlib)
{
    register_converters() ;

    using namespace minxlib ;
    exception  ::pythonize();
    display    ::pythonize();
    window     ::pythonize();
    root_window::pythonize();
    event      ::pythonize();
    keymap     ::pythonize();

Changes to minxlib/window.cc.

535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
{
    logger.debug() << "killing window " << m_id << " with brute force" ;
    XKillClient(m_display, m_id) ;
}

//------------------------ PYTHON INTERFACE ----------------------------

static void register_converters()
{
    // STL int vector containing window geometry into a Python list
    typedef std::vector<int> geom ;
    py::to_python_converter<geom, universal_converter<geom> >() ;

    // STL map containing window properties to a Python dictionary
    typedef std::map<std::string, std::string> props ;
    py::to_python_converter<props, universal_converter<props> >() ;

    // On Minx's Python side, set_properties() takes a dict mapping
    // strings to strings; we'd like that converted to an STL map...
    iterable_converter().from_python<std::map<std::string, std::string> >() ;
}

void window::pythonize()
{
    register_converters() ;

    py::class_<window>("window", py::no_init).
        def(py::self == py::self).
        def(py::self != py::self).
        def(py::self == py::other<Window>()  ).
        def(py::self != py::other<Window>()  ).
        def_readonly("id",      &window::m_id).
        def("properties",       &window::properties     ).







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


<
<







535
536
537
538
539
540
541















542
543


544
545
546
547
548
549
550
{
    logger.debug() << "killing window " << m_id << " with brute force" ;
    XKillClient(m_display, m_id) ;
}

//------------------------ PYTHON INTERFACE ----------------------------
















void window::pythonize()
{


    py::class_<window>("window", py::no_init).
        def(py::self == py::self).
        def(py::self != py::self).
        def(py::self == py::other<Window>()  ).
        def(py::self != py::other<Window>()  ).
        def_readonly("id",      &window::m_id).
        def("properties",       &window::properties     ).