feat(api): add get_current_window call
All checks were successful
CI API Docs / Test C API Documentation Generation (pull_request) Successful in 25s
CI API Docs / Test Python API Documentation Generation (pull_request) Successful in 31s
CI Code / Check coding style (pull_request) Successful in 35s
CI Code / Check spelling (pull_request) Successful in 20s
CI Code / Linux (arch) (pull_request) Successful in 13m58s
CI Code / Linux (ubuntu) (pull_request) Successful in 13m41s
CI Code / Linux (debian) (pull_request) Successful in 16m19s

Add prof_get_current_window API to retrieve the title of the currently active window, matching the titlebar display.

The feature is especially useful to track currently used plugin window.
This commit is contained in:
2025-09-30 16:40:02 +02:00
parent 40dd773c6a
commit e36f7d5964
8 changed files with 107 additions and 52 deletions

View File

@@ -185,6 +185,17 @@ void prof_send_line(char *line);
*/ */
char* prof_get_current_recipient(void); char* prof_get_current_recipient(void);
/**
* Gets the title of the current window as shown in the titlebar.
*
* Special cases:
* - MUC configuration window: Includes "config" and an asterisk if modified (e.g., "room@example.com config *").
* - vCard window: Includes the bare JID and an asterisk if modified (e.g., "vCard user@example.com *").
*
* @return A null-terminated string containing the window title. The caller must free the returned string.
*/
char* prof_get_current_window(void);
/** /**
* Gets the Jabber ID of the current chat room. * Gets the Jabber ID of the current chat room.
* @return The room Jabber ID (e.g., "metalchat@conference.example.com") or NULL if not in a room. * @return The room Jabber ID (e.g., "metalchat@conference.example.com") or NULL if not in a room.

View File

@@ -830,6 +830,22 @@ def get_current_recipient() -> str | None:
""" """
pass pass
def get_current_window() -> str:
"""Retrieves the title of the current window as shown in the titlebar.
Returns the title of the currently active window, matching the titlebar display.
Special cases:
- For MUC configuration windows, includes "config" and an asterisk if modified (e.g., "room@example.com config \*").
- For vCard windows, includes the bare JID and an asterisk if modified (e.g., "vCard user@example.com \*").
:return: The window title as a string.
Example::
title = prof.get_current_window()
prof.cons_show(f"Current window: {title}")
"""
def get_current_muc() -> str | None: def get_current_muc() -> str | None:
"""Retrieves the Jabber ID of the current chat room. """Retrieves the Jabber ID of the current chat room.

View File

@@ -54,6 +54,7 @@
#include "plugins/settings.h" #include "plugins/settings.h"
#include "plugins/disco.h" #include "plugins/disco.h"
#include "ui/ui.h" #include "ui/ui.h"
#include "ui/win_types.h"
#include "ui/window_list.h" #include "ui/window_list.h"
#include "xmpp/roster_list.h" #include "xmpp/roster_list.h"
@@ -205,6 +206,13 @@ api_get_current_recipient(void)
} }
} }
gchar*
api_get_current_window(void)
{
ProfWin* current = wins_get_current();
return win_get_title(current);
}
char* char*
api_get_current_muc(void) api_get_current_muc(void)
{ {

View File

@@ -46,6 +46,7 @@ void api_notify(const char* message, const char* category, int timeout_ms);
void api_send_line(char* line); void api_send_line(char* line);
char* api_get_current_recipient(void); char* api_get_current_recipient(void);
gchar* api_get_current_window(void);
char* api_get_current_muc(void); char* api_get_current_muc(void);
gboolean api_current_win_is_console(void); gboolean api_current_win_is_console(void);
char* api_get_current_nick(void); char* api_get_current_nick(void);

View File

@@ -165,6 +165,12 @@ c_api_get_current_recipient(void)
return api_get_current_recipient(); return api_get_current_recipient();
} }
static char*
c_api_get_current_window(void)
{
return api_get_current_window();
}
static char* static char*
c_api_get_current_muc(void) c_api_get_current_muc(void)
{ {
@@ -477,6 +483,7 @@ c_api_init(void)
prof_notify = c_api_notify; prof_notify = c_api_notify;
prof_send_line = c_api_send_line; prof_send_line = c_api_send_line;
prof_get_current_recipient = c_api_get_current_recipient; prof_get_current_recipient = c_api_get_current_recipient;
prof_get_current_window = c_api_get_current_window;
prof_get_current_muc = c_api_get_current_muc; prof_get_current_muc = c_api_get_current_muc;
prof_current_win_is_console = c_api_current_win_is_console; prof_current_win_is_console = c_api_current_win_is_console;
prof_get_current_nick = c_api_get_current_nick; prof_get_current_nick = c_api_get_current_nick;

View File

@@ -62,6 +62,7 @@ void (*prof_notify)(const char* message, int timeout_ms, const char* category) =
void (*prof_send_line)(char* line) = NULL; void (*prof_send_line)(char* line) = NULL;
char* (*prof_get_current_recipient)(void) = NULL; char* (*prof_get_current_recipient)(void) = NULL;
char* (*prof_get_current_window)(void) = NULL;
char* (*prof_get_current_muc)(void) = NULL; char* (*prof_get_current_muc)(void) = NULL;
int (*prof_current_win_is_console)(void) = NULL; int (*prof_current_win_is_console)(void) = NULL;
char* (*prof_get_current_nick)(void) = NULL; char* (*prof_get_current_nick)(void) = NULL;

View File

@@ -71,6 +71,7 @@ void (*prof_notify)(const char* message, int timeout_ms, const char* category);
void (*prof_send_line)(char* line); void (*prof_send_line)(char* line);
char* (*prof_get_current_recipient)(void); char* (*prof_get_current_recipient)(void);
char* (*prof_get_current_window)(void);
char* (*prof_get_current_muc)(void); char* (*prof_get_current_muc)(void);
int (*prof_current_win_is_console)(void); int (*prof_current_win_is_console)(void);
char* (*prof_get_current_nick)(void); char* (*prof_get_current_nick)(void);

View File

@@ -415,6 +415,15 @@ python_api_get_current_recipient(PyObject* self, PyObject* args)
} }
} }
static PyObject*
python_api_get_current_window(PyObject* self, PyObject* args)
{
allow_python_threads();
auto_gchar gchar* recipient = api_get_current_window();
disable_python_threads();
return Py_BuildValue("s", recipient);
}
static PyObject* static PyObject*
python_api_get_current_muc(PyObject* self, PyObject* args) python_api_get_current_muc(PyObject* self, PyObject* args)
{ {
@@ -1530,6 +1539,7 @@ static PyMethodDef apiMethods[] = {
{ "send_line", python_api_send_line, METH_VARARGS, "Send a line of input." }, { "send_line", python_api_send_line, METH_VARARGS, "Send a line of input." },
{ "notify", python_api_notify, METH_VARARGS, "Send desktop notification." }, { "notify", python_api_notify, METH_VARARGS, "Send desktop notification." },
{ "get_current_recipient", python_api_get_current_recipient, METH_VARARGS, "Return the jid of the recipient of the current window." }, { "get_current_recipient", python_api_get_current_recipient, METH_VARARGS, "Return the jid of the recipient of the current window." },
{ "get_current_window", python_api_get_current_window, METH_VARARGS, "Return title of the current window." },
{ "get_current_muc", python_api_get_current_muc, METH_VARARGS, "Return the jid of the room of the current window." }, { "get_current_muc", python_api_get_current_muc, METH_VARARGS, "Return the jid of the room of the current window." },
{ "get_current_nick", python_api_get_current_nick, METH_VARARGS, "Return nickname in current room." }, { "get_current_nick", python_api_get_current_nick, METH_VARARGS, "Return nickname in current room." },
{ "get_name_from_roster", python_api_get_name_from_roster, METH_VARARGS, "Return nickname in roster of barejid." }, { "get_name_from_roster", python_api_get_name_from_roster, METH_VARARGS, "Return nickname in roster of barejid." },