@@ -34,6 +34,8 @@ struct pdf_source {
3434 unsigned char * cached_raster ;
3535 bool cached_anypagesrendered ;
3636
37+ obs_hotkey_pair_id change_page_hotkey_pair ;
38+
3739 obs_source_t * src ;
3840};
3941
@@ -170,6 +172,45 @@ static void pdf_source_load(struct pdf_source *context)
170172}
171173
172174
175+ static void pdf_source_change_page (struct pdf_source * context ,
176+ bool change_to_previous )
177+ {
178+ if (change_to_previous && context -> page_number > 1 )
179+ {
180+ context -> page_number -- ;
181+ }
182+ else if (!change_to_previous && context -> page_number < 9999 )
183+ {
184+ context -> page_number ++ ;
185+ }
186+
187+ pdf_source_load (context );
188+ }
189+
190+
191+ static bool pdf_source_hotkey_prev (void * data , obs_hotkey_pair_id id ,
192+ obs_hotkey_t * hotkey , bool pressed )
193+ {
194+ if (pressed )
195+ {
196+ pdf_source_change_page (data , true);
197+ }
198+
199+ return true;
200+ }
201+
202+ static bool pdf_source_hotkey_next (void * data , obs_hotkey_pair_id id ,
203+ obs_hotkey_t * hotkey , bool pressed )
204+ {
205+ if (pressed )
206+ {
207+ pdf_source_change_page (data , false);
208+ }
209+
210+ return true;
211+ }
212+
213+
173214static const char * pdf_source_get_name (void * unused )
174215{
175216 UNUSED_PARAMETER (unused );
@@ -193,10 +234,13 @@ static void pdf_source_update(void *data, obs_data_t *settings)
193234
194235static void * pdf_source_create (obs_data_t * settings , obs_source_t * source )
195236{
196- UNUSED_PARAMETER (source );
197-
198237 struct pdf_source * context = bzalloc (sizeof (struct pdf_source ));
199238 context -> src = source ;
239+
240+ context -> change_page_hotkey_pair = obs_hotkey_pair_register_source (source ,
241+ "PdfSource.PrevPage" , obs_module_text ("PdfSource.PrevPage" ),
242+ "PdfSource.NextPage" , obs_module_text ("PdfSource.NextPage" ),
243+ pdf_source_hotkey_prev , pdf_source_hotkey_next , context , context );
200244
201245 pdf_source_update (context , settings );
202246
@@ -219,6 +263,9 @@ static void pdf_source_destroy(void *data)
219263 context -> texture = NULL ;
220264 }
221265
266+ obs_hotkey_pair_unregister (context -> change_page_hotkey_pair );
267+ context -> change_page_hotkey_pair = OBS_INVALID_HOTKEY_PAIR_ID ;
268+
222269 bfree (context );
223270}
224271
@@ -266,21 +313,6 @@ static void pdf_source_render(void *data, gs_effect_t *effect)
266313 }
267314}
268315
269- static void pdf_source_change_page (struct pdf_source * context ,
270- bool change_to_previous )
271- {
272- if (change_to_previous && context -> page_number > 1 )
273- {
274- context -> page_number -- ;
275- }
276- else if (!change_to_previous && context -> page_number < 9999 )
277- {
278- context -> page_number ++ ;
279- }
280-
281- pdf_source_load (context );
282- }
283-
284316static void pdf_source_key_click (void * data ,
285317 const struct obs_key_event * event , bool key_up )
286318{
0 commit comments