|
| 1 | +/* |
| 2 | + * Copyright (C) 2016 Andriy Grytsenko <andrej@rep.kiev.ua> |
| 3 | + * |
| 4 | + * This file is a part of LXKeys project. |
| 5 | + * |
| 6 | + * This program is free software; you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation; either version 2 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License |
| 17 | + * along with this program; if not, write to the Free Software Foundation, |
| 18 | + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | + */ |
| 20 | + |
| 21 | +#ifdef HAVE_CONFIG_H |
| 22 | +# include "config.h" |
| 23 | +#endif |
| 24 | + |
| 25 | +#include "lxkeys.h" |
| 26 | + |
| 27 | +#include <libfm/fm-extra.h> |
| 28 | +#include <glib/gi18n.h> |
| 29 | + |
| 30 | +typedef struct { |
| 31 | + char *path; |
| 32 | + FmXmlFile *xml; |
| 33 | + GList *actions; /* no-exec actions */ |
| 34 | + GList *execs; /* exec-only actions */ |
| 35 | + //GList *available_wm_actions; |
| 36 | + //GList *available_app_actions; |
| 37 | +} ObXmlFile; |
| 38 | + |
| 39 | +static FmXmlFileTag ObXmlFile_keyboard; /* section that we work on */ |
| 40 | +static FmXmlFileTag ObXmlFile_keybind; /* subsection, for each binding */ |
| 41 | +static FmXmlFileTag ObXmlFile_action; /* may be multiple for a binding */ |
| 42 | +static FmXmlFileTag ObXmlFile_command; /* for <action name="Execute"> */ |
| 43 | +static FmXmlFileTag ObXmlFile_execute; /* obsolete alias for command */ |
| 44 | + |
| 45 | +static gboolean tag_handler_keyboard(FmXmlFileItem *item, GList *children, |
| 46 | + char * const *attribute_names, |
| 47 | + char * const *attribute_values, |
| 48 | + guint n_attributes, gint line, gint pos, |
| 49 | + GError **error, gpointer user_data) |
| 50 | +{ |
| 51 | + /* anything to do? */ |
| 52 | + return TRUE; |
| 53 | +} |
| 54 | + |
| 55 | +static gboolean tag_handler_keybind(FmXmlFileItem *item, GList *children, |
| 56 | + char * const *attribute_names, |
| 57 | + char * const *attribute_values, |
| 58 | + guint n_attributes, gint line, gint pos, |
| 59 | + GError **error, gpointer user_data) |
| 60 | +{ |
| 61 | + /* decide where to put: execs or actions */ |
| 62 | + /* create LXKeysApp or LXKeysGlobal */ |
| 63 | +} |
| 64 | + |
| 65 | +static gboolean tag_handler_action(FmXmlFileItem *item, GList *children, |
| 66 | + char * const *attribute_names, |
| 67 | + char * const *attribute_values, |
| 68 | + guint n_attributes, gint line, gint pos, |
| 69 | + GError **error, gpointer user_data) |
| 70 | +{ |
| 71 | + |
| 72 | +} |
| 73 | + |
| 74 | +static gboolean tag_handler_command(FmXmlFileItem *item, GList *children, |
| 75 | + char * const *attribute_names, |
| 76 | + char * const *attribute_values, |
| 77 | + guint n_attributes, gint line, gint pos, |
| 78 | + GError **error, gpointer user_data) |
| 79 | +{ |
| 80 | +} |
| 81 | + |
| 82 | +static gpointer obcfg_load(gpointer config, GError **error) |
| 83 | +{ |
| 84 | + ObXmlFile *cfg = (ObXmlFile *)config; |
| 85 | + |
| 86 | + if (config) { |
| 87 | + /* just discard any changes if any exist */ |
| 88 | + FmXmlFile *old_xml = cfg->xml; |
| 89 | + |
| 90 | + cfg->xml = fm_xml_file_new(old_xml); |
| 91 | + g_object_unref(old_xml); |
| 92 | + } else { |
| 93 | + /* prepare data */ |
| 94 | + cfg = g_new0(ObXmlFile, 1); |
| 95 | + cfg->xml = fm_xml_file_new(NULL); |
| 96 | + /* register handlers */ |
| 97 | + ObXmlFile_keyboard = fm_xml_file_set_handler(cfg->xml, "keyboard", |
| 98 | + &tag_handler_keyboard, FALSE, NULL); |
| 99 | + ObXmlFile_keybind = fm_xml_file_set_handler(cfg->xml, "keybind", |
| 100 | + &tag_handler_keybind, FALSE, NULL); |
| 101 | + ObXmlFile_action = fm_xml_file_set_handler(cfg->xml, "action", |
| 102 | + &tag_handler_action, FALSE, NULL); |
| 103 | + ObXmlFile_command = fm_xml_file_set_handler(cfg->xml, "command", |
| 104 | + &tag_handler_command, FALSE, NULL); |
| 105 | + ObXmlFile_execute = fm_xml_file_set_handler(cfg->xml, "execute", |
| 106 | + &tag_handler_command, FALSE, NULL); |
| 107 | + |
| 108 | + /* let try to detect rc.xml file currently in use: |
| 109 | + with Lubuntu it's lubuntu-rc.xml, with lxde session it's lxde-rc.xml */ |
| 110 | + |
| 111 | + } |
| 112 | + /* try to load ~/.config/openbox/$xml */ |
| 113 | + |
| 114 | + /* if it does not exist then try to load $XDG_SYSTEM_CONFDIR/openbox/rc.xml */ |
| 115 | + |
| 116 | + |
| 117 | + return cfg; |
| 118 | +} |
| 119 | + |
| 120 | +static gboolean obcfg_save(gpointer config, GError **error) |
| 121 | +{ |
| 122 | + ObXmlFile *cfg = (ObXmlFile *)config; |
| 123 | + |
| 124 | + /* save as ~/.config/openbox/$xml */ |
| 125 | +} |
| 126 | + |
| 127 | +static void obcfg_free(gpointer config) |
| 128 | +{ |
| 129 | + ObXmlFile *cfg = (ObXmlFile *)config; |
| 130 | + |
| 131 | + g_free(cfg->path); |
| 132 | + g_object_unref(cfg->xml); |
| 133 | + g_free(cfg); |
| 134 | +} |
| 135 | + |
| 136 | +static GList *obcfg_get_wm_keys(gpointer config, const char *mask, GError **error) |
| 137 | +{ |
| 138 | +} |
| 139 | + |
| 140 | +static gboolean obcfg_set_wm_key(gpointer config, LXKeysGlobal *data, GError **error) |
| 141 | +{ |
| 142 | +} |
| 143 | + |
| 144 | +FM_DEFINE_MODULE(lxkeys, Openbox) |
| 145 | + |
| 146 | +LXKeysPluginInit fm_module_init_lxkeys = { |
| 147 | + .load = obcfg_load, |
| 148 | + .save = obcfg_save, |
| 149 | + .free = obcfg_free, |
| 150 | + .get_wm_keys = obcfg_get_wm_keys, |
| 151 | + .set_wm_key = obcfg_set_wm_key |
| 152 | + // .get_wm_actions = obcfg_get_wm_actions, |
| 153 | + // .get_app_keys = obcfg_get_app_keys, |
| 154 | + // .set_app_key = obcfg_set_app_key |
| 155 | +}; |
0 commit comments