void kbd_backlight_init(void) { int ret; if (kbd_cfg.auto_on) kbd_bck_info.inhibit = 0; else kbd_bck_info.inhibit = KBD_INHIBIT_CFG; kbd_bck_info.toggle_lvl = kbd_cfg.auto_lvl; kbd_bck_info.inhibit_lvl = 0; kbd_bck_info.auto_on = 0; if (!has_kbd_backlight() || (mops->type == MACHINE_POWERBOOK_58) || (mops->type == MACHINE_POWERBOOK_59)) { /* Nothing to probe for the PMU05 machines */ ret = 0; } else ret = kbd_probe_lmu(); if (!has_kbd_backlight() || (ret < 0)) { lmu_info.lmuaddr = 0; kbd_bck_info.r_sens = 0; kbd_bck_info.l_sens = 0; kbd_bck_info.level = 0; ambient_info.left = 0; ambient_info.right = 0; ambient_info.max = 0; return; } kbd_bck_info.level = kbd_backlight_get(); if (kbd_bck_info.level < 0) kbd_bck_info.level = 0; kbd_bck_info.max = KBD_BACKLIGHT_MAX; ambient_init(&kbd_bck_info.r_sens, &kbd_bck_info.l_sens); kbd_auto_init(); }
void kbd_backlight_init(void) { if (kbd_cfg.auto_on) kbd_bck_info.inhibit = 0; else kbd_bck_info.inhibit = KBD_INHIBIT_CFG; kbd_bck_info.toggle_lvl = kbd_cfg.auto_lvl; kbd_bck_info.inhibit_lvl = 0; kbd_bck_info.auto_on = 0; if (!has_kbd_backlight()) { kbd_bck_info.r_sens = 0; kbd_bck_info.l_sens = 0; kbd_bck_info.level = 0; return; } kbd_bck_info.level = kbd_backlight_get(); if (kbd_bck_info.level < 0) kbd_bck_info.level = 0; kbd_bck_info.max = KBD_BACKLIGHT_MAX; kbd_auto_init(); }
void kbd_backlight_cleanup(void) { if (has_kbd_backlight()) kbd_auto_cleanup(); }
void evdev_process_events(int fd, uint32_t events) { int ret; struct input_event ev; /* some of the event devices cease to exist when suspending */ if (events & (EPOLLERR | EPOLLHUP)) { logmsg(LOG_INFO, "Error condition signaled on event device"); ret = evloop_remove(fd); if (ret < 0) logmsg(LOG_ERR, "Could not remove device from event loop"); if (fd == internal_kbd_fd) internal_kbd_fd = -1; close(fd); return; } ret = read(fd, &ev, sizeof(struct input_event)); if (ret != sizeof(struct input_event)) return; if (ev.type == EV_KEY) { /* key released - we don't care */ if (ev.value == 0) return; /* Reset keyboard backlight idle timer */ if (fd == internal_kbd_fd) { kbd_bck_info.idle = 0; kbd_backlight_inhibit_clear(KBD_INHIBIT_IDLE); } switch (ev.code) { case KEY_BRIGHTNESSDOWN: logdebug("\nKEY: LCD backlight down\n"); mops->lcd_backlight_step(STEP_DOWN); break; case KEY_BRIGHTNESSUP: logdebug("\nKEY: LCD backlight up\n"); mops->lcd_backlight_step(STEP_UP); break; case KEY_MUTE: logdebug("\nKEY: audio mute\n"); audio_toggle_mute(); break; case KEY_VOLUMEDOWN: logdebug("\nKEY: audio down\n"); audio_step(STEP_DOWN); break; case KEY_VOLUMEUP: logdebug("\nKEY: audio up\n"); audio_step(STEP_UP); break; case KEY_SWITCHVIDEOMODE: logdebug("\nKEY: video toggle\n"); video_switch(); break; case KEY_KBDILLUMTOGGLE: logdebug("\nKEY: keyboard backlight off\n"); if (!has_kbd_backlight()) break; if (kbd_cfg.auto_on) kbd_backlight_inhibit_toggle(KBD_INHIBIT_USER); else kbd_backlight_toggle(); break; case KEY_KBDILLUMDOWN: logdebug("\nKEY: keyboard backlight down\n"); if (!has_kbd_backlight()) break; kbd_backlight_step(STEP_DOWN); if (kbd_bck_info.level == KBD_BACKLIGHT_OFF) kbd_backlight_inhibit_set(KBD_INHIBIT_USER); break; case KEY_KBDILLUMUP: logdebug("\nKEY: keyboard backlight up\n"); if (!has_kbd_backlight()) break; kbd_backlight_inhibit_clear(KBD_INHIBIT_USER); kbd_backlight_step(STEP_UP); break; case KEY_EJECTCD: logdebug("\nKEY: CD eject\n"); cd_eject(); break; case KEY_NEXTSONG: logdebug("\nKEY: IR fast forward\n"); break; case KEY_PREVIOUSSONG: logdebug("\nKEY: IR rewind\n"); break; case KEY_PLAYPAUSE: logdebug("\nKEY: IR play/pause\n"); break; case KEY_MENU: logdebug("\nKEY: IR menu\n"); break; default: #if 0 logdebug("\nKEY: %x\n", ev.code); #endif /* 0 */ break; } } else if (ev.type == EV_SW) { /* Lid switch */ if (ev.code == SW_LID) { if (ev.value) { logdebug("\nLID: closed\n"); kbd_backlight_inhibit_set(KBD_INHIBIT_LID); } else { logdebug("\nLID: open\n"); kbd_backlight_inhibit_clear(KBD_INHIBIT_LID); } } } }
static int evdev_try_add(int fd) { unsigned short id[4]; unsigned long bit[EV_MAX][NBITS(KEY_MAX)]; char devname[256]; int ret; devname[0] = '\0'; ioctl(fd, EVIOCGNAME(sizeof(devname)), devname); logdebug("\nInvestigating evdev [%s]\n", devname); ioctl(fd, EVIOCGID, id); if ((!evdev_is_internal(id)) #ifndef __powerpc__ && !(appleir_cfg.enabled && evdev_is_appleir(id)) #endif && !(has_kbd_backlight() && evdev_is_lidswitch(id)) && !(evdev_is_mouseemu(id)) && !(evdev_is_extkbd(id))) { logdebug("Discarding evdev: bus 0x%04x, vid 0x%04x, pid 0x%04x\n", id[ID_BUS], id[ID_VENDOR], id[ID_PRODUCT]); close(fd); return -1; } memset(bit, 0, sizeof(bit)); ioctl(fd, EVIOCGBIT(0, EV_MAX), bit[0]); if (!test_bit(EV_KEY, bit[0])) { logdebug("evdev: no EV_KEY event type (not a keyboard)\n"); if (!test_bit(EV_SW, bit[0])) { logdebug("Discarding evdev: no EV_SW event type (not a switch)\n"); close(fd); return -1; } } /* Wireless keyboards advertise EV_ABS events, single them out */ else if (test_bit(EV_ABS, bit[0]) && !(evdev_is_extkbd_alu_wl(id))) { logdebug("Discarding evdev with EV_ABS event type (mouse/trackpad)\n"); close(fd); return -1; } /* There are 2 keyboards, but one of them only has the eject key; the real keyboard has all the keys and the LEDs. Checking for the LEDs is a quick way of identifying the keyboard we want. */ if (test_bit(EV_LED, bit[0]) && evdev_is_internal(id)) { logdebug(" -> Internal keyboard\n"); internal_kbd_fd = fd; } ret = evloop_add(fd, EPOLLIN, evdev_process_events); if (ret < 0) { logmsg(LOG_ERR, "Could not add device to event loop"); if (fd == internal_kbd_fd) internal_kbd_fd = -1; close(fd); return -1; } return 0; }