maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Maemo 5 / Fremantle (https://talk.maemo.org/forumdisplay.php?f=40)
-   -   SDL on N900 / Maemo (https://talk.maemo.org/showthread.php?t=74299)

droll 2011-06-24 05:08

SDL on N900 / Maemo
 
i am new to Linux / N900 / SDL programming. but I am not new to mobile development (11 years) or programming (>25 years). i have experience in C and C++ plus a few other languages.

i am currently picking up an app that someone wrote here but has since abandoned a long time ago. this app uses SDL.

the app is written in C to keep things simple. i call SDL_WM_ToggleFullScreen to get the app into full screen. everything works fine except - i can't use the CTRL-BACKSPACE key combo on the N900 to switch back out to the task viewer or desktop.

the only way i can get out is to hit the power button at the top which brings down a menu and if i wait a few seconds it then goes back out to the desktop. i can then swap to the task manager and see my app's window.

is there a way to pass the CTRL-BACKSPACE key combination back to the operating system instead of having it trapped by SDL? or is there another way to handle this?

my thoughts now are to have a key in my app that allows the user to toggle between full screen and windowed mode. but ideally i would like my app to run in full screen all the time but still give the flexibility to the user to task out and say respond to an incoming SMS.

dwaradzyn 2011-06-24 06:03

Re: SDL on N900 / Maemo
 
Using D-Bus is the answer:

Code:


#include <dbus/dbus.h>

void invokeTaskManager() {
        DBusConnection* bus = NULL;
        DBusMessage* msg = NULL;
        DBusError error;

        dbus_error_init(&error);

        bus = dbus_bus_get(DBUS_BUS_SESSION, &error);

        if (bus == NULL) {
                fprintf(stderr, "bus == NULL\n");
                return;
        }

        // create a signal and check for errors
        msg = dbus_message_new_signal("/com/nokia/hildon_desktop", // path
                        "com.nokia.hildon_desktop", // interface
                        "exit_app_view"); // method str
        if (NULL == msg) {
                fprintf(stderr, "Message Null\n");
                exit(1);
        }

        // send the message and flush the connection
        if (!dbus_connection_send(bus, msg, NULL)) {
                fprintf(stderr, "Out Of Memory!\n");
                exit(1);
        }

        dbus_connection_flush(bus);
        dbus_message_unref(msg);
}


droll 2011-06-24 06:29

Re: SDL on N900 / Maemo
 
aaaaaaaaah thank u. thanks for the code snippet too.

let me try to figure out how to integrate this. i'm guessing i should run the code when i detect ctrl-backspace in SDL, yes?

Zas 2011-06-24 06:58

Re: SDL on N900 / Maemo
 
Include stdlib.h and you can use the code:
Code:

system("dbus-send /com/nokia/hildon_desktop com.nokia.hildon_desktop.exit_app_view");
to do this.

You can either add a key combination or an on screen button much like the one originally in hildon windows. Ctrl+backspace works when I code in SDL & c++. Don't know why it doesn't for you.

droll 2011-06-24 07:04

Re: SDL on N900 / Maemo
 
got it working nicely. thanks!!!!

i basically capture a keycode which i designate for activating the task manager. perfect.

i don't know why ctrl-backspace doesn't work yet since i just started looking through the sources of that app. are you running in full screen mode?

droll 2011-06-24 07:07

Re: SDL on N900 / Maemo
 
hmmmmmmmmm gotta spend a bit more time debugging the code though. if i manage to get toggle to the task manager ONCE, then ctrl-backspace works nicely thereafter without needing dbus.

but if i don't toggle to the task manager for the first time, ctrl-backspace doesn't work.

Mentalist Traceur 2011-06-24 07:17

Re: SDL on N900 / Maemo
 
Personally I think the user should have options to have either fullscreen or not - you can still make your preference the default without actually limiting user choice to make the app full-screen or not. Of course, some apps would be hard to properly scale to both fullscreen/'normal', so can't really be picky if that's the case.

Zas 2011-06-24 07:18

Re: SDL on N900 / Maemo
 
Maybe its the way you go to fullscreen. Have you tried creating the screen surface already as a fullscreen surface with "SDL_SWSURFACE|SDL_FULLSCREEN"

droll 2011-06-24 07:26

Re: SDL on N900 / Maemo
 
nevermind. fixed it. all is fine and dandy. no need to use dbus anymore. yup, i had to use SDL_FULLSCREEN plus some other minor logic errors that the original author had in the code.

thanks folks.

JadeH 2011-06-24 08:54

Re: SDL on N900 / Maemo
 
I love SDL :) I wrote some good things in C+SDL before (mainly a 2d/physics engine and other small cool stuff) and got them working on PSP, linux and now n900, without much tweaking at all, pretty cool


All times are GMT. The time now is 15:08.

vBulletin® Version 3.8.8