Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Expose active blanking policy on D-Bus
UI side needs to differentiate between display turning off due to
explicit user activity like pressing power key and other reasons like
incoming calls, alarms etc. Currently this is not possible.

Allow applications to query and track display blanking policy on D-Bus.
When default blanking policy is effective, display turns on only because
of explicit user activity. If display is unblanked for other reasons, the
non-default blanking policy is signaled before display power up actually
starts.

[mce] Expose active blanking policy on D-Bus. Fixes JB#29675
  • Loading branch information
spiiroin committed Jun 18, 2015
1 parent fe85ced commit 4abe2a8
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 1 deletion.
65 changes: 65 additions & 0 deletions datapipe.c
Expand Up @@ -1029,6 +1029,71 @@ const char *device_lock_state_repr(device_lock_state_t state)
return res;
}

/** Convert uiexctype_t enum to human readable string
*
* Note that while uiexctype_t actually is a bitmask
* and this function is expected to be used in situations
* where at maximum one bit is set.
*
* @param state uiexctype_t exception stata
*
* @return human readable representation of state
*/
const char *uiexctype_repr(uiexctype_t state)
{
const char *res = "unknown";
switch( state ) {
case UIEXC_NONE: res = "none"; break;
case UIEXC_LINGER: res = "linger"; break;
case UIEXC_CALL: res = "call"; break;
case UIEXC_ALARM: res = "alarm"; break;
case UIEXC_NOTIF: res = "notif"; break;
default: break;
}
return res;
}

/** Convert uiexctype_t enum to dbus argument string
*
* Note that while uiexctype_t actually is a bitmask
* and this function is expected to be used in situations
* where at maximum one bit is set.
*
* @param state uiexctype_t exception stata
*
* @return representation of state for use over dbus
*/
const char *uiexctype_to_dbus(uiexctype_t state)
{
const char *res = MCE_BLANKING_POLICY_DEFAULT_STRING;

switch( state ) {
case UIEXC_NOTIF:
res = MCE_BLANKING_POLICY_NOTIFICATION_STRING;
break;

case UIEXC_ALARM:
res = MCE_BLANKING_POLICY_ALARM_STRING;
break;

case UIEXC_CALL:
res = MCE_BLANKING_POLICY_CALL_STRING;
break;

case UIEXC_LINGER:
res = MCE_BLANKING_POLICY_LINGER_STRING;
break;

case UIEXC_NONE:
break;

default:
mce_log(LL_WARN, "unknown blanking policy; using default");
break;
}
return res;
}

