3 // ©1996-2002 Henrik Isaksson
17 struct InputEvent
*myhandler(struct InputEvent
*ev
, struct MsgPort
*port
)
19 struct InputEvent
* __saveds ASM
myhandler(register __a0
struct InputEvent
*ev
GNUCREG(a0
),
20 register __a1
struct MsgPort
*port
GNUCREG(a1
))
23 struct InputEvent
*evnt
=ev
;
26 if(evnt
->ie_Class
== IECLASS_RAWKEY
) {
29 m
=PM_Mem_Alloc(sizeof(struct PM_InpMsg
));
31 m
->msg
.mn_Length
=sizeof(struct PM_InpMsg
);
32 m
->msg
.mn_ReplyPort
=NULL
;
34 switch(evnt
->ie_Code
) {
37 m
->Kind
=PM_MSG_TERMINATE
;
46 m
->Kind
=PM_MSG_OPENSUB
;
49 m
->Kind
=PM_MSG_CLOSESUB
;
53 m
->Kind
=PM_MSG_SELECT
;
56 m
->Kind
=PM_MSG_MULTISELECT
;
59 m
->Kind
=PM_MSG_DEBUGINFO
;
62 if(m
->Kind
) PutMsg(port
, (struct Message
*)m
);
67 if(evnt
->ie_Class
== IECLASS_TIMER
) {
70 m
=PM_Mem_Alloc(sizeof(struct PM_InpMsg
));
72 m
->msg
.mn_Length
=sizeof(struct PM_InpMsg
);
73 m
->msg
.mn_ReplyPort
=NULL
;
75 PutMsg(port
, (struct Message
*)m
);
78 if(evnt
->ie_Class
== IECLASS_RAWMOUSE
) {
81 m
=PM_Mem_Alloc(sizeof(struct PM_InpMsg
));
83 m
->msg
.mn_Length
=sizeof(struct PM_InpMsg
);
84 m
->msg
.mn_ReplyPort
=NULL
;
85 m
->Kind
=PM_MSG_RAWMOUSE
;
86 m
->Code
=evnt
->ie_Code
;
87 m
->Qual
=evnt
->ie_Qualifier
;
88 PutMsg(port
, (struct Message
*)m
);
91 evnt
->ie_Code
=IECODE_NOBUTTON
;
93 evnt
=evnt
->ie_NextEvent
;
101 static char handlername
[] = "PM Input Handler";
105 AROS_UFH2(struct InputEvent
*, myhandler_aros
,
106 AROS_UFHA(struct InputEvent
*, ev
, A0
),
107 AROS_UFHA(struct MsgPort
*, port
, A1
))
111 return myhandler(ev
, port
);
115 #define HANDLER_CODE (APTR)AROS_ASMSYMNAME(myhandler_aros)
117 #define HANDLER_CODE (void *)myhandler
122 struct PM_InputHandler
*PM_InstallHandler(int pri
)
124 struct PM_InputHandler
*pmh
;
126 pmh
=PM_Mem_Alloc(sizeof(struct PM_InputHandler
));
128 pmh
->mp
=CreatePort(0,0);
130 pmh
->port
=CreatePort(0,0);
132 pmh
->ior
=CreateStdIO(pmh
->mp
);
134 pmh
->error
=OpenDevice("input.device",0,(struct IORequest
*)pmh
->ior
,0);
136 pmh
->intr
.is_Data
=(APTR
)pmh
->port
;
137 pmh
->intr
.is_Code
=HANDLER_CODE
;
138 pmh
->intr
.is_Node
.ln_Pri
=pri
;
139 pmh
->intr
.is_Node
.ln_Name
=handlername
;
140 pmh
->ior
->io_Command
=IND_ADDHANDLER
;
141 pmh
->ior
->io_Data
=(APTR
)&pmh
->intr
;
142 pmh
->ior
->io_Message
.mn_ReplyPort
=pmh
->mp
;
144 DoIO((struct IORequest
*)pmh
->ior
);
158 void PM_RemoveHandler(struct PM_InputHandler
*pmh
)
160 struct PM_InpMsg
*msg
;
166 pmh
->ior
->io_Command
=IND_REMHANDLER
;
167 pmh
->ior
->io_Data
=(APTR
)&pmh
->intr
;
168 DoIO((struct IORequest
*)pmh
->ior
);
170 CloseDevice((struct IORequest
*)pmh
->ior
);
172 DeleteStdIO(pmh
->ior
);
174 while((msg
=(struct PM_InpMsg
*)GetMsg(pmh
->port
))) {
177 DeletePort(pmh
->port
);
194 void EZDeleteTimer(struct timerequest
*TimeRequest
)
196 struct MsgPort
*TimePort
;
200 if(TimeRequest
->tr_node
.io_Device
)
201 CloseDevice((struct IORequest
*)TimeRequest
);
203 if((TimePort
=TimeRequest
->tr_node
.io_Message
.mn_ReplyPort
))
204 DeletePort(TimePort
);
206 DeleteExtIO((struct IORequest
*)TimeRequest
);
210 struct timerequest
*EZCreateTimer(LONG Unit
)
212 struct MsgPort
*TimePort
;
213 struct timerequest
*TimeRequest
;
215 if(!(TimePort
= (struct MsgPort
*)CreatePort(NULL
,0)))
218 if(!(TimeRequest
= (struct timerequest
*)CreateExtIO(TimePort
,sizeof(struct timerequest
))))
220 DeletePort(TimePort
);
225 if(OpenDevice(TIMERNAME
, Unit
, (struct IORequest
*)TimeRequest
, 0))
227 DeleteExtIO((struct IORequest
*)TimeRequest
);
228 DeletePort(TimePort
);