updates and additions
[webos-internals:djcin7s-modifications.git] / misc / misc-fixed-keyboard-brightness-35.patch
1 diff --git a/usr/lib/luna/system/luna-systemui/app/controllers/bar-assistant.js b/usr/lib/luna/system/luna-systemui/app/controllers/bar-assistant.js
2 index 0e239cc..bdfd637 100644
3 --- a/usr/lib/luna/system/luna-systemui/app/controllers/bar-assistant.js
4 +++ b/usr/lib/luna/system/luna-systemui/app/controllers/bar-assistant.js
5 @@ -105,6 +105,7 @@ var BarAssistant = Foundations.Class.create({
6                 
7                 //Subscribe to Powerd Notification.
8                 this.powerInit();
9 +               this.keypadOnSliderChange();
10                 
11                 //Subscribe to Application Manager 
12                 this.initOnServerStart("com.palm.applicationManager", this.appMgrInit.bind(this));
13 @@ -2230,6 +2231,78 @@ queryBatteryStatus: function() {
14                 method: 'batteryStatusQuery',});
15  },
16  
17 +keypadOnSliderChange: function() {
18 +       this.sliderStateSubscribe = new Mojo.Service.Request('palm://com.palm.keys/switches', {
19 +               method: 'status',
20 +               parameters: {'subscribe': true},
21 +               onSuccess: function(data) {
22 +                       if (data.key === "slider") {
23 +                               if (this.displayStateSubscribe) {
24 +                                       this.displayStateSubscribe.cancel();
25 +                                       delete this.displayStateSubscribe;
26 +                               }
27 +                               if (data.state === 'up') {
28 +                                       this.keypadBrightness(true);
29 +                                       this.recheckSliderState.bind(this).delay(1); //do this to catch quick up & down movements
30 +                               } else if (data.state === 'down') {
31 +                                       this.keypadBrightness(false);
32 +                               }
33 +                       }
34 +               }.bind(this)
35 +       });
36 +},
37 +
38 +keypadBrightness: function(state) {
39 +       if (state == true) {
40 +               this.controller.serviceRequest('palm://com.palm.power/backlight', {
41 +                       method: 'set',
42 +                       parameters:{keypad:{brightness:35}}
43 +               });
44 +               if (!this.displayStateSubscribe) {
45 +                       this.keypadOnDisplayChange.bind(this).delay(0.25);
46 +               }
47 +       } else if (state == false) {
48 +               if (this.displayStateSubscribe) {
49 +                       this.displayStateSubscribe.cancel();
50 +                       delete this.displayStateSubscribe;
51 +               }
52 +               this.controller.serviceRequest('palm://com.palm.power/backlight', {
53 +                       method: 'set',
54 +                       parameters:{keypad:{brightness:0}}
55 +               });
56 +       }
57 +},
58 +
59 +keypadOnDisplayChange: function() {
60 +       this.displayStateSubscribe = new Mojo.Service.Request('palm://com.palm.display/control', {
61 +               method:'status',
62 +               parameters:{subscribe:true},
63 +               onSuccess: function(response) {
64 +                       if(response && response.event) {
65 +                               if (response.event === "displayOn") {
66 +                                       this.recheckSliderState();
67 +                               }
68 +                       }
69 +               }.bind(this),
70 +       });
71 +},
72 +
73 +recheckSliderState: function() {
74 +       var serviceRequest = new Mojo.Service.Request('palm://com.palm.keys/switches', {
75 +               method: 'status',
76 +               parameters: {'get':'slider'},
77 +               onSuccess: function(data) {
78 +                       if (data.key === "slider") {
79 +                               if (data.state === 'down') {
80 +                                       this.keypadBrightness(false);
81 +                               } else if (data.state === 'up') {
82 +                                       this.keypadBrightness(true);
83 +                               }
84 +                       }
85 +               }.bind(this),
86 +       });
87 +},
88 +
89  /*
90   * Initialize power
91   */