/** Convert service_state_t enum to human readable string
*
* @param state service_state_t enumeration value
Expand Down
3 changes: 3 additions & 0 deletions mce.h
Expand Up @@ -308,6 +308,9 @@ typedef enum {
UIEXC_NOTIF = 1<<3,
} uiexctype_t;

const char *uiexctype_repr(uiexctype_t state);
const char *uiexctype_to_dbus(uiexctype_t state);

/** D-Bus service availability */
typedef enum {
SERVICE_STATE_UNDEF = -1,
Expand Down
79 changes: 78 additions & 1 deletion tklock.c
Expand Up @@ -300,6 +300,9 @@ static void tklock_ui_disable_lpm(void);

// dbus ipc

static void tklock_dbus_send_display_blanking_policy(DBusMessage *const req);
static gboolean tklock_dbus_display_blanking_policy_get_cb(DBusMessage *const msg);

static void tklock_dbus_send_keyboard_slide_state(DBusMessage *const req);
static gboolean tklock_dbus_keyboard_slide_state_get_req_cb(DBusMessage *const msg);

Expand Down Expand Up @@ -1285,7 +1288,9 @@ static void tklock_datapipe_exception_state_cb(gconstpointer data)
if( exception_state == prev )
goto EXIT;

mce_log(LL_DEBUG, "exception_state = %d -> %d", prev, exception_state);
mce_log(LL_DEBUG, "exception_state = %s -> %s",
uiexctype_repr(prev),
uiexctype_repr(exception_state));

/* Cancel autorelock if there is a call */
if( exception_state == UIEXC_CALL &&
Expand All @@ -1301,6 +1306,9 @@ static void tklock_datapipe_exception_state_cb(gconstpointer data)
tklock_autolock_rethink();
tklock_proxlock_rethink();

/* Broadcast blanking policy change */
tklock_dbus_send_display_blanking_policy(0);

EXIT:
return;
}
Expand Down Expand Up @@ -4784,6 +4792,57 @@ static void tklock_ui_disable_lpm(void)
* DBUS MESSAGE HANDLERS
* ========================================================================= */

/** Send the blanking policy state
*
* @param req A method call message to be replied, or
* NULL to broadcast a policy change signal
*/
static void
tklock_dbus_send_display_blanking_policy(DBusMessage *const req)
{
DBusMessage *rsp = 0;

if( req )
rsp = dbus_new_method_reply(req);
else
rsp = dbus_new_signal(MCE_SIGNAL_PATH, MCE_SIGNAL_IF,
MCE_BLANKING_POLICY_SIG);
if( !rsp )
goto EXIT;

const char *arg = uiexctype_to_dbus(exception_state);

mce_log(LL_DEBUG, "send display blanking policy %s: %s",
req ? "reply" : "signal", arg);

if( !dbus_message_append_args(rsp,
DBUS_TYPE_STRING, &arg,
DBUS_TYPE_INVALID) )
goto EXIT;

dbus_send_message(rsp), rsp = 0;

EXIT:
if( rsp ) dbus_message_unref(rsp);
}

/** D-Bus callback for the get blakng policy state method call
*
* @param msg The D-Bus message
*
* @return TRUE
*/
static gboolean
tklock_dbus_display_blanking_policy_get_cb(DBusMessage *const msg)
{
mce_log(LL_DEVEL, "Received blanking policy get from %s",
mce_dbus_get_message_sender_ident(msg));

tklock_dbus_send_display_blanking_policy(msg);

return TRUE;
}

#define MCE_KEYBOARD_SLIDE_STATE_SIG "keyboard_slide_state_ind"
#define MCE_KEYBOARD_SLIDE_STATE_REQ "keyboard_slide_state_req"

Expand Down Expand Up @@ -5223,6 +5282,13 @@ static mce_dbus_handler_t tklock_dbus_handlers[] =
.args =
" <arg name=\"keyboard_state\" type=\"s\"/>\n"
},
{
.interface = MCE_SIGNAL_IF,
.name = MCE_BLANKING_POLICY_SIG,
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.args =
" <arg name=\"blanking_policy\" type=\"s\"/>\n"
},
/* method calls */
{
.interface = MCE_REQUEST_IF,
Expand Down Expand Up @@ -5283,6 +5349,14 @@ static mce_dbus_handler_t tklock_dbus_handlers[] =
.args =
" <arg direction=\"out\" name=\"keyboard_state\" type=\"s\"/>\n"
},
{
.interface = MCE_REQUEST_IF,
.name = MCE_BLANKING_POLICY_GET,
.type = DBUS_MESSAGE_TYPE_METHOD_CALL,
.callback = tklock_dbus_display_blanking_policy_get_cb,
.args =
" <arg direction=\"out\" name=\"blanking_policy\" type=\"s\"/>\n"
},
/* sentinel */
{
.interface = 0
Expand Down Expand Up @@ -5783,6 +5857,9 @@ gboolean mce_tklock_init(void)
/* Make sure lpm state gets initialized & broadcast */
tklock_lpmui_set_state(false);

/* Broadcast initial blanking policy */
tklock_dbus_send_display_blanking_policy(0);

/* Evaluate initial lid sensor state */
tklock_lid_sensor_rethink();

Expand Down

0 comments on commit 4abe2a8

Please sign in to comment.