2014-03-06 01:43:48 -08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "ecore_drm_private.h"
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <linux/vt.h>
|
|
|
|
#include <linux/kd.h>
|
|
|
|
|
|
|
|
#ifndef KDSKBMUTE
|
|
|
|
# define KDSKBMUTE 0x4B51
|
|
|
|
#endif
|
|
|
|
|
2015-01-19 09:27:28 -08:00
|
|
|
static int kbd_mode = 0;
|
|
|
|
|
2015-01-05 06:08:27 -08:00
|
|
|
Eina_Bool
|
|
|
|
_ecore_drm_tty_switch(Ecore_Drm_Device *dev, int activate_vt)
|
ecore-drm: added vt switch key event handler
Summary:
Because vt mode of tty is set to VT_PROCESS,
ecore-drm is responsible for managing switch-to or switch-from other vt.
For that, ecore-drm has to handshake with kernel(tty driver).
On switch-from side(A):
1. Listen key event to satisfy vt switch key binding.
2. ioctl(fd, VT_ACTIVE, switch-to-vt) for activating switch-to vt.
3. Receive SIGUSR1(relsig) from kernel.
4. Prepare releasing vt, and ioctl(fd, VT_RELDISP, 1).
On switch-to side(B):
0. Kernel receive VT_RELDISP with value 1(ok) from switch-from vt.
1. Receive SIGUSR2(acqsig) from kernel.
2. ioctl(fd, VT_RELDISP, VT_ACKACQ), and start to setup vt.
This revision added A-1 step on above.
Test Plan:
On booted PC with systemd.
1. launch enlightenment_start with drm and wayland
ex) ECORE_DRM_TTY=/dev/tty1 \
E_WL_FORCE=drm \
ELM_ENGINE=wayland_shm enlightenment_start
2. try to switch vt by pressing "Ctrl + Alt + (F1 ~ F8)"
Reviewers: gwanglim, stefan_schmidt, devilhorns
Subscribers: cedric
Differential Revision: https://phab.enlightenment.org/D1280
2014-09-15 09:03:52 -07:00
|
|
|
{
|
2015-01-05 06:08:27 -08:00
|
|
|
if (!ioctl(dev->tty.fd, VT_ACTIVATE, activate_vt) < 0)
|
|
|
|
return EINA_FALSE;
|
|
|
|
return EINA_TRUE;
|
2014-03-06 01:43:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_ecore_drm_tty_setup(Ecore_Drm_Device *dev)
|
|
|
|
{
|
|
|
|
struct stat st;
|
2014-09-15 12:45:31 -07:00
|
|
|
int kmode;
|
2014-03-06 01:43:48 -08:00
|
|
|
struct vt_mode vtmode = { 0 };
|
|
|
|
|
|
|
|
if (fstat(dev->tty.fd, &st) == -1)
|
|
|
|
{
|
|
|
|
ERR("Failed to get stats for tty: %m");
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
2014-09-15 12:45:31 -07:00
|
|
|
if (ioctl(dev->tty.fd, KDGETMODE, &kmode))
|
|
|
|
{
|
|
|
|
ERR("Could not get tty mode: %m");
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioctl(dev->tty.fd, VT_ACTIVATE, minor(st.st_rdev)) < 0)
|
|
|
|
{
|
|
|
|
ERR("Failed to activate vt: %m");
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioctl(dev->tty.fd, VT_WAITACTIVE, minor(st.st_rdev)) < 0)
|
2014-03-06 01:43:48 -08:00
|
|
|
{
|
2014-09-15 12:45:31 -07:00
|
|
|
ERR("Failed to wait active: %m");
|
2014-03-06 01:43:48 -08:00
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
2015-01-19 09:27:28 -08:00
|
|
|
if (ioctl(dev->tty.fd, KDGKBMODE, &kbd_mode))
|
|
|
|
{
|
|
|
|
ERR("Could not get curent kbd mode: %m");
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
2015-01-13 12:35:55 -08:00
|
|
|
if (ioctl(dev->tty.fd, KDSKBMUTE, 1) &&
|
|
|
|
ioctl(dev->tty.fd, KDSKBMODE, K_OFF))
|
|
|
|
{
|
|
|
|
ERR("Could not set K_OFF keyboard mode: %m");
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
2014-03-06 01:43:48 -08:00
|
|
|
|
2014-09-15 12:45:31 -07:00
|
|
|
if (kmode != KD_GRAPHICS)
|
2014-07-15 06:41:29 -07:00
|
|
|
{
|
2014-09-15 12:45:31 -07:00
|
|
|
if (ioctl(dev->tty.fd, KDSETMODE, KD_GRAPHICS))
|
|
|
|
{
|
|
|
|
ERR("Could not set graphics mode: %m");
|
2014-12-16 06:20:25 -08:00
|
|
|
goto err_kmode;
|
2014-09-15 12:45:31 -07:00
|
|
|
}
|
2014-07-15 06:41:29 -07:00
|
|
|
}
|
2014-03-06 01:43:48 -08:00
|
|
|
|
|
|
|
vtmode.mode = VT_PROCESS;
|
|
|
|
vtmode.waitv = 0;
|
|
|
|
vtmode.relsig = SIGUSR1;
|
|
|
|
vtmode.acqsig = SIGUSR2;
|
|
|
|
if (ioctl(dev->tty.fd, VT_SETMODE, &vtmode) < 0)
|
|
|
|
{
|
|
|
|
ERR("Could not set Terminal Mode: %m");
|
2014-12-16 06:20:25 -08:00
|
|
|
goto err_setmode;
|
2014-03-06 01:43:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
2014-12-16 06:20:25 -08:00
|
|
|
err_setmode:
|
|
|
|
ioctl(dev->tty.fd, KDSETMODE, KD_TEXT);
|
|
|
|
err_kmode:
|
|
|
|
return EINA_FALSE;
|
2014-03-06 01:43:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @defgroup Ecore_Drm_Tty_Group Tty manipulation functions
|
|
|
|
*
|
|
|
|
* Functions that deal with opening, closing, and otherwise using a tty
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Open a tty for use
|
|
|
|
*
|
|
|
|
* @param dev The Ecore_Drm_Device that this tty will belong to.
|
|
|
|
* @param name The name of the tty to try and open.
|
|
|
|
* If NULL, /dev/tty0 will be used.
|
|
|
|
*
|
|
|
|
* @return EINA_TRUE on success, EINA_FALSE on failure
|
|
|
|
*
|
|
|
|
* @ingroup Ecore_Drm_Tty_Group
|
|
|
|
*/
|
|
|
|
EAPI Eina_Bool
|
|
|
|
ecore_drm_tty_open(Ecore_Drm_Device *dev, const char *name)
|
|
|
|
{
|
|
|
|
char tty[32] = "<stdin>";
|
|
|
|
|
|
|
|
/* check for valid device */
|
|
|
|
if ((!dev) || (!dev->drm.name)) return EINA_FALSE;
|
|
|
|
|
|
|
|
/* assign default tty fd of -1 */
|
|
|
|
dev->tty.fd = -1;
|
|
|
|
|
|
|
|
if (!name)
|
|
|
|
{
|
|
|
|
char *env;
|
|
|
|
|
|
|
|
if ((env = getenv("ECORE_DRM_TTY")))
|
|
|
|
snprintf(tty, sizeof(tty), "%s", env);
|
|
|
|
else
|
2014-09-15 12:45:31 -07:00
|
|
|
dev->tty.fd = dup(STDIN_FILENO);
|
2014-03-06 01:43:48 -08:00
|
|
|
}
|
2014-10-06 07:08:19 -07:00
|
|
|
else
|
2014-10-06 07:07:22 -07:00
|
|
|
snprintf(tty, sizeof(tty), "%s", name);
|
2014-03-06 01:43:48 -08:00
|
|
|
|
|
|
|
if (dev->tty.fd < 0)
|
|
|
|
{
|
|
|
|
DBG("Trying to Open Tty: %s", tty);
|
|
|
|
|
|
|
|
dev->tty.fd = open(tty, O_RDWR | O_NOCTTY);
|
|
|
|
if (dev->tty.fd < 0)
|
|
|
|
{
|
|
|
|
DBG("Failed to Open Tty: %m");
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-15 12:45:31 -07:00
|
|
|
/* DBG("Opened Tty %s : %d", tty, dev->tty.fd); */
|
2014-03-06 01:43:48 -08:00
|
|
|
|
2014-09-04 00:43:53 -07:00
|
|
|
/* save tty name */
|
2014-03-06 01:43:48 -08:00
|
|
|
dev->tty.name = eina_stringshare_add(tty);
|
|
|
|
|
|
|
|
/* FIXME */
|
|
|
|
if (!_ecore_drm_tty_setup(dev))
|
2014-11-26 06:01:47 -08:00
|
|
|
{
|
|
|
|
close(dev->tty.fd);
|
|
|
|
dev->tty.fd = -1;
|
2014-12-10 05:02:45 -08:00
|
|
|
if (dev->tty.name)
|
|
|
|
{
|
|
|
|
eina_stringshare_del(dev->tty.name);
|
|
|
|
dev->tty.name = NULL;
|
|
|
|
}
|
2014-11-26 06:01:47 -08:00
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
2014-03-06 01:43:48 -08:00
|
|
|
|
|
|
|
/* set current tty into env */
|
|
|
|
setenv("ECORE_DRM_TTY", tty, 1);
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2014-12-10 05:03:44 -08:00
|
|
|
static void
|
|
|
|
_ecore_drm_tty_restore(Ecore_Drm_Device *dev)
|
|
|
|
{
|
|
|
|
int fd = dev->tty.fd;
|
|
|
|
struct vt_mode mode = { 0 };
|
|
|
|
|
|
|
|
if (fd < 0) return;
|
|
|
|
|
|
|
|
if (ioctl(fd, KDSETMODE, KD_TEXT))
|
|
|
|
ERR("Could not set KD_TEXT mode on tty: %m\n");
|
|
|
|
|
2015-01-19 09:27:28 -08:00
|
|
|
if (ioctl(dev->tty.fd, KDSKBMUTE, 0) &&
|
|
|
|
ioctl(dev->tty.fd, KDSKBMODE, kbd_mode))
|
|
|
|
{
|
|
|
|
ERR("Could not restore keyboard mode: %m");
|
|
|
|
}
|
|
|
|
|
2014-12-10 05:03:44 -08:00
|
|
|
ecore_drm_device_master_drop(dev);
|
|
|
|
|
|
|
|
mode.mode = VT_AUTO;
|
|
|
|
if (ioctl(fd, VT_SETMODE, &mode) < 0)
|
|
|
|
ERR("Could not reset VT handling\n");
|
|
|
|
}
|
|
|
|
|
2014-03-06 01:43:48 -08:00
|
|
|
/**
|
|
|
|
* Close an already opened tty
|
|
|
|
*
|
|
|
|
* @param dev The Ecore_Drm_Device which owns this tty.
|
|
|
|
*
|
|
|
|
* @return EINA_TRUE on success, EINA_FALSE on failure
|
|
|
|
*
|
|
|
|
* @ingroup Ecore_Drm_Tty_Group
|
|
|
|
*/
|
|
|
|
EAPI Eina_Bool
|
|
|
|
ecore_drm_tty_close(Ecore_Drm_Device *dev)
|
|
|
|
{
|
|
|
|
/* check for valid device */
|
|
|
|
if ((!dev) || (!dev->drm.name)) return EINA_FALSE;
|
|
|
|
|
2014-12-10 05:03:44 -08:00
|
|
|
_ecore_drm_tty_restore(dev);
|
|
|
|
|
2014-03-06 01:43:48 -08:00
|
|
|
close(dev->tty.fd);
|
|
|
|
|
|
|
|
dev->tty.fd = -1;
|
|
|
|
|
|
|
|
/* clear the tty name */
|
|
|
|
if (dev->tty.name) eina_stringshare_del(dev->tty.name);
|
|
|
|
dev->tty.name = NULL;
|
|
|
|
|
|
|
|
unsetenv("ECORE_DRM_TTY");
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Release a virtual terminal
|
|
|
|
*
|
|
|
|
* @param dev The Ecore_Drm_Device which owns this tty.
|
|
|
|
*
|
|
|
|
* @return EINA_TRUE on success, EINA_FALSE on failure
|
|
|
|
*
|
|
|
|
* @ingroup Ecore_Drm_Tty_Group
|
|
|
|
*/
|
|
|
|
EAPI Eina_Bool
|
|
|
|
ecore_drm_tty_release(Ecore_Drm_Device *dev)
|
|
|
|
{
|
|
|
|
/* check for valid device */
|
|
|
|
if ((!dev) || (!dev->drm.name) || (dev->tty.fd < 0)) return EINA_FALSE;
|
|
|
|
|
|
|
|
/* send ioctl for vt release */
|
2014-09-15 12:45:31 -07:00
|
|
|
if (ioctl(dev->tty.fd, VT_RELDISP, 1) < 0)
|
|
|
|
{
|
|
|
|
ERR("Could not release VT: %m");
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
2014-03-06 01:43:48 -08:00
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Acquire a virtual terminal
|
|
|
|
*
|
|
|
|
* @param dev The Ecore_Drm_Device which owns this tty.
|
|
|
|
*
|
|
|
|
* @return EINA_TRUE on success, EINA_FALSE on failure
|
|
|
|
*
|
|
|
|
* @ingroup Ecore_Drm_Tty_Group
|
|
|
|
*/
|
|
|
|
EAPI Eina_Bool
|
|
|
|
ecore_drm_tty_acquire(Ecore_Drm_Device *dev)
|
|
|
|
{
|
|
|
|
/* check for valid device */
|
|
|
|
if ((!dev) || (!dev->drm.name) || (dev->tty.fd < 0)) return EINA_FALSE;
|
|
|
|
|
|
|
|
/* send ioctl for vt acquire */
|
2014-09-15 12:45:31 -07:00
|
|
|
if (ioctl(dev->tty.fd, VT_RELDISP, VT_ACKACQ) < 0)
|
|
|
|
{
|
|
|
|
ERR("Could not acquire VT: %m");
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
2014-03-06 01:43:48 -08:00
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
2014-03-10 01:24:08 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the opened virtual terminal file descriptor
|
|
|
|
*
|
|
|
|
* @param dev The Ecore_Drm_Device which owns this tty.
|
|
|
|
*
|
|
|
|
* @return The tty fd opened from previous call to ecore_drm_tty_open
|
|
|
|
*
|
|
|
|
* @ingroup Ecore_Drm_Tty_Group
|
|
|
|
*
|
|
|
|
* @since 1.10
|
|
|
|
*/
|
|
|
|
EAPI int
|
|
|
|
ecore_drm_tty_get(Ecore_Drm_Device *dev)
|
|
|
|
{
|
|
|
|
/* check for valid device */
|
|
|
|
if ((!dev) || (!dev->drm.name) || (dev->tty.fd < 0)) return -1;
|
|
|
|
|
|
|
|
return dev->tty.fd;
|
|
|
|
}
|