drivers/hid/hid-magicmouse.c
Source file repositories/reference/linux-study-clean/drivers/hid/hid-magicmouse.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hid/hid-magicmouse.c- Extension
.c- Size
- 32966 bytes
- Lines
- 1066
- Domain
- Driver Families
- Bucket
- drivers/hid
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/hid.hlinux/input/mt.hlinux/module.hlinux/slab.hlinux/workqueue.hhid-ids.h
Detected Declarations
struct magicmouse_scfunction param_set_scroll_speedfunction magicmouse_firm_touchfunction magicmouse_emit_buttonsfunction magicmouse_emit_touchfunction magicmouse_raw_eventfunction magicmouse_eventfunction magicmouse_setup_inputfunction reportedfunction magicmouse_input_mappingfunction magicmouse_input_configuredfunction magicmouse_enable_multitouchfunction magicmouse_enable_mt_workfunction is_usb_magicmouse2function is_usb_magictrackpad2function magicmouse_fetch_batteryfunction magicmouse_battery_timer_tickfunction magicmouse_probefunction magicmouse_removefunction is_usb_magictrackpad2
Annotated Snippet
struct magicmouse_sc {
struct input_dev *input;
unsigned long quirks;
int ntouches;
int scroll_accel;
unsigned long scroll_jiffies;
struct {
short x;
short y;
short scroll_x;
short scroll_y;
short scroll_x_hr;
short scroll_y_hr;
u8 size;
bool scroll_x_active;
bool scroll_y_active;
} touches[16];
int tracking_ids[16];
struct hid_device *hdev;
struct delayed_work work;
struct timer_list battery_timer;
};
static int magicmouse_firm_touch(struct magicmouse_sc *msc)
{
int touch = -1;
int ii;
/* If there is only one "firm" touch, set touch to its
* tracking ID.
*/
for (ii = 0; ii < msc->ntouches; ii++) {
int idx = msc->tracking_ids[ii];
if (msc->touches[idx].size < 8) {
/* Ignore this touch. */
} else if (touch >= 0) {
touch = -1;
break;
} else {
touch = idx;
}
}
return touch;
}
static void magicmouse_emit_buttons(struct magicmouse_sc *msc, int state)
{
int last_state = test_bit(BTN_LEFT, msc->input->key) << 0 |
test_bit(BTN_RIGHT, msc->input->key) << 1 |
test_bit(BTN_MIDDLE, msc->input->key) << 2;
if (emulate_3button) {
int id;
/* If some button was pressed before, keep it held
* down. Otherwise, if there's exactly one firm
* touch, use that to override the mouse's guess.
*/
if (state == 0) {
/* The button was released. */
} else if (last_state != 0) {
state = last_state;
} else if ((id = magicmouse_firm_touch(msc)) >= 0) {
int x = msc->touches[id].x;
if (x < middle_button_start)
state = 1;
else if (x > middle_button_stop)
state = 2;
else
state = 4;
} /* else: we keep the mouse's guess */
input_report_key(msc->input, BTN_MIDDLE, state & 4);
}
input_report_key(msc->input, BTN_LEFT, state & 1);
input_report_key(msc->input, BTN_RIGHT, state & 2);
if (state != last_state)
msc->scroll_accel = SCROLL_ACCEL_DEFAULT;
}
static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tdata)
{
struct input_dev *input = msc->input;
int id, x, y, size, orientation, touch_major, touch_minor, state, down;
Annotation
- Immediate include surface: `linux/device.h`, `linux/hid.h`, `linux/input/mt.h`, `linux/module.h`, `linux/slab.h`, `linux/workqueue.h`, `hid-ids.h`.
- Detected declarations: `struct magicmouse_sc`, `function param_set_scroll_speed`, `function magicmouse_firm_touch`, `function magicmouse_emit_buttons`, `function magicmouse_emit_touch`, `function magicmouse_raw_event`, `function magicmouse_event`, `function magicmouse_setup_input`, `function reported`, `function magicmouse_input_mapping`.
- Atlas domain: Driver Families / drivers/hid.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.