diff --git a/makefile b/makefile index bd572b7..7c637af 100644 --- a/makefile +++ b/makefile @@ -61,6 +61,7 @@ install:$(BIND)/$(NAME) install -dZ ${DESTDIR}/etc/ly install -DZ $(BIND)/$(NAME) -t ${DESTDIR}/usr/bin install -DZ xsetup.sh -t ${DESTDIR}/etc/ly + install -DZ wsetup.sh -t ${DESTDIR}/etc/ly install -DZ $(RESD)/config.ini -t ${DESTDIR}/etc/ly install -dZ ${DESTDIR}/etc/ly/lang install -DZ $(RESD)/lang/* -t ${DESTDIR}/etc/ly/lang diff --git a/res/config.ini b/res/config.ini index 580dfcd..6d08010 100644 --- a/res/config.ini +++ b/res/config.ini @@ -38,6 +38,9 @@ #xauthority=.lyxauth #path=/sbin:/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/env +#wayland_cmd=/etc/ly/wsetup.sh +#wayland_sessions=/usr/share/wayland-sessions + # shutdown is given parameters, do not use an alternative # this is here only to allow you to change its location #shutdown_cmd=/sbin/shutdown diff --git a/src/config.c b/src/config.c index 218c45d..a1f323f 100644 --- a/src/config.c +++ b/src/config.c @@ -65,6 +65,10 @@ int config_lang_handler(void* user, const char* section, const char* name, const { cfg_dup(&lang.xinitrc, value); } + else if (strcmp(name, "wayland") == 0) + { + cfg_dup(&lang.wayland, value); + } else if (strcmp(name, "logout") == 0) { cfg_dup(&lang.logout, value); @@ -184,6 +188,10 @@ void config_lang_patch() { lang.xinitrc = strdup("xinitrc"); } + if (lang.wayland == 0) + { + lang.wayland = strdup("wayland"); + } if (lang.logout == 0) { lang.logout = strdup("logout"); @@ -282,6 +290,7 @@ void config_lang_free() free(lang.f2); free(lang.shell); free(lang.xinitrc); + free(lang.wayland); free(lang.logout); free(lang.capslock); free(lang.numlock); @@ -376,6 +385,14 @@ int config_config_handler(void* user, const char* section, const char* name, con { cfg_dup(&config.x_cmd_setup, value); } + else if (strcmp(name, "wayland_sessions") == 0) + { + cfg_dup(&config.wayland_sessions, value); + } + else if (strcmp(name, "wayland_cmd") == 0) + { + cfg_dup(&config.wayland_cmd, value); + } else if (strcmp(name, "mcookie_cmd") == 0) { cfg_dup(&config.mcookie_cmd, value); @@ -519,7 +536,14 @@ void config_config_patch() { config.x_cmd_setup = strdup("/etc/ly/xsetup.sh"); } - if (config.mcookie_cmd == 0) + if (config.wayland_sessions == 0){ + config.wayland_sessions = strdup("/usr/share/wayland-sessions"); + } + if (config.wayland_cmd == 0) + { + config.wayland_cmd = strdup("/etc/ly/wsetup.sh"); + } + if (config.mcookie_cmd == 0) { config.mcookie_cmd = strdup("/usr/bin/mcookie"); } @@ -569,6 +593,8 @@ void config_config_free() { free(config.xsessions); free(config.service_name); + free(config.wayland_sessions); + free(config.wayland_cmd); free(config.x_cmd); free(config.x_cmd_setup); free(config.mcookie_cmd); diff --git a/src/config.h b/src/config.h index 287d514..afa27d3 100644 --- a/src/config.h +++ b/src/config.h @@ -21,6 +21,8 @@ struct lang char* capslock; char* numlock; + char* wayland; + // errors char* err_pam_buf; char* err_pam_sys; @@ -65,6 +67,10 @@ struct config char* service_name; char* x_cmd; char* x_cmd_setup; + + char* wayland_sessions; + char* wayland_cmd; + char* mcookie_cmd; char* xauthority; char* path; diff --git a/src/desktop.c b/src/desktop.c index e5c296d..7b7628a 100644 --- a/src/desktop.c +++ b/src/desktop.c @@ -9,82 +9,130 @@ #include #include -char* value_name = NULL; -char* value_exec = NULL; +char *value_name = NULL; +char *value_exec = NULL; -int desktop_handler(void* user, const char* section, const char* name, const char* value) -{ - (void)(user); +int desktop_handler(void *user, const char *section, const char *name, const char *value) { + (void) (user); - if (strcmp(section, "Desktop Entry") == 0) - { - if ((strcmp(name, "Name") == 0) && (value_name == NULL)) - { - value_name = strdup(value); - } - if ((strcmp(name, "Exec") == 0) && (value_exec == NULL)) - { - value_exec = strdup(value); - } - } + if (strcmp(section, "Desktop Entry") == 0) { + if ((strcmp(name, "Name") == 0) && (value_name == NULL)) { + value_name = strdup(value); + } + if ((strcmp(name, "Exec") == 0) && (value_exec == NULL)) { + value_exec = strdup(value); + } + } - return 1; + return 1; } -enum err desktop_load(struct desktop* target) -{ - DIR* dir; - struct dirent* dir_info; +enum err desktop_load_wayland_sessions(struct desktop *target) { + DIR *dir; + struct dirent *dir_info; - #if defined(NAME_MAX) - char path[NAME_MAX]; - #elif defined(_POSIX_PATH_MAX) - char path[_POSIX_PATH_MAX]; - #else - char path[1024]; - #endif +#if defined(NAME_MAX) + char path[NAME_MAX]; +#elif defined(_POSIX_PATH_MAX) + char path[_POSIX_PATH_MAX]; +#else + char path[1024]; +#endif - // checks dir existence - if (access(config.xsessions, F_OK) == -1) - { - return XSESSIONS_MISSING; - } + // checks dir existence + if (access(config.wayland_sessions, F_OK) == -1) { + return XSESSIONS_MISSING; + } - // requests read access - dir = opendir(config.xsessions); + // requests read access + dir = opendir(config.wayland_sessions); - if (dir == NULL) - { - return XSESSIONS_READ; - } + if (dir == NULL) { + return XSESSIONS_READ; + } - // reads the content - dir_info = readdir(dir); + // reads the content + dir_info = readdir(dir); - while (dir_info != NULL) - { - // skips the files starting with "." - if ((dir_info->d_name)[0] == '.') - { - dir_info = readdir(dir); - continue; - } + while (dir_info != NULL) { + // skips the files starting with "." + if ((dir_info->d_name)[0] == '.') { + dir_info = readdir(dir); + continue; + } - snprintf(path, (sizeof (path)) - 1, "%s/", config.xsessions); - strncat(path, dir_info->d_name, (sizeof (path)) - 1); - ini_parse(path, desktop_handler, NULL); + snprintf(path, (sizeof(path)) - 1, "%s/", config.wayland_sessions); + strncat(path, dir_info->d_name, (sizeof(path)) - 1); + ini_parse(path, desktop_handler, NULL); - if ((value_name != NULL) && (value_exec != NULL)) - { - widget_desktop_add(target, value_name, value_exec, DS_XORG); - value_name = NULL; - value_exec = NULL; - } + if ((value_name != NULL) && (value_exec != NULL)) { + widget_desktop_add(target, value_name, value_exec, DS_WAYLAND); + value_name = NULL; + value_exec = NULL; + } - dir_info = readdir(dir); - } + dir_info = readdir(dir); + } - closedir(dir); + closedir(dir); - return OK; + return OK; } + +enum err desktop_load_xorg_sessions(struct desktop *target) { + DIR *dir; + struct dirent *dir_info; + +#if defined(NAME_MAX) + char path[NAME_MAX]; +#elif defined(_POSIX_PATH_MAX) + char path[_POSIX_PATH_MAX]; +#else + char path[1024]; +#endif + + // checks dir existence + if (access(config.xsessions, F_OK) == -1) { + return XSESSIONS_MISSING; + } + + // requests read access + dir = opendir(config.xsessions); + + if (dir == NULL) { + return XSESSIONS_READ; + } + + // reads the content + dir_info = readdir(dir); + + while (dir_info != NULL) { + // skips the files starting with "." + if ((dir_info->d_name)[0] == '.') { + dir_info = readdir(dir); + continue; + } + + snprintf(path, (sizeof(path)) - 1, "%s/", config.xsessions); + strncat(path, dir_info->d_name, (sizeof(path)) - 1); + ini_parse(path, desktop_handler, NULL); + + if ((value_name != NULL) && (value_exec != NULL)) { + widget_desktop_add(target, value_name, value_exec, DS_XORG); + value_name = NULL; + value_exec = NULL; + } + + dir_info = readdir(dir); + } + + closedir(dir); + + return OK; +} + +enum err desktop_load(struct desktop* target){ + int xload = desktop_load_xorg_sessions(target); + int wload = desktop_load_wayland_sessions(target); + return xload != OK ? xload : wload != OK ? wload : OK; +} \ No newline at end of file diff --git a/src/login.c b/src/login.c index 1db832c..765012b 100644 --- a/src/login.c +++ b/src/login.c @@ -178,7 +178,7 @@ void launch_wayland(struct passwd* pwd, pam_handle_t* pam_handle, const char* de_command) { char cmd[32]; - snprintf(cmd, 32, "exec %s", de_command); + snprintf(cmd, 32, "exec %s %s", config.wayland_cmd, de_command); reset_terminal(pwd); execl(pwd->pw_shell, pwd->pw_shell, "-l", "-c", cmd, NULL); exit(EXIT_SUCCESS); diff --git a/src/widgets.c b/src/widgets.c index fcffd0d..af2f5b9 100644 --- a/src/widgets.c +++ b/src/widgets.c @@ -18,6 +18,7 @@ enum err widget_desktop(struct desktop* target) error |= widget_desktop_add(target, strdup(lang.shell), strdup(""), DS_SHELL); error |= widget_desktop_add(target, strdup(lang.xinitrc), strdup(""), DS_XINITRC); + error |= widget_desktop_add(target, strdup(lang.wayland), strdup(""), DS_WAYLAND); return error; } diff --git a/wsetup.sh b/wsetup.sh new file mode 100644 index 0000000..d49a1ec --- /dev/null +++ b/wsetup.sh @@ -0,0 +1,45 @@ +#!/bin/sh +# wayland-session - run as user +# Copyright (C) 2015 Pier Luigi Fiorini +# This file is extracted from kde-workspace (kdm/kfrontend/genkdmconf.c) +# Copyright (C) 2001-2005 Oswald Buddenhagen +session=$1 +# Note that the respective logout scripts are not sourced. +case $SHELL in + */bash) + [ -z "$BASH" ] && exec $SHELL $0 "$@" + set +o posix + [ -f /etc/profile ] && . /etc/profile + if [ -f $HOME/.bash_profile ]; then + . $HOME/.bash_profile + elif [ -f $HOME/.bash_login ]; then + . $HOME/.bash_login + elif [ -f $HOME/.profile ]; then + . $HOME/.profile + fi + ;; +*/zsh) + [ -z "$ZSH_NAME" ] && exec $SHELL $0 "$@" + [ -d /etc/zsh ] && zdir=/etc/zsh || zdir=/etc + zhome=${ZDOTDIR:-$HOME} + # zshenv is always sourced automatically. + [ -f $zdir/zprofile ] && . $zdir/zprofile + [ -f $zhome/.zprofile ] && . $zhome/.zprofile + [ -f $zdir/zlogin ] && . $zdir/zlogin + [ -f $zhome/.zlogin ] && . $zhome/.zlogin + emulate -R sh + ;; + */csh|*/tcsh) + # [t]cshrc is always sourced automatically. + # Note that sourcing csh.login after .cshrc is non-standard. + wlsess_tmp=${mktemp /tmp/wlsess-env-XXXXXX} + $SHELL -c "if (-f /etc/csh.login) source /etc/csh.login; if (-f ~/.login) source ~/.login; /bin/sh -c 'export -p' >! $wlsess_tmp" + . $wlsess_tmp + rm -f $wlsess_tmp + ;; + *) # Plain sh, ksh, and anything we do not know. + [ -f /etc/profile ] && . /etc/profile + [ -f $HOME/.profile ] && . $HOME/.profile + ;; +esac +eval exec "$session"