OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "power_manager/powerd.h" | 5 #include "power_manager/powerd.h" |
6 | 6 |
7 #include <gdk/gdkx.h> | 7 #include <gdk/gdkx.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <X11/extensions/dpms.h> | 9 #include <X11/extensions/dpms.h> |
10 #include <X11/keysym.h> | 10 #include <X11/keysym.h> |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 daemon->GenerateMetricsOnPowerEvent(info); | 289 daemon->GenerateMetricsOnPowerEvent(info); |
290 // Do not emergency suspend if no battery exists. | 290 // Do not emergency suspend if no battery exists. |
291 if (info.battery_is_present) | 291 if (info.battery_is_present) |
292 daemon->SuspendOnLowBattery(info.battery_percentage); | 292 daemon->SuspendOnLowBattery(info.battery_percentage); |
293 } | 293 } |
294 | 294 |
295 GdkFilterReturn Daemon::gdk_event_filter(GdkXEvent* gxevent, GdkEvent*, | 295 GdkFilterReturn Daemon::gdk_event_filter(GdkXEvent* gxevent, GdkEvent*, |
296 gpointer data) { | 296 gpointer data) { |
297 Daemon* daemon = static_cast<Daemon*>(data); | 297 Daemon* daemon = static_cast<Daemon*>(data); |
298 XEvent* xevent = static_cast<XEvent*>(gxevent); | 298 XEvent* xevent = static_cast<XEvent*>(gxevent); |
| 299 bool changed_brightness = false; |
299 if (xevent->type == KeyPress) { | 300 if (xevent->type == KeyPress) { |
300 int keycode = xevent->xkey.keycode; | 301 int keycode = xevent->xkey.keycode; |
301 if (keycode == daemon->key_brightness_up_ || | 302 if (keycode == daemon->key_brightness_up_ || |
302 keycode == daemon->key_f7_) { | 303 keycode == daemon->key_f7_) { |
303 if (keycode == daemon->key_brightness_up_) { | 304 if (keycode == daemon->key_brightness_up_) { |
304 LOG(INFO) << "Key press: Brightness up"; | 305 LOG(INFO) << "Key press: Brightness up"; |
305 } else { // keycode == daemon->key_f7_ | 306 } else { // keycode == daemon->key_f7_ |
306 LOG(INFO) << "Key press: F7"; | 307 LOG(INFO) << "Key press: F7"; |
307 } | 308 } |
308 daemon->ctl_->IncreaseBrightness(); | 309 daemon->ctl_->IncreaseBrightness(); |
| 310 changed_brightness = true; |
309 } else if (keycode == daemon->key_brightness_down_ || | 311 } else if (keycode == daemon->key_brightness_down_ || |
310 keycode == daemon->key_f6_) { | 312 keycode == daemon->key_f6_) { |
311 if (keycode == daemon->key_brightness_down_) { | 313 if (keycode == daemon->key_brightness_down_) { |
312 LOG(INFO) << "Key press: Brightness down"; | 314 LOG(INFO) << "Key press: Brightness down"; |
313 } else { // keycode == daemon->key_f6_ | 315 } else { // keycode == daemon->key_f6_ |
314 LOG(INFO) << "Key press: F6"; | 316 LOG(INFO) << "Key press: F6"; |
315 } | 317 } |
316 daemon->ctl_->DecreaseBrightness(); | 318 daemon->ctl_->DecreaseBrightness(); |
| 319 changed_brightness = true; |
317 } | 320 } |
318 } | 321 } |
| 322 |
| 323 if (changed_brightness) { |
| 324 int64 brightness = 0; |
| 325 daemon->ctl_->GetBrightness(&brightness); |
| 326 daemon->SendBrightnessChangedSignal(static_cast<int>(brightness)); |
| 327 } |
| 328 |
319 return GDK_FILTER_CONTINUE; | 329 return GDK_FILTER_CONTINUE; |
320 } | 330 } |
321 | 331 |
322 void Daemon::GrabKey(KeyCode key, uint32 mask) { | 332 void Daemon::GrabKey(KeyCode key, uint32 mask) { |
323 uint32 NumLockMask = Mod2Mask; | 333 uint32 NumLockMask = Mod2Mask; |
324 uint32 CapsLockMask = LockMask; | 334 uint32 CapsLockMask = LockMask; |
325 Window root = DefaultRootWindow(GDK_DISPLAY()); | 335 Window root = DefaultRootWindow(GDK_DISPLAY()); |
326 XGrabKey(GDK_DISPLAY(), key, mask, root, True, GrabModeAsync, GrabModeAsync); | 336 XGrabKey(GDK_DISPLAY(), key, mask, root, True, GrabModeAsync, GrabModeAsync); |
327 XGrabKey(GDK_DISPLAY(), key, mask | CapsLockMask, root, True, | 337 XGrabKey(GDK_DISPLAY(), key, mask | CapsLockMask, root, True, |
328 GrabModeAsync, GrabModeAsync); | 338 GrabModeAsync, GrabModeAsync); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 Daemon* daemon = static_cast<Daemon*>(data); | 477 Daemon* daemon = static_cast<Daemon*>(data); |
468 if (!strcmp(name, "lock_on_idle_suspend")) { | 478 if (!strcmp(name, "lock_on_idle_suspend")) { |
469 daemon->ReadLockScreenSettings(); | 479 daemon->ReadLockScreenSettings(); |
470 daemon->locker_.Init(daemon->use_xscreensaver_, | 480 daemon->locker_.Init(daemon->use_xscreensaver_, |
471 daemon->lock_on_idle_suspend_); | 481 daemon->lock_on_idle_suspend_); |
472 daemon->SetIdleOffset(0); | 482 daemon->SetIdleOffset(0); |
473 } | 483 } |
474 return true; | 484 return true; |
475 } | 485 } |
476 | 486 |
| 487 void Daemon::SendBrightnessChangedSignal(int level) { |
| 488 chromeos::dbus::Proxy proxy(chromeos::dbus::GetSystemBusConnection(), |
| 489 "/", |
| 490 kPowerManagerInterface); |
| 491 DBusMessage* signal = dbus_message_new_signal("/", |
| 492 kPowerManagerInterface, |
| 493 kBrightnessChangedSignal); |
| 494 CHECK(signal); |
| 495 dbus_message_append_args(signal, |
| 496 DBUS_TYPE_INT32, &level, |
| 497 DBUS_TYPE_INVALID); |
| 498 dbus_g_proxy_send(proxy.gproxy(), signal, NULL); |
| 499 dbus_message_unref(signal); |
| 500 } |
| 501 |
477 } // namespace power_manager | 502 } // namespace power_manager |
OLD | NEW |