mirror of
https://gitlab.freedesktop.org/libinput/libei.git
synced 2026-05-01 15:07:59 +02:00
libei: add a hook to configure the client name
Better than the current "myclient". Lacks safety and whatnot so long-term it will have to get replaced with something else. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
f228927b1f
commit
b1231dfa1f
4 changed files with 25 additions and 2 deletions
|
|
@ -50,6 +50,7 @@ struct ei {
|
|||
enum ei_state state;
|
||||
struct list event_queue;
|
||||
struct list devices;
|
||||
char *name;
|
||||
};
|
||||
|
||||
enum ei_device_state {
|
||||
|
|
|
|||
17
src/libei.c
17
src/libei.c
|
|
@ -116,6 +116,7 @@ ei_destroy(struct ei *ei)
|
|||
if (ei->backend.destroy)
|
||||
ei->backend.destroy(ei);
|
||||
sink_unref(ei->sink);
|
||||
free(ei->name);
|
||||
}
|
||||
|
||||
OBJECT_DECLARE_INIT(ei);
|
||||
|
|
@ -215,8 +216,13 @@ connection_send_connect(struct ei *ei)
|
|||
if (ei->state == EI_STATE_DISCONNECTED)
|
||||
return 0;
|
||||
|
||||
const char buf[] = "connect myclient\n"; /* FIXME */
|
||||
return min(0, xwrite(source_get_fd(ei->source), buf, sizeof(buf)));
|
||||
char buf[128];
|
||||
|
||||
if (!xsnprintf(buf, sizeof(buf), "connect %s\n",
|
||||
ei->name ? ei->name : "unnamed"))
|
||||
return -ENOMEM;
|
||||
|
||||
return min(0, xwrite(source_get_fd(ei->source), buf, strlen(buf)));
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -555,3 +561,10 @@ ei_set_connection(struct ei *ei, int fd)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
_public_ void
|
||||
ei_configure_name(struct ei *ei, const char *name)
|
||||
{
|
||||
free(ei->name);
|
||||
ei->name = xstrdup(name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,6 +101,13 @@ enum ei_event_type {
|
|||
struct ei *
|
||||
ei_new(void);
|
||||
|
||||
/**
|
||||
* Set the name for this client. This is a suggestion to the
|
||||
* server only and may not be honored.
|
||||
*/
|
||||
void
|
||||
ei_configure_name(struct ei * ei, const char *name);
|
||||
|
||||
struct ei *
|
||||
ei_socket_new_context(void *user_data);
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ int main(int argc, char **argv)
|
|||
struct ei *ei = ei_socket_new_context(NULL);
|
||||
assert(ei);
|
||||
|
||||
ei_configure_name(ei, "ei-socket-client-demo");
|
||||
|
||||
/* This should be handled by libei */
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue