@@ -565,37 +565,27 @@ void con_fix_percent(Con *con) {
565
565
*
566
566
*/
567
567
void con_toggle_fullscreen (Con * con , int fullscreen_mode ) {
568
- Con * workspace , * fullscreen ;
569
-
570
568
if (con -> type == CT_WORKSPACE ) {
571
569
DLOG ("You cannot make a workspace fullscreen.\n" );
572
570
return ;
573
571
}
574
572
575
573
DLOG ("toggling fullscreen for %p / %s\n" , con , con -> name );
576
- if (con -> fullscreen_mode == CF_NONE ) {
577
- /* 1: check if there already is a fullscreen con */
578
- if (fullscreen_mode == CF_GLOBAL )
579
- fullscreen = con_get_fullscreen_con (croot , CF_GLOBAL );
580
- else {
581
- workspace = con_get_workspace (con );
582
- fullscreen = con_get_fullscreen_con (workspace , CF_OUTPUT );
583
- }
584
- if (fullscreen != NULL ) {
585
- /* Disable fullscreen for the currently fullscreened
586
- * container and enable it for the one the user wants
587
- * to have in fullscreen mode. */
588
- LOG ("Disabling fullscreen for (%p/%s) upon user request\n" ,
589
- fullscreen , fullscreen -> name );
590
- fullscreen -> fullscreen_mode = CF_NONE ;
591
- }
592
574
593
- /* 2: enable fullscreen */
594
- con -> fullscreen_mode = fullscreen_mode ;
595
- } else {
596
- /* 1: disable fullscreen */
597
- con -> fullscreen_mode = CF_NONE ;
598
- }
575
+ if (con -> fullscreen_mode == CF_NONE )
576
+ con_enable_fullscreen (con , fullscreen_mode );
577
+ else
578
+ con_disable_fullscreen (con );
579
+ }
580
+
581
+ /*
582
+ * Sets the specified fullscreen mode for the given container, sends the
583
+ * “fullscreen_mode” event and changes the XCB fullscreen property of the
584
+ * container’s window, if any.
585
+ *
586
+ */
587
+ static void con_set_fullscreen_mode (Con * con , fullscreen_mode_t fullscreen_mode ) {
588
+ con -> fullscreen_mode = fullscreen_mode ;
599
589
600
590
DLOG ("mode now: %d\n" , con -> fullscreen_mode );
601
591
@@ -618,6 +608,79 @@ void con_toggle_fullscreen(Con *con, int fullscreen_mode) {
618
608
A__NET_WM_STATE , XCB_ATOM_ATOM , 32 , num , values );
619
609
}
620
610
611
+ /*
612
+ * Enables fullscreen mode for the given container, if necessary.
613
+ *
614
+ * If the container’s mode is already CF_OUTPUT or CF_GLOBAL, the container is
615
+ * kept fullscreen but its mode is set to CF_GLOBAL and CF_OUTPUT,
616
+ * respectively.
617
+ *
618
+ * Other fullscreen containers will be disabled first, if they hide the new
619
+ * one.
620
+ *
621
+ */
622
+ void con_enable_fullscreen (Con * con , fullscreen_mode_t fullscreen_mode ) {
623
+ if (con -> type == CT_WORKSPACE ) {
624
+ DLOG ("You cannot make a workspace fullscreen.\n" );
625
+ return ;
626
+ }
627
+
628
+ assert (fullscreen_mode == CF_GLOBAL || fullscreen_mode == CF_OUTPUT );
629
+
630
+ if (fullscreen_mode == CF_GLOBAL )
631
+ DLOG ("enabling global fullscreen for %p / %s\n" , con , con -> name );
632
+ else
633
+ DLOG ("enabling fullscreen for %p / %s\n" , con , con -> name );
634
+
635
+ if (con -> fullscreen_mode == fullscreen_mode ) {
636
+ DLOG ("fullscreen already enabled for %p / %s\n" , con , con -> name );
637
+ return ;
638
+ }
639
+
640
+ Con * con_ws = con_get_workspace (con );
641
+
642
+ /* Disable any fullscreen container that would conflict the new one. */
643
+ Con * fullscreen = con_get_fullscreen_con (croot , CF_GLOBAL );
644
+ if (fullscreen == NULL )
645
+ fullscreen = con_get_fullscreen_con (con_ws , CF_OUTPUT );
646
+ if (fullscreen != NULL )
647
+ con_disable_fullscreen (fullscreen );
648
+
649
+ /* Set focus to new fullscreen container. Unless in global fullscreen mode
650
+ * and on another workspace restore focus afterwards.
651
+ * Switch to the container’s workspace if mode is global. */
652
+ Con * cur_ws = con_get_workspace (focused );
653
+ Con * old_focused = focused ;
654
+ if (fullscreen_mode == CF_GLOBAL && cur_ws != con_ws )
655
+ workspace_show (con_ws );
656
+ con_focus (con );
657
+ if (fullscreen_mode != CF_GLOBAL && cur_ws != con_ws )
658
+ con_focus (old_focused );
659
+
660
+ con_set_fullscreen_mode (con , fullscreen_mode );
661
+ }
662
+
663
+ /*
664
+ * Disables fullscreen mode for the given container regardless of the mode, if
665
+ * necessary.
666
+ *
667
+ */
668
+ void con_disable_fullscreen (Con * con ) {
669
+ if (con -> type == CT_WORKSPACE ) {
670
+ DLOG ("You cannot make a workspace fullscreen.\n" );
671
+ return ;
672
+ }
673
+
674
+ DLOG ("disabling fullscreen for %p / %s\n" , con , con -> name );
675
+
676
+ if (con -> fullscreen_mode == CF_NONE ) {
677
+ DLOG ("fullscreen already disabled for %p / %s\n" , con , con -> name );
678
+ return ;
679
+ }
680
+
681
+ con_set_fullscreen_mode (con , CF_NONE );
682
+ }
683
+
621
684
/*
622
685
* Moves the given container to the currently focused container on the given
623
686
* workspace.
0 commit comments