maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   OS2008 / Maemo 4 / Chinook - Diablo (https://talk.maemo.org/forumdisplay.php?f=29)
-   -   Odds and ends (https://talk.maemo.org/showthread.php?t=74915)

auouymous 2011-09-12 01:08

Re: Odds and ends
 
Quote:

Originally Posted by Addison (Post 1086572)
I wish that you just would have said that it's not possible instead.

This ability is actually planned for ASUI. I just need to figure out the best way to handle it. Probably unmap ASUI and open its blank window to grab all keys. Use a simple command language in asui-settings to map keys to dbus calls, ignore them or pass them through. The screen automatically comes on when a key is pressed so I'll probably have a configure the delay before turning it back off. That way it would only remain on for a few seconds instead of for your entire dim/blank timeout.

Thoughts?

Addison 2011-09-12 05:03

Re: Odds and ends
 
Isn't the dim/blank timeout done in milliseconds?

Why not just set it at 1?

Maybe it won't even be noticeable. :)

auouymous 2011-09-12 05:23

Re: Odds and ends
 
Quote:

Originally Posted by Addison (Post 1086614)
Isn't the dim/blank timeout done in milliseconds?

Why not just set it at 1?

Maybe it won't even be noticeable. :)

What if you want to see the screen briefly while pressing the keys? Duration is not a problem since the user would be able to set it.

jstokes 2011-09-13 08:29

Re: Odds and ends
 
Quote:

Originally Posted by Addison (Post 1085925)
Hey, there's one other thing I wanted to ask.

I love Xmms.

I also love how you can use the zoom in and out keys to change tracks.

The thing is, this doesn't work with the tablet locked so that the screen is turned off to save on battery life.

Is there any possible trick around this?

I wrote a hack, but unfortunately it doesn't work correctly: Sometimes, when locking, this program picks up spurious input events making the program think the zoom keys have been pressed, even when they haven't.

The idea behind this program (was supposed to be) is simple: If the zoom in/out keys are pressed are pressed while the tablet is locked and the display is dimmed/off, it will run /home/user/xmmskey and pass which zoom key was pressed by passing it as argv[1] (in a script, you can check if $1 = "in") and you could run xmmsctrl (available from free's debfarm repository) from this script.

If a resident Maemo 4 programmer (I don't know what I'm doing!) knows where I've messed up, I'll fix it, but it seems like auouymous is working on something anyway.

PHP Code:

/* Code taken from Austin Che's powerlaunch and fanoush's evkey */
/* gcc xmmskey.c  $(pkg-config --cflags --libs glib-2.0 dbus-glib-1) -Wall -O2 -o xmmskey */

#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
#include <linux/input.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <dbus/dbus-glib.h>
#include <mce/dbus-names.h>
#include <mce/mode-names.h>

#define INPUT_DEV "/dev/input/event2"
#define KP_PATH "/sys/devices/platform/omap2_mcspi.1/spi1.0/disable_kp"
#define ZOOMIN_KC 65
#define ZOOMOUT_KC 66
#define SCRIPT_TO_RUN "/home/user/xmmskey"

static GMainLoop *loopy NULL;

static 
gint inputfd = -1;
static 
GIOChannel *inputfdchannel NULL;

static 
DBusGConnection *systembus NULL;
static 
DBusGProxy *mceproxy NULL;

static 
void sighandler (gint signo G_GNUC_UNUSED)
{
    if (!
inputfdchannel)
    {
        
g_io_channel_shutdown (inputfdchannelFALSENULL);
        
g_io_channel_unref (inputfdchannel);
        
inputfdchannel NULL;
    }

    if (
inputfd != -1)
    {
        
close (inputfd);
        
inputfd = -1;
    }
    
    if (
mceproxy)
    {
        
g_object_unref (mceproxy);
        
mceproxy NULL;
    }

    if (
loopy)
    {
        
g_main_loop_quit (loopy);
        
g_main_loop_unref (loopy);
        
loopy NULL;
    }
}

static 
void disable_kplock (void)
{
    
FILE *kp g_fopen (KP_PATH"w");
    if (
kp)
    {
        
fputc (0kp);
        
fclose (kp);
    }
}

static 
inline DBusGProxyget_mce_request_proxy (void)
{
    return 
dbus_g_proxy_new_for_name (systembusMCE_SERVICEMCE_REQUEST_PATHMCE_REQUEST_IF);
}

static 
gboolean is_tablet_locked (void)
{
    
gchar *lockmode NULL;
    
gboolean retval FALSE;
    
DBusGProxy *mcereqproxy get_mce_request_proxy();

    
dbus_g_proxy_call (mcereqproxyMCE_TKLOCK_MODE_GETNULLG_TYPE_INVALIDG_TYPE_STRING, &lockmodeG_TYPE_INVALID);
    
g_object_unref (mcereqproxy);
    if (!
lockmode)
        return 
FALSE;

    
retval g_strrstr (lockmodeMCE_TK_UNLOCKED) == NULL;
    
g_free (lockmode);

    return 
retval;
}

static 
void blank_screen (void)
{
    
DBusGProxy *mcereqproxy get_mce_request_proxy();

    
dbus_g_proxy_call_no_reply (mcereqproxyMCE_DISPLAY_OFF_REQG_TYPE_INVALID);
    
g_object_unref (mcereqproxy);
}

static 
void begin_work (gboolean zoomin)
{
    
gchar cmdline[sizeof (SCRIPT_TO_RUN) + 10];
    
g_snprintf (cmdlinesizeof (cmdline), "%s %s"SCRIPT_TO_RUNzoomin "in" "out");
    
g_spawn_command_line_sync (cmdlineNULLNULLNULLNULL);
    
blank_screen();
}

static 
gboolean input_cb (GIOChannel *sourceGIOCondition conditiongpointer data G_GNUC_UNUSED)
{
    if(
condition & (G_IO_IN G_IO_PRI))
    {
        
struct input_event ev;
        
gsize bytes_read;
        
        if (!
is_tablet_locked())
            return 
FALSE;

        if (
g_io_channel_read_chars (source, (gchar*) &evsizeof (struct input_event), &bytes_readNULL) == G_IO_STATUS_NORMAL)
        {
            if (
bytes_read != sizeof (struct input_event))
                goto 
getmeout;

            if (
ev.type != EV_KEY)
                goto 
getmeout;

            if (
ev.value != 0/* Act only on key release */
                
goto getmeout;

            if (
ev.code == ZOOMIN_KC)
                
begin_work (TRUE);
            else if (
ev.code == ZOOMOUT_KC)
                
begin_work (FALSE);
        }
    }

getmeout:
    return 
TRUE;
}

static 
void display_cb (DBusGProxy *proxy G_GNUC_UNUSED, const gchar *dispstategpointer data G_GNUC_UNUSED)
{
    if (!
g_str_equal (dispstateMCE_DISPLAY_ON_STRING) && is_tablet_locked())
    {
        
disable_kplock();
        
g_io_add_watch (inputfdchannelG_IO_IN G_IO_PRIinput_cbinputfdchannel);
    }
}

static 
void tklock_cb (DBusGProxy *proxy G_GNUC_UNUSED, const gchar *modegpointer data G_GNUC_UNUSED)
{
    if (
g_strrstr (modeMCE_TK_UNLOCKED))
    {
        
dbus_g_proxy_disconnect_signal (mceproxyMCE_DISPLAY_SIGG_CALLBACK (display_cb), NULL);
        
GSource *inputfd_watch g_main_context_find_source_by_user_data (NULLinputfdchannel);
        if (
inputfd_watch)
            
g_source_destroy (inputfd_watch);
    }
    else
    {
        
dbus_g_proxy_connect_signal (mceproxyMCE_DISPLAY_SIGG_CALLBACK (display_cb), NULLNULL);
    }
}

int main (void)
{
    
inputfd open (INPUT_DEVO_RDONLY O_NONBLOCK);
    if (
inputfd == -1)
        return 
EXIT_FAILURE;
    
    
signal (SIGTERMsighandler);
    
signal (SIGINTsighandler);
    
signal (SIGQUITsighandler);

    
g_type_init();    
    
systembus dbus_g_bus_get (DBUS_BUS_SYSTEMNULL);
    if (!
systembus)
    {
        
sighandler(0);
        return 
EXIT_FAILURE;
    }

    
inputfdchannel g_io_channel_unix_new (inputfd);
    if (!
inputfdchannel)
    {
        
sighandler(0);
        return 
EXIT_FAILURE;
    }
    
    
g_io_channel_set_flags (inputfdchannelG_IO_FLAG_NONBLOCKNULL);
    
g_io_channel_set_encoding (inputfdchannelNULLNULL);

    
mceproxy dbus_g_proxy_new_for_name (systembusMCE_SERVICEMCE_SIGNAL_PATHMCE_SIGNAL_IF);
    
dbus_g_proxy_add_signal (mceproxyMCE_DISPLAY_SIGG_TYPE_STRINGG_TYPE_INVALID);
    
dbus_g_proxy_add_signal (mceproxyMCE_TKLOCK_MODE_SIGG_TYPE_STRINGG_TYPE_INVALID);
    
dbus_g_proxy_connect_signal (mceproxyMCE_TKLOCK_MODE_SIGG_CALLBACK (tklock_cb), NULLNULL);
    
    
loopy g_main_loop_new (NULLFALSE);
    
g_main_loop_run (loopy);

    return 
EXIT_SUCCESS;



Addison 2011-09-13 10:41

Re: Odds and ends
 
Quote:

Originally Posted by auouymous (Post 1086620)
What if you want to see the screen briefly while pressing the keys? Duration is not a problem since the user would be able to set it.

Okay. So perhaps just have that customizable on the user's side then? :)

auouymous 2011-09-13 20:38

Re: Odds and ends
 
Quote:

Originally Posted by jstokes (Post 1087336)
If a resident Maemo 4 programmer (I don't know what I'm doing!) knows where I've messed up, I'll fix it, but it seems like auouymous is working on something anyway.

Your KP_PATH only works on n800. Need to detect device type and change KP_PATH if you want it to also work on n810.

The key handling code looks correct, ASUI uses similar code to read the power button but not glib, maybe a problem with glib. Have you tried
Code:

printf("event: time=%f, type=%u, code=%u, value=%d\n", (float)ev.time.tv_sec + (float)ev.time.tv_usec / 1000000.0, ev.type, ev.code, ev.value);
after the ev.value condition? You can then see the time each event occured and its parameters.

Addison 2011-09-14 01:55

Re: Odds and ends
 
Ooh! Hey!

I finally got around to using the built in Email with my Gmail POP account after all these years.

I love how I can now receive LED notifications. :)

Is there any hack to have it scan for new messages every minute though?

The lowest setting is only at every 5 minutes.

n9ots 2011-09-14 10:44

Re: Odds and ends
 
Quote:

Originally Posted by Addison (Post 1087869)
Is there any hack to have it scan for new messages every minute though?

The lowest setting is only at every 5 minutes.

not sure but you could try setting the 'update interval' with gconf-editor. (apps > modest)

maacruz 2011-09-14 12:27

Re: Odds and ends
 
Quote:

Originally Posted by Addison (Post 1087869)
Ooh! Hey!

I finally got around to using the built in Email with my Gmail POP account after all these years.

I love how I can now receive LED notifications. :)

Is there any hack to have it scan for new messages every minute though?

The lowest setting is only at every 5 minutes.

Isn't it a bit of abuse to scan every minute?
If it comes by email, sure it can wait 5 minutes, can't it?

Addison 2011-09-14 12:42

Re: Odds and ends
 
I only ask because LED notification for Dial Central is still broke with it's latest build.

This would be a simple alternative instead. :)


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

vBulletin® Version 3.8.8