summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQball Cow <qball@blame.services>2023-06-01 21:56:06 +0200
committerQball Cow <qball@blame.services>2023-06-01 21:56:06 +0200
commit7972420c30275514751802d1ed517a45bbd83da1 (patch)
tree93beb5e084fa0c5cbaafa07a5b3839c7e5b2d3cf
parentdd3035a1a61f8196d394f6867701a0e1b3af30ac (diff)
Prepare updates for new APIs.
-rw-r--r--include/mode-private.h47
-rw-r--r--source/mode.c3
-rw-r--r--source/modes/combi.c3
-rw-r--r--source/modes/drun.c3
-rw-r--r--source/modes/filebrowser.c1
-rw-r--r--source/modes/help-keys.c3
-rw-r--r--source/modes/recursivebrowser.c2
-rw-r--r--source/modes/run.c3
-rw-r--r--source/modes/ssh.c3
-rw-r--r--source/modes/window.c6
10 files changed, 66 insertions, 8 deletions
diff --git a/include/mode-private.h b/include/mode-private.h
index 796bcc6f..08c6043b 100644
--- a/include/mode-private.h
+++ b/include/mode-private.h
@@ -32,7 +32,16 @@
G_BEGIN_DECLS
/** ABI version to check if loaded plugin is compatible. */
-#define ABI_VERSION 6u
+#define ABI_VERSION 7u
+
+typedef enum {
+ /** Mode type is not set */
+ MODE_TYPE_UNSET = 0b0000,
+ /** A normal mode. */
+ MODE_TYPE_SWITCHER = 0b0001,
+ /** A mode that can be used to completer */
+ MODE_TYPE_COMPLETER = 0b0010,
+} ModeType;
/**
* @param data Pointer to #Mode object.
@@ -151,6 +160,28 @@ typedef char *(*_mode_preprocess_input)(Mode *sw, const char *input);
*/
typedef char *(*_mode_get_message)(const Mode *sw);
+
+/**
+ * Create a new instance of this mode.
+ * Free (free) result after use, after using mode_destroy.
+ *
+ * @returns Instantiate a new instance of this mode.
+ */
+typedef Mode *(*_mode_create)( void );
+
+/**
+ * @param sw The #Mode pointer
+ * @param menu_retv The return value
+ * @param input The input string
+ * @param selected_line The selected line
+ * @param the path that was completed
+ *
+ * Handle the user accepting an entry in completion mode.
+ *
+ * @returns the next action to take
+ */
+typedef ModeMode (*_mode_completer_result)(Mode *sw, int menu_retv, char **input,
+ unsigned int selected_line, char **path);
/**
* Structure defining a switcher.
* It consists of a name, callback and if enabled
@@ -197,6 +228,17 @@ struct rofi_mode {
* And has data in `ed`
*/
_mode_free free;
+
+ /**
+ * Create mode.
+ */
+ _mode_create create;
+
+ /**
+ * If this mode is used as completer.
+ */
+ _mode_completer_result completer_result;
+
/** Extra fields for script */
void *ed;
@@ -206,6 +248,9 @@ struct rofi_mode {
/** Fallack icon.*/
uint32_t fallback_icon_fetch_uid;
uint32_t fallback_icon_not_found;
+
+ /** type */
+ ModeType type;
};
G_END_DECLS
#endif // ROFI_MODE_PRIVATE_H
diff --git a/source/mode.c b/source/mode.c
index e2e5d85d..e62127cb 100644
--- a/source/mode.c
+++ b/source/mode.c
@@ -44,6 +44,9 @@
int mode_init(Mode *mode) {
g_return_val_if_fail(mode != NULL, FALSE);
g_return_val_if_fail(mode->_init != NULL, FALSE);
+ if ( mode->type == MODE_TYPE_UNSET ) {
+ g_warning("Mode '%s' does not have a type set. Please update mode.", mode->name);
+ }
// to make sure this is initialized correctly.
mode->fallback_icon_fetch_uid = 0;
mode->fallback_icon_not_found = FALSE;
diff --git a/source/modes/combi.c b/source/modes/combi.c
index 3542e72a..25b6ce85 100644
--- a/source/modes/combi.c
+++ b/source/modes/combi.c
@@ -342,4 +342,5 @@ Mode combi_mode = {.name = "combi",
._get_icon = combi_get_icon,
._preprocess_input = combi_preprocess_input,
.private_data = NULL,
- .free = NULL};
+ .free = NULL,
+ .type = MODE_TYPE_SWITCHER };
diff --git a/source/modes/drun.c b/source/modes/drun.c
index 635fed7b..41b086ca 100644
--- a/source/modes/drun.c
+++ b/source/modes/drun.c
@@ -1483,6 +1483,7 @@ Mode drun_mode = {.name = "drun",
._get_icon = _get_icon,
._preprocess_input = NULL,
.private_data = NULL,
- .free = NULL};
+ .free = NULL,
+ .type = MODE_TYPE_SWITCHER };
#endif // ENABLE_DRUN
diff --git a/source/modes/filebrowser.c b/source/modes/filebrowser.c
index f9930ee7..bed84927 100644
--- a/source/modes/filebrowser.c
+++ b/source/modes/filebrowser.c
@@ -729,4 +729,5 @@ Mode file_browser_mode = {
._preprocess_input = NULL,
.private_data = NULL,
.free = NULL,
+ .type = MODE_TYPE_SWITCHER|MODE_TYPE_COMPLETER
};
diff --git a/source/modes/help-keys.c b/source/modes/help-keys.c
index 728219ea..0b8a565a 100644
--- a/source/modes/help-keys.c
+++ b/source/modes/help-keys.c
@@ -118,4 +118,5 @@ Mode help_keys_mode = {.name = "keys",
._get_completion = NULL,
._get_display_value = _get_display_value,
.private_data = NULL,
- .free = NULL};
+ .free = NULL,
+ .type = MODE_TYPE_SWITCHER };
diff --git a/source/modes/recursivebrowser.c b/source/modes/recursivebrowser.c
index 8f9ec2b7..8293e8a4 100644
--- a/source/modes/recursivebrowser.c
+++ b/source/modes/recursivebrowser.c
@@ -568,4 +568,6 @@ Mode recursive_browser_mode = {
._preprocess_input = NULL,
.private_data = NULL,
.free = NULL,
+ .create = create_new_recursive_browser,
+ .type = MODE_TYPE_SWITCHER|MODE_TYPE_COMPLETER
};
diff --git a/source/modes/run.c b/source/modes/run.c
index 0fc018a1..db3245da 100644
--- a/source/modes/run.c
+++ b/source/modes/run.c
@@ -572,5 +572,6 @@ Mode run_mode = {.name = "run",
._get_completion = NULL,
._preprocess_input = NULL,
.private_data = NULL,
- .free = NULL};
+ .free = NULL,
+ .type = MODE_TYPE_SWITCHER };
/** @}*/
diff --git a/source/modes/ssh.c b/source/modes/ssh.c
index aca8f7ad..05484cc4 100644
--- a/source/modes/ssh.c
+++ b/source/modes/ssh.c
@@ -645,5 +645,6 @@ Mode ssh_mode = {.name = "ssh",
._get_completion = NULL,
._preprocess_input = NULL,
.private_data = NULL,
- .free = NULL};
+ .free = NULL,
+ .type = MODE_TYPE_SWITCHER };
/**@}*/
diff --git a/source/modes/window.c b/source/modes/window.c
index 5ac4a8f8..91ad3fc7 100644
--- a/source/modes/window.c
+++ b/source/modes/window.c
@@ -1134,7 +1134,8 @@ Mode window_mode = {.name = "window",
._get_completion = NULL,
._preprocess_input = NULL,
.private_data = NULL,
- .free = NULL};
+ .free = NULL,
+ .type = MODE_TYPE_SWITCHER };
Mode window_mode_cd = {.name = "windowcd",
.cfg_name_key = "display-windowcd",
._init = window_mode_init_cd,
@@ -1147,6 +1148,7 @@ Mode window_mode_cd = {.name = "windowcd",
._get_completion = NULL,
._preprocess_input = NULL,
.private_data = NULL,
- .free = NULL};
+ .free = NULL,
+ .type = MODE_TYPE_SWITCHER };
#endif // WINDOW_MODE