Provide BUS:DEV, VENDOR:PRODUCT and NAME as argument to the connect/disconnect scripts
This commit is contained in:
parent
8e8f69f749
commit
1f4b59fb45
7 changed files with 103 additions and 14 deletions
|
@ -411,6 +411,33 @@ start=KEY_ESC
|
|||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--on-connect</option> <replaceable class="parameter">EXE</replaceable></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Launches <replaceable class="parameter">EXE</replaceable>
|
||||
when a controller gets connected. As arguments
|
||||
"<replaceable>BUSDEV</replaceable>:<replaceable>DEVNUM</replaceable>",
|
||||
"<replaceable>idVendor</replaceable>:<replaceable>idProduct</replaceable>",
|
||||
"<replaceable>NAME</replaceable> are provided.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--on-disconnect</option> <replaceable class="parameter">EXE</replaceable></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Launches <replaceable class="parameter">EXE</replaceable>
|
||||
when a controller gets disconnected. As arguments
|
||||
"<replaceable>BUSDEV</replaceable>:<replaceable>DEVNUM</replaceable>",
|
||||
"<replaceable>idVendor</replaceable>:<replaceable>idProduct</replaceable>",
|
||||
"<replaceable>NAME</replaceable> are provided.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
</variablelist>
|
||||
</refsect2>
|
||||
|
||||
|
@ -1486,6 +1513,7 @@ pos = (1.0f - (1.0f - pos) ** t) ** (1 / t);]]></programlisting>
|
|||
switch this behaviour off.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--name NAME</option></term>
|
||||
|
|
|
@ -18,13 +18,21 @@
|
|||
|
||||
#include "controller_slot.hpp"
|
||||
|
||||
#include <boost/format.hpp>
|
||||
|
||||
#include "xboxdrv_thread.hpp"
|
||||
|
||||
void
|
||||
ControllerSlot::connect(XboxdrvThread* thread)
|
||||
ControllerSlot::connect(XboxdrvThread* thread,
|
||||
uint8_t busnum, uint8_t devnum,
|
||||
const XPadDevice& dev_type)
|
||||
{
|
||||
assert(thread == 0);
|
||||
assert(m_thread == 0);
|
||||
m_thread = thread;
|
||||
|
||||
m_busnum = busnum;
|
||||
m_devnum = devnum;
|
||||
m_dev_type = dev_type;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -56,4 +64,22 @@ ControllerSlot::is_connected() const
|
|||
return m_thread;
|
||||
}
|
||||
|
||||
std::string
|
||||
ControllerSlot::get_usbpath() const
|
||||
{
|
||||
return (boost::format("%03d:%03d") % static_cast<int>(m_busnum) % static_cast<int>(m_devnum)).str();
|
||||
}
|
||||
|
||||
std::string
|
||||
ControllerSlot::get_usbid() const
|
||||
{
|
||||
return (boost::format("%04x:%04x") % m_dev_type.idVendor % m_dev_type.idProduct).str();
|
||||
}
|
||||
|
||||
std::string
|
||||
ControllerSlot::get_name() const
|
||||
{
|
||||
return m_dev_type.name;
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
|
|
@ -33,6 +33,10 @@ private:
|
|||
std::vector<ControllerMatchRulePtr> m_rules;
|
||||
int m_led_status;
|
||||
XboxdrvThread* m_thread;
|
||||
|
||||
uint8_t m_busnum;
|
||||
uint8_t m_devnum;
|
||||
XPadDevice m_dev_type;
|
||||
|
||||
public:
|
||||
ControllerSlot() :
|
||||
|
@ -40,7 +44,10 @@ public:
|
|||
m_config(),
|
||||
m_rules(),
|
||||
m_led_status(-1),
|
||||
m_thread(0)
|
||||
m_thread(0),
|
||||
m_busnum(),
|
||||
m_devnum(),
|
||||
m_dev_type()
|
||||
{}
|
||||
|
||||
ControllerSlot(int id_,
|
||||
|
@ -52,7 +59,10 @@ public:
|
|||
m_config(config_),
|
||||
m_rules(rules_),
|
||||
m_led_status(led_status_),
|
||||
m_thread(thread_)
|
||||
m_thread(thread_),
|
||||
m_busnum(),
|
||||
m_devnum(),
|
||||
m_dev_type()
|
||||
{}
|
||||
|
||||
ControllerSlot(const ControllerSlot& rhs) :
|
||||
|
@ -60,7 +70,10 @@ public:
|
|||
m_config(rhs.m_config),
|
||||
m_rules(rhs.m_rules),
|
||||
m_led_status(rhs.m_led_status),
|
||||
m_thread(rhs.m_thread)
|
||||
m_thread(rhs.m_thread),
|
||||
m_busnum(rhs.m_busnum),
|
||||
m_devnum(rhs.m_devnum),
|
||||
m_dev_type(rhs.m_dev_type)
|
||||
{}
|
||||
|
||||
ControllerSlot& operator=(const ControllerSlot& rhs)
|
||||
|
@ -72,12 +85,17 @@ public:
|
|||
m_rules = rhs.m_rules;
|
||||
m_led_status = rhs.m_led_status;
|
||||
m_thread = rhs.m_thread;
|
||||
m_busnum = rhs.m_busnum;
|
||||
m_devnum = rhs.m_devnum;
|
||||
m_dev_type = rhs.m_dev_type;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool is_connected() const;
|
||||
void connect(XboxdrvThread* thread);
|
||||
void connect(XboxdrvThread* thread,
|
||||
uint8_t busnum, uint8_t devnum,
|
||||
const XPadDevice& dev_type);
|
||||
void disconnect();
|
||||
bool try_disconnect();
|
||||
|
||||
|
@ -85,6 +103,10 @@ public:
|
|||
int get_led_status() const { return m_led_status; }
|
||||
int get_id() const { return m_id; }
|
||||
ControllerSlotConfigPtr get_config() const { return m_config; }
|
||||
|
||||
std::string get_usbpath() const;
|
||||
std::string get_usbid() const;
|
||||
std::string get_name() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -499,7 +499,7 @@ XboxdrvDaemon::launch_xboxdrv(const XPadDevice& dev_type, const Options& opts,
|
|||
|
||||
std::auto_ptr<XboxdrvThread> thread(new XboxdrvThread(message_proc, controller, opts));
|
||||
thread->start_thread(opts);
|
||||
slot.connect(thread.release());
|
||||
slot.connect(thread.release(), busnum, devnum, dev_type);
|
||||
|
||||
on_connect(slot);
|
||||
|
||||
|
@ -530,15 +530,26 @@ XboxdrvDaemon::get_free_slot_count() const
|
|||
void
|
||||
XboxdrvDaemon::on_connect(const ControllerSlot& slot)
|
||||
{
|
||||
log_info("launching connect script");
|
||||
spawn_exe(m_opts.on_connect);
|
||||
log_info("launching connect script: " << m_opts.on_connect);
|
||||
std::vector<std::string> args;
|
||||
args.push_back(m_opts.on_connect);
|
||||
args.push_back(slot.get_usbpath());
|
||||
args.push_back(slot.get_usbid());
|
||||
args.push_back(slot.get_name());
|
||||
spawn_exe(args);
|
||||
}
|
||||
|
||||
void
|
||||
XboxdrvDaemon::on_disconnect(const ControllerSlot& slot)
|
||||
{
|
||||
log_info("launching disconnect script");
|
||||
spawn_exe(m_opts.on_disconnect);
|
||||
log_info("launching disconnect script: " << m_opts.on_disconnect);
|
||||
|
||||
std::vector<std::string> args;
|
||||
args.push_back(m_opts.on_disconnect);
|
||||
args.push_back(slot.get_usbpath());
|
||||
args.push_back(slot.get_usbid());
|
||||
args.push_back(slot.get_name());
|
||||
spawn_exe(args);
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/bash
|
||||
|
||||
exec notify-send "Xboxdrv" "Controller connected ${RANDOM} $*" -t 1000
|
||||
exec notify-send -i gtk-connect "Controller connected:" "$3\n$2\n$1"
|
||||
|
||||
# EOF #
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/bash
|
||||
|
||||
exec notify-send "Xboxdrv" "Controller disconnected ${RANDOM} $*" -t 1000
|
||||
exec notify-send -i gtk-disconnect "Controller disconnected" "$3\n$2\n$1"
|
||||
|
||||
# EOF #
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
exec ./xboxdrv --daemon \
|
||||
--on-connect test/on-connect.sh \
|
||||
--on-disconnect test/on-disconnect.sh \
|
||||
--next-controller --next-controller
|
||||
--next-controller \
|
||||
--next-controller \
|
||||
--next-controller
|
||||
|
||||
# EOF #
|
||||
|
|
Loading…
Reference in a new issue