Dec 27, 2013

Improve your lazy debugging in C++

Are you too lazy to learn your debugger? When debugging, I usually want to know if some code section is reached.

I can do this:


void foobar() {
    printf("foobar()\n");
    // ... do foobar
}

But I should use cout instead printf in C++ . printf is faster, but in this case it should be irrelevant. So I have:


void foobar() {
    std::cout << "foobar()" << std::endl;
    // ... do foobar
}

I could also use GCC's function name macro __PRETTY_FUNCTION__ and __LINE__ macro to identify the reached code section easier.


void foobar() {
    std::cout <<  __PRETTY_FUNCTION__ << " at line " <<  __LINE__ << std::endl;
    // ... do foobar
}

Add that on a macro to reuse it:


#if DEBUG
#include 
#define REACH std::cout <<  __PRETTY_FUNCTION__ << " at line " <<  __LINE__ << std::endl;
#endif

void foobar() {
    REACH
    // ... do foobar
}

And happy debugging!

Not.

Dec 19, 2013

How to set a X window visible or invisible using Xlib


bool m_visible;
Display* m_display;
Window m_window;

void setVisible(bool visible)
{
    if (visible == m_visible)
        return;

    if (visible)
        XMapWindow(m_display, m_window);
    else
        XUnmapWindow(m_display, m_window);

    m_visible = visible;
}

Oct 3, 2013

Functional Pattern Matching with Python

This talk as given at Python Brasil 2013, at Brasília.

Aug 23, 2013

Jun 11, 2013

Nix

For the last few months my team (OpenBossa) at INDT (Instituto Nokia de Tecnologia) have been working on WebKitNix (Nix for short). WebKitNix is a new WebKit2 port, fully based on POSIX and OpenGL. We also use CMake build system (like GTK and Efl), GLib, libsoup (networking) and Cairo (2D graphics) as dependencies. It also uses Coordinated Graphics and Tiled Backing Store from WebKit2. Many of its building blocks are shared with others ports already on trunk.

The Nix port offers a C API for rendering a WebView within a OpenGL context, based on WebKit2 API. You can use Nix to create applications such as a web browser or a web runtime. WebKit2 run the context for each web page in a different process. This process isolation keeps the UI responsive, with smooth animations and scrolling, because it does not get blocked by Javascript execution.

We want to ease the work of Consumer Electronics developers who wants to have a web runtime in their platform, without the need to create another WebKit port. That is why Nix has less dependencies than Efl, GTK or Qt, which should also be ported to the target platform.

Nix API also enables the application to interact with the Javascript context. So it is possible to add new APIs, to handle application specific features.

How did it started?

The OpenBossa team used to maintain the Qt WebKit port for years, helping Nokia/Trolltech. But then, in the last years, from the experience gathered with the Snowshoe browser, handling with dependencies (such as QtNetwork) that were much bigger than we really needed. We tried to replace some dependencies of QtWebKit and later Efl to see how minimal WebKit could be. So we took some steps:

  1. Initial idea: platform/posix or platform/glib (share code)
  2. Ivolved problem: we wanted to have different behaviors for QQuickWebView -> Qt Raw WebView
  3. Network: QtWebKit + Soup experiment
  4. Efl Raw WebView experiment
  5. Efl Without Efl :-)
  6. Nix

How to use it?

When you compile Nix source code you can run the MiniBrowser to test it:

$ $WEBKITOUTPUTDIR/Release/bin/MiniBrowser http://maps.nokia.com

MiniBrowser code

The Nix-Demos repository offers some example code, including a Glut based browser and minimal Python bindings for Nix: https://github.com/WebKitNix/nix-demos.

On Nix-Demos we also have a Nix view, using only a DispmanX and OpenGL ES 2 working on the Raspberry Pi. To compile this demo, you will need our RaspberryPi SDK .

There is even a browser with its UI written in HTML: Drowser

Feel free to contact us on #webkitnix at freenode.

Roadmap

Our plan is to upstream Nix in WebKit trunk by June/2013. Then, keep the maintainence and focus on the web platform, including some new HTML5 features, such as WebRTC.

May 30, 2013

Why is Python slow? Python Nordeste 2013

It was a great event! Thanks to everyone who made it happen.