Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
libvncserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rasky
libvncserver
Commits
5d090960
Commit
5d090960
authored
Apr 30, 2002
by
dscho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dimming for mac
parent
103df739
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
185 additions
and
3 deletions
+185
-3
mac.c
mac.c
+185
-3
No files found.
mac.c
View file @
5d090960
...
...
@@ -43,8 +43,176 @@
#include "rfb.h"
#include "keysym.h"
#include <IOKit/pwr_mgt/IOPMLib.h>
#include <IOKit/pwr_mgt/IOPM.h>
#include <stdio.h>
#include <signal.h>
#include <pthread.h>
Bool
rfbNoDimming
=
FALSE
;
Bool
rfbNoSleep
=
TRUE
;
static
pthread_mutex_t
dimming_mutex
;
static
unsigned
long
dim_time
;
static
unsigned
long
sleep_time
;
static
mach_port_t
master_dev_port
;
static
io_connect_t
power_mgt
;
static
Bool
initialized
=
FALSE
;
static
Bool
dim_time_saved
=
FALSE
;
static
Bool
sleep_time_saved
=
FALSE
;
static
int
saveDimSettings
(
void
)
{
if
(
IOPMGetAggressiveness
(
power_mgt
,
kPMMinutesToDim
,
&
dim_time
)
!=
kIOReturnSuccess
)
return
-
1
;
dim_time_saved
=
TRUE
;
return
0
;
}
static
int
restoreDimSettings
(
void
)
{
if
(
!
dim_time_saved
)
return
-
1
;
if
(
IOPMSetAggressiveness
(
power_mgt
,
kPMMinutesToDim
,
dim_time
)
!=
kIOReturnSuccess
)
return
-
1
;
dim_time_saved
=
FALSE
;
dim_time
=
0
;
return
0
;
}
static
int
saveSleepSettings
(
void
)
{
if
(
IOPMGetAggressiveness
(
power_mgt
,
kPMMinutesToSleep
,
&
sleep_time
)
!=
kIOReturnSuccess
)
return
-
1
;
sleep_time_saved
=
TRUE
;
return
0
;
}
static
int
restoreSleepSettings
(
void
)
{
if
(
!
sleep_time_saved
)
return
-
1
;
if
(
IOPMSetAggressiveness
(
power_mgt
,
kPMMinutesToSleep
,
sleep_time
)
!=
kIOReturnSuccess
)
return
-
1
;
sleep_time_saved
=
FALSE
;
sleep_time
=
0
;
return
0
;
}
int
rfbDimmingInit
(
void
)
{
pthread_mutex_init
(
&
dimming_mutex
,
NULL
);
if
(
IOMasterPort
(
bootstrap_port
,
&
master_dev_port
)
!=
kIOReturnSuccess
)
return
-
1
;
if
(
!
(
power_mgt
=
IOPMFindPowerManagement
(
master_dev_port
)))
return
-
1
;
if
(
rfbNoDimming
)
{
if
(
saveDimSettings
()
<
0
)
return
-
1
;
if
(
IOPMSetAggressiveness
(
power_mgt
,
kPMMinutesToDim
,
0
)
!=
kIOReturnSuccess
)
return
-
1
;
}
if
(
rfbNoSleep
)
{
if
(
saveSleepSettings
()
<
0
)
return
-
1
;
if
(
IOPMSetAggressiveness
(
power_mgt
,
kPMMinutesToSleep
,
0
)
!=
kIOReturnSuccess
)
return
-
1
;
}
initialized
=
TRUE
;
return
0
;
}
int
rfbUndim
(
void
)
{
int
result
=
-
1
;
pthread_mutex_lock
(
&
dimming_mutex
);
if
(
!
initialized
)
goto
DONE
;
if
(
!
rfbNoDimming
)
{
if
(
saveDimSettings
()
<
0
)
goto
DONE
;
if
(
IOPMSetAggressiveness
(
power_mgt
,
kPMMinutesToDim
,
0
)
!=
kIOReturnSuccess
)
goto
DONE
;
if
(
restoreDimSettings
()
<
0
)
goto
DONE
;
}
if
(
!
rfbNoSleep
)
{
if
(
saveSleepSettings
()
<
0
)
goto
DONE
;
if
(
IOPMSetAggressiveness
(
power_mgt
,
kPMMinutesToSleep
,
0
)
!=
kIOReturnSuccess
)
goto
DONE
;
if
(
restoreSleepSettings
()
<
0
)
goto
DONE
;
}
result
=
0
;
DONE:
pthread_mutex_unlock
(
&
dimming_mutex
);
return
result
;
}
int
rfbDimmingShutdown
(
void
)
{
int
result
=
-
1
;
if
(
!
initialized
)
goto
DONE
;
pthread_mutex_lock
(
&
dimming_mutex
);
if
(
dim_time_saved
)
if
(
restoreDimSettings
()
<
0
)
goto
DONE
;
if
(
sleep_time_saved
)
if
(
restoreSleepSettings
()
<
0
)
goto
DONE
;
result
=
0
;
DONE:
pthread_mutex_unlock
(
&
dimming_mutex
);
return
result
;
}
rfbScreenInfoPtr
rfbScreen
;
void
shutdown
(
rfbClientPtr
cl
);
/* some variables to enable special behaviour */
int
startTime
=
-
1
,
maxSecsToConnect
=
0
;
Bool
disconnectAfterFirstClient
=
TRUE
;
...
...
@@ -233,6 +401,8 @@ KbdAddEvent(Bool down, KeySym keySym, struct _rfbClientRec* cl)
if
(((
int
)
cl
->
clientData
)
==-
1
)
return
;
/* viewOnly */
rfbUndim
();
for
(
i
=
0
;
i
<
(
sizeof
(
keyTable
)
/
sizeof
(
int
));
i
+=
2
)
{
if
(
keyTable
[
i
]
==
keySym
)
{
keyCode
=
keyTable
[
i
+
1
];
...
...
@@ -262,6 +432,8 @@ PtrAddEvent(buttonMask, x, y, cl)
if
(((
int
)
cl
->
clientData
)
==-
1
)
return
;
/* viewOnly */
rfbUndim
();
position
.
x
=
x
;
position
.
y
=
y
;
...
...
@@ -340,7 +512,7 @@ refreshCallback(CGRectCount count, const CGRect *rectArray, void *ignore)
#endif
if
(
startTime
>
0
&&
time
(
0
)
>
startTime
+
maxSecsToConnect
)
exit
(
0
);
shutdown
(
0
);
for
(
i
=
0
;
i
<
count
;
i
++
)
rfbMarkRectAsModified
(
rfbScreen
,
...
...
@@ -351,13 +523,13 @@ refreshCallback(CGRectCount count, const CGRect *rectArray, void *ignore)
void
clientGone
(
rfbClientPtr
cl
)
{
exit
(
0
);
shutdown
(
cl
);
}
enum
rfbNewClientAction
newClient
(
rfbClientPtr
cl
)
{
if
(
startTime
>
0
&&
time
(
0
)
>
startTime
+
maxSecsToConnect
)
exit
(
0
);
shutdown
(
cl
);
if
(
disconnectAfterFirstClient
)
cl
->
clientGoneHook
=
clientGone
;
...
...
@@ -407,6 +579,8 @@ int main(int argc,char *argv[])
sharedMode
=
TRUE
;
}
rfbDimmingInit
();
ScreenInit
(
argc
,
argv
);
rfbScreen
->
newClientHook
=
newClient
;
...
...
@@ -417,6 +591,14 @@ int main(int argc,char *argv[])
CGRegisterScreenRefreshCallback
(
refreshCallback
,
NULL
);
RunApplicationEventLoop
();
rfbDimmingShutdown
();
return
(
0
);
/* never ... */
}
void
shutdown
(
rfbClientPtr
cl
)
{
rfbScreenCleanup
(
rfbScreen
);
rfbDimmingShutdown
();
exit
(
0
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment