[maemo-developers] Rotation support.. :(

From: Cornelius Hald hald at icandy.de
Date: Sat Nov 7 17:47:34 EET 2009
Hi Aniello,

you have to enable the accelerators first. Here's a method copied from
my code:

void
orientation_enable_accelerators()
{
	AppData *app_data = app_data_get();

	if (app_data->accelerators == TRUE) {
		return;
	}

	/* TODO: Replace string "req_accelerometer_enable" with constant once we switched to final SDK */
	if (osso_rpc_run_system(app_data->osso_ctx, MCE_SERVICE, MCE_REQUEST_PATH,
			MCE_REQUEST_IF,	"req_accelerometer_enable", NULL, DBUS_TYPE_INVALID) == OSSO_OK) {
		g_printerr("INFO: Accelerometers enabled\n");
		app_data->accelerators = TRUE;
	} else {
		g_printerr("WARN: Cannot enable accelerometers\n");
	}
}

To save energy you should disable them again if your window is not the top most window. The rest of the code can be found here:
https://garage.maemo.org/plugins/scmsvn/viewcvs.php/trunk/conboy/src/orientation.c?revision=514&root=conboy&view=markup

Cheers!
Conny


On Sat, 2009-11-07 at 15:19 +0000, Aniello Del Sorbo wrote:
> I am trying to add rotation to Xournal.
> 
> I have defined the DBus message sig as follows:
> 
> #define MCE_SIGNAL_MATCH "type='signal',"  \
>         "sender='"    MCE_SERVICE                "'," \
>         "path='"      MCE_SIGNAL_PATH            "'," \
>         "interface='" MCE_SIGNAL_IF              "'"
> 
> then I've added a DBus filter and handler:
> 
> sys_conn = osso_get_sys_dbus_connection(ctx);
>   if (sys_conn) {
>         DBusError error;
>         dbus_error_init (&error);
>         dbus_bus_add_match (sys_conn, MCE_SIGNAL_MATCH, &error);
>         if (dbus_error_is_set(&error)){
>                 printf("dbus_bus_add_match failed: %s\n", error.message);
>                 dbus_error_free(&error);
>         }
> 
>         if (!dbus_connection_add_filter (sys_conn,
>                   (DBusHandleMessageFunction) mce_filter_func, NULL, NULL)) {
>                 printf("Error dbus_connection_add_filter failed\n");
>         } else {
>                 printf ("DBUS filter added\n");
>         }
>   }
> 
> and defined the handler function:
> 
> DBusHandlerResult
> mce_filter_func (DBusConnection *connection, DBusMessage *message, void *data)
> {
>         DBusMessageIter iter;
>         const gchar *mode = NULL;
> 
>         printf ("MCE\n");
> 
>         if (dbus_message_is_signal(message, MCE_SIGNAL_IF,
> MCE_DEVICE_ORIENTATION_SIG)) {
>                 printf ("is a orientation signal\n");
>                 if (dbus_message_iter_init(message, &iter)) {
>                         printf ("getting mode\n");
>                         dbus_message_iter_get_basic(&iter, &mode);
> 
>                         hildon_rotate_ui (mode);
>                 }
>         }
> 
>         return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
> }
> 
> It compiles, starts up, the MCE function gets called twice when
> Xournal starts (it prints MCE twice) and gets called for several other
> DBus messages (like screen lock/unlock), but NOT for rotate messages.
> 
> What am I missing?
> 
> Thanks!
> 
> References:
> [1] <http://wiki.maemo.org/Using_Fremantle_Widgets#Listening_To_Hardware_Orientation_Changes>
> 
> [2] <http://wiki.maemo.org/Documentation/Maemo_5_Developer_Guide/Porting_Software/Porting_Existing_GTK%2B_Application_to_Maemo_5#Portrait_Mode>
> 
> [3] <https://garage.maemo.org/plugins/scmsvn/viewcvs.php/trunk/omweather/src/weather-portrait.c?revision=2951&root=omweather&view=markup>
> 
> [4] <https://garage.maemo.org/plugins/scmsvn/viewcvs.php/trunk/omweather/src/weather-dbus.c?revision=3265&root=omweather&view=markup>
> 

More information about the maemo-developers mailing list