ecore-drm: Cleanup launcher code

Summary: This moves the VT switch handling code to the tty file, and
sets the proper flags on the VT when opened.

@fix

Signed-off-by: Chris Michael <cp.michael@samsung.com>
This commit is contained in:
Chris Michael 2015-01-22 12:40:32 -05:00
parent c7d557cf4e
commit 81a4731036
1 changed files with 52 additions and 140 deletions

View File

@ -1,9 +1,8 @@
#include "ecore_drm_private.h"
#include "ecore_drm_logind.h"
static Eina_Bool logind = EINA_FALSE;
static Eina_Bool
static Eina_Bool
_ecore_drm_launcher_cb_vt_switch(void *data, int type EINA_UNUSED, void *event)
{
Ecore_Drm_Device *dev;
@ -28,143 +27,8 @@ _ecore_drm_launcher_cb_vt_switch(void *data, int type EINA_UNUSED, void *event)
return ECORE_CALLBACK_PASS_ON;
}
static Eina_Bool
_ecore_drm_launcher_cb_vt_signal(void *data, int type EINA_UNUSED, void *event)
{
Ecore_Drm_Device *dev;
Ecore_Event_Signal_User *ev;
siginfo_t sigdata;
dev = data;
ev = event;
sigdata = ev->data;
if (sigdata.si_code != SI_KERNEL) return ECORE_CALLBACK_RENEW;
if (ev->number == 1)
{
if (!logind)
{
Ecore_Drm_Input *input;
Ecore_Drm_Output *output;
Ecore_Drm_Sprite *sprite;
Eina_List *l;
/* disable inputs (suspends) */
EINA_LIST_FOREACH(dev->inputs, l, input)
ecore_drm_inputs_disable(input);
/* disable hardware cursor */
EINA_LIST_FOREACH(dev->outputs, l, output)
ecore_drm_output_cursor_size_set(output, 0, 0, 0);
/* disable sprites */
EINA_LIST_FOREACH(dev->sprites, l, sprite)
ecore_drm_sprites_fb_set(sprite, 0, 0);
/* drop drm master */
ecore_drm_device_master_drop(dev);
_ecore_drm_event_activate_send(EINA_FALSE);
}
/* issue ioctl to release vt */
if (!ecore_drm_tty_release(dev))
ERR("Could not release VT: %m");
}
else if (ev->number == 2)
{
if (!logind)
{
Ecore_Drm_Output *output;
Ecore_Drm_Input *input;
Eina_List *l;
/* set drm master */
if (!ecore_drm_device_master_set(dev))
ERR("Could not set drm master: %m");
/* set output mode */
EINA_LIST_FOREACH(dev->outputs, l, output)
ecore_drm_output_enable(output);
/* enable inputs */
EINA_LIST_FOREACH(dev->inputs, l, input)
ecore_drm_inputs_enable(input);
if (ecore_drm_tty_acquire(dev))
_ecore_drm_event_activate_send(EINA_TRUE);
else
ERR("Could not acquire VT: %m");
}
else
{
if (!ecore_drm_tty_acquire(dev))
ERR("Could not acquire VT: %m");
}
}
return ECORE_CALLBACK_RENEW;
}
EAPI Eina_Bool
ecore_drm_launcher_connect(Ecore_Drm_Device *dev)
{
if (!(logind = _ecore_drm_logind_connect(dev)))
{
DBG("Launcher: Not Support logind\n");
if (geteuid() == 0)
DBG("Launcher: Try to keep going with root privilege\n");
else
{
ERR("Launcher: Need Root Privilege or logind\n");
return EINA_FALSE;
}
}
if (!ecore_drm_tty_open(dev, NULL))
{
ERR("Launcher: failed to open tty\n");
return EINA_FALSE;
}
/* setup handler for signals */
dev->tty.event_hdlr =
ecore_event_handler_add(ECORE_EVENT_SIGNAL_USER,
_ecore_drm_launcher_cb_vt_signal, dev);
/* setup handler for key event of vt switch */
dev->tty.switch_hdlr =
ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
_ecore_drm_launcher_cb_vt_switch, dev);
DBG("Launcher: Success Connect\n");
return EINA_TRUE;
}
EAPI void
ecore_drm_launcher_disconnect(Ecore_Drm_Device *dev)
{
if (dev->tty.event_hdlr) ecore_event_handler_del(dev->tty.event_hdlr);
dev->tty.event_hdlr = NULL;
if (dev->tty.switch_hdlr) ecore_event_handler_del(dev->tty.switch_hdlr);
dev->tty.switch_hdlr = NULL;
if (!ecore_drm_tty_close(dev))
ERR("Launcher: failed to close tty\n");
if (logind)
{
logind = EINA_FALSE;
_ecore_drm_logind_disconnect(dev);
}
}
static int
_device_flags_set(int fd, int flags)
int
_ecore_drm_launcher_device_flags_set(int fd, int flags)
{
int fl;
@ -189,6 +53,54 @@ _device_flags_set(int fd, int flags)
return fd;
}
EAPI Eina_Bool
ecore_drm_launcher_connect(Ecore_Drm_Device *dev)
{
/* try to connect to logind */
if (!(logind = _ecore_drm_logind_connect(dev)))
{
DBG("Launcher: Logind not supported");
if (geteuid() == 0)
{
DBG("Launcher: Trying to continue with root privileges");
if (!ecore_drm_tty_open(dev, NULL))
{
ERR("Launcher: Could not setup tty");
return EINA_FALSE;
}
}
else
{
ERR("Launcher: Root privileges needed");
return EINA_FALSE;
}
}
dev->tty.switch_hdlr =
ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
_ecore_drm_launcher_cb_vt_switch, dev);
return EINA_TRUE;
}
EAPI void
ecore_drm_launcher_disconnect(Ecore_Drm_Device *dev)
{
if (dev->tty.switch_hdlr) ecore_event_handler_del(dev->tty.switch_hdlr);
dev->tty.switch_hdlr = NULL;
if (!logind)
{
if (!ecore_drm_tty_close(dev))
ERR("Launcher: Could not close tty");
}
else
{
_ecore_drm_logind_disconnect(dev);
logind = EINA_FALSE;
}
}
Eina_Bool
_ecore_drm_launcher_device_open(const char *device, Ecore_Drm_Open_Cb callback, void *data, int flags)
{
@ -226,7 +138,7 @@ _ecore_drm_launcher_device_open_no_pending(const char *device, int flags)
if (logind)
{
fd = _ecore_drm_logind_device_open_no_pending(device);
if ((fd = _device_flags_set(fd, flags)) == -1)
if ((fd = _ecore_drm_launcher_device_flags_set(fd, flags)) < 0)
{
_ecore_drm_logind_device_close(device);
return -1;