2009-07-24 01:04:12 +00:00
|
|
|
/*
|
|
|
|
|
spacenavd - a free software replacement driver for 6dof space-mice.
|
2022-03-21 06:50:36 +00:00
|
|
|
Copyright (C) 2007-2022 John Tsiombikas <nuclear@member.fsf.org>
|
2009-07-24 01:04:12 +00:00
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
2009-07-20 22:47:08 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include "client.h"
|
2018-08-15 12:10:26 +00:00
|
|
|
#include "dev.h"
|
|
|
|
|
#include "spnavd.h"
|
2009-07-20 22:47:08 +00:00
|
|
|
|
|
|
|
|
#ifdef USE_X11
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2013-04-04 22:06:50 +00:00
|
|
|
static struct client *client_list = NULL;
|
|
|
|
|
static struct client *client_iter; /* iterator (used by first/next calls) */
|
2009-07-20 22:47:08 +00:00
|
|
|
|
|
|
|
|
/* add a client to the list
|
|
|
|
|
* cdata points to the socket fd for new-protocol clients, or the
|
|
|
|
|
* window XID for clients talking to us through the magellan protocol
|
|
|
|
|
*/
|
|
|
|
|
struct client *add_client(int type, void *cdata)
|
|
|
|
|
{
|
|
|
|
|
struct client *client;
|
|
|
|
|
|
|
|
|
|
#ifdef USE_X11
|
2013-04-04 22:06:50 +00:00
|
|
|
if(!cdata || (type != CLIENT_UNIX && type != CLIENT_X11))
|
2009-07-20 22:47:08 +00:00
|
|
|
#else
|
2013-04-04 22:06:50 +00:00
|
|
|
if(!cdata || type != CLIENT_UNIX)
|
2009-07-20 22:47:08 +00:00
|
|
|
#endif
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-12 14:47:09 +00:00
|
|
|
if(!(client = calloc(1, sizeof *client))) {
|
2009-07-20 22:47:08 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
client->type = type;
|
|
|
|
|
if(type == CLIENT_UNIX) {
|
|
|
|
|
client->sock = *(int*)cdata;
|
|
|
|
|
#ifdef USE_X11
|
|
|
|
|
} else {
|
|
|
|
|
client->win = *(Window*)cdata;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2022-02-10 10:58:33 +00:00
|
|
|
/* default to protocol version 0 until the client changes it */
|
|
|
|
|
client->proto = 0;
|
2022-03-21 06:50:36 +00:00
|
|
|
/* evmask for proto-v0 clients is just input events */
|
|
|
|
|
client->evmask = EVMASK_MOTION | EVMASK_BUTTON;
|
2009-07-20 22:47:08 +00:00
|
|
|
|
|
|
|
|
client->sens = 1.0f;
|
2022-02-10 10:58:33 +00:00
|
|
|
client->dev = 0; /* default/first device */
|
2013-04-04 22:06:50 +00:00
|
|
|
|
2018-08-23 02:57:40 +00:00
|
|
|
if(!client_list && cfg.led == LED_AUTO) {
|
|
|
|
|
/* on first client, turn the led on */
|
|
|
|
|
set_devices_led(1);
|
2013-04-04 22:06:50 +00:00
|
|
|
}
|
|
|
|
|
client->next = client_list;
|
|
|
|
|
client_list = client;
|
2009-07-20 22:47:08 +00:00
|
|
|
|
|
|
|
|
return client;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void remove_client(struct client *client)
|
|
|
|
|
{
|
|
|
|
|
struct client *iter = client_list;
|
2018-08-23 02:57:40 +00:00
|
|
|
if(!iter) return;
|
2009-07-20 22:47:08 +00:00
|
|
|
|
2013-04-04 22:06:50 +00:00
|
|
|
if(iter == client) {
|
|
|
|
|
client_list = iter->next;
|
|
|
|
|
free(iter);
|
2018-08-23 02:57:40 +00:00
|
|
|
iter = client_list;
|
|
|
|
|
if(!iter) {
|
|
|
|
|
if(cfg.led == LED_AUTO) {
|
2018-08-15 12:10:26 +00:00
|
|
|
set_devices_led(0); /* no more clients, turn off led */
|
2018-08-23 02:57:40 +00:00
|
|
|
}
|
2013-04-04 22:06:50 +00:00
|
|
|
return;
|
2018-08-15 12:10:26 +00:00
|
|
|
}
|
2013-04-04 22:06:50 +00:00
|
|
|
}
|
|
|
|
|
|
2009-07-20 22:47:08 +00:00
|
|
|
while(iter->next) {
|
|
|
|
|
if(iter->next == client) {
|
|
|
|
|
struct client *tmp = iter->next;
|
|
|
|
|
iter->next = tmp->next;
|
|
|
|
|
free(tmp);
|
|
|
|
|
} else {
|
|
|
|
|
iter = iter->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int get_client_type(struct client *client)
|
|
|
|
|
{
|
|
|
|
|
return client->type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int get_client_socket(struct client *client)
|
|
|
|
|
{
|
|
|
|
|
return client->sock;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef USE_X11
|
|
|
|
|
Window get_client_window(struct client *client)
|
|
|
|
|
{
|
|
|
|
|
return client->win;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void set_client_sensitivity(struct client *client, float sens)
|
|
|
|
|
{
|
|
|
|
|
client->sens = sens;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float get_client_sensitivity(struct client *client)
|
|
|
|
|
{
|
|
|
|
|
return client->sens;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-10 10:58:33 +00:00
|
|
|
void set_client_device(struct client *client, struct device *dev)
|
2013-04-04 22:06:50 +00:00
|
|
|
{
|
2022-02-10 10:58:33 +00:00
|
|
|
client->dev = dev;
|
2013-04-04 22:06:50 +00:00
|
|
|
}
|
|
|
|
|
|
2022-02-10 10:58:33 +00:00
|
|
|
struct device *get_client_device(struct client *client)
|
2013-04-04 22:06:50 +00:00
|
|
|
{
|
2022-02-10 10:58:33 +00:00
|
|
|
return client->dev ? client->dev : get_devices();
|
2013-04-04 22:06:50 +00:00
|
|
|
}
|
|
|
|
|
|
2009-07-20 22:47:08 +00:00
|
|
|
struct client *first_client(void)
|
|
|
|
|
{
|
2018-08-23 02:57:40 +00:00
|
|
|
client_iter = client_list;
|
|
|
|
|
return client_iter;
|
2009-07-20 22:47:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct client *next_client(void)
|
|
|
|
|
{
|
2018-08-23 02:57:40 +00:00
|
|
|
if(client_iter) {
|
2013-04-04 22:06:50 +00:00
|
|
|
client_iter = client_iter->next;
|
2018-08-23 02:57:40 +00:00
|
|
|
}
|
2013-04-04 22:06:50 +00:00
|
|
|
return client_iter;
|
2009-07-20 22:47:08 +00:00
|
|
|
}
|