~profzoom/wmaker/master

« back to all changes in this revision

Viewing changes to src/actions.c

  • Committer: Carlos R. Mafra
  • Author(s): David Maciejak
  • Date: 2023-03-31 08:11:38 UTC
  • Revision ID: git-v1:ab45c6c6c2c624f0488d566c9108326ecf8d2843
Add central position feature for active window

This patch adds a new Central feature under the window menu
"Other maximization" entry.
Shortcut can be configured via WPrefs "Center active window" action.
When called the active window is centered on the screen head.
If the window height or width are bigger than the head size,
the window is resized to fit.
There are some transitions defined as below:
*from fullscreen to center
*from any corner to center
*from top half to center top half
*from bottom half to center bottom half
*from left half to center left half
*from right half to center right half

Undoing the action is done via the window menu "Unmaximize" entry
or the shortcut.

Show diffs side-by-side

added added

removed removed

Lines of Context:
404
404
        usableArea = wGetUsableAreaForHead(scr, head, &totalArea, True);
405
405
 
406
406
        /* Only save directions, not kbd or xinerama hints */
407
 
        directions &= (MAX_HORIZONTAL | MAX_VERTICAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_TOPHALF | MAX_BOTTOMHALF | MAX_MAXIMUS);
 
407
        directions &= (MAX_HORIZONTAL | MAX_VERTICAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_TOPHALF | MAX_BOTTOMHALF | MAX_MAXIMUS | MAX_CENTRAL);
408
408
 
409
409
        if (WFLAGP(wwin, full_maximize))
410
410
                usableArea = totalArea;
431
431
                wwin->maximus_y = new_y;
432
432
                wwin->flags.old_maximized |= MAX_MAXIMUS;
433
433
        } else {
 
434
                /* center the window if can fit, if not sticking it to the screen edges */
 
435
                if (directions & MAX_CENTRAL) {
 
436
                        if (wwin->frame->core->height > (usableArea.y2 - usableArea.y1)) {
 
437
                                new_y = usableArea.y1;
 
438
                                new_height = usableArea.y2 - usableArea.y1 - adj_size;
 
439
                        } else {
 
440
                                new_height = (wwin->old_geometry.height) ? wwin->old_geometry.height : wwin->frame->core->height;
 
441
                                new_height += wwin->frame->top_width + wwin->frame->bottom_width;
 
442
                                new_y = half_scr_height - new_height / 2;
 
443
                        }
 
444
                        if (wwin->frame->core->width > (usableArea.x2 - usableArea.x1)) {
 
445
                                new_x = usableArea.x1;
 
446
                                new_width = usableArea.x2 - usableArea.x1 - adj_size;
 
447
                        }
 
448
                        else {
 
449
                                new_width = (wwin->old_geometry.width) ? wwin->old_geometry.width : wwin->frame->core->width;
 
450
                                new_x = half_scr_width - new_width / 2;
 
451
                        }
 
452
                }
434
453
                /* set default values if no option set then */
435
 
                if (!(directions & (MAX_HORIZONTAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_MAXIMUS))) {
 
454
                if (!(directions & (MAX_HORIZONTAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_MAXIMUS | MAX_CENTRAL))) {
436
455
                        new_width = (wwin->old_geometry.width) ? wwin->old_geometry.width : wwin->frame->core->width;
437
456
                        new_x = (wwin->old_geometry.x) ? wwin->old_geometry.x : wwin->frame_x;
438
457
                }
439
 
                if (!(directions & (MAX_VERTICAL | MAX_TOPHALF | MAX_BOTTOMHALF | MAX_MAXIMUS))) {
 
458
                if (!(directions & (MAX_VERTICAL | MAX_TOPHALF | MAX_BOTTOMHALF | MAX_MAXIMUS| MAX_CENTRAL))) {
440
459
                        new_height = (wwin->old_geometry.height) ? wwin->old_geometry.height : wwin->frame->core->height;
441
460
                        new_y = (wwin->old_geometry.y) ? wwin->old_geometry.y : wwin->frame_y;
442
461
                }
445
464
                if (directions & MAX_LEFTHALF) {
446
465
                        new_width = half_scr_width - adj_size;
447
466
                        new_x = usableArea.x1;
 
467
                        if (directions & MAX_CENTRAL) {
 
468
                                new_y = half_scr_height - wwin->old_geometry.height / 2;
 
469
                        }
448
470
                } else if (directions & MAX_RIGHTHALF) {
449
471
                        new_width = half_scr_width - adj_size;
450
472
                        new_x = usableArea.x1 + half_scr_width;
 
473
                        if (directions & MAX_CENTRAL)
 
474
                                new_y = half_scr_height - wwin->old_geometry.height / 2;
451
475
                }
452
476
                /* top|bottom position */
453
477
                if (directions & MAX_TOPHALF) {
454
478
                        new_height = half_scr_height - adj_size;
455
479
                        new_y = usableArea.y1;
 
480
                        if (directions & MAX_CENTRAL)
 
481
                                new_x = half_scr_width - wwin->old_geometry.width / 2;
456
482
                } else if (directions & MAX_BOTTOMHALF) {
457
483
                        new_height = half_scr_height - adj_size;
458
484
                        new_y = usableArea.y1 + half_scr_height;
 
485
                        if (directions & MAX_CENTRAL)
 
486
                                new_x = half_scr_width - wwin->old_geometry.width / 2;
459
487
                }
460
488
 
461
489
                /* vertical|horizontal position */
494
522
void handleMaximize(WWindow *wwin, int directions)
495
523
{
496
524
        int current = wwin->flags.maximized;
497
 
        int requested = directions & (MAX_HORIZONTAL | MAX_VERTICAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_TOPHALF | MAX_BOTTOMHALF | MAX_MAXIMUS);
 
525
        int requested = directions & (MAX_HORIZONTAL | MAX_VERTICAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_TOPHALF | MAX_BOTTOMHALF | MAX_MAXIMUS | MAX_CENTRAL);
498
526
        int effective = requested ^ current;
499
527
        int flags = directions & ~requested;
500
528
        int head = wGetHeadForWindow(wwin);
625
653
                                head);
626
654
 
627
655
        else {
 
656
 
628
657
                if ((requested == (MAX_HORIZONTAL | MAX_VERTICAL)) ||
629
658
                                (requested == MAX_MAXIMUS))
630
659
                        effective = requested;
631
660
                else {
632
 
                        if (requested & MAX_LEFTHALF) {
 
661
                        if (requested & MAX_CENTRAL) {
 
662
                                effective |= MAX_CENTRAL;
 
663
                                if (current & (MAX_HORIZONTAL | MAX_VERTICAL))
 
664
                                        effective &= ~(MAX_HORIZONTAL | MAX_VERTICAL);
 
665
                                else if (current & MAX_TOPHALF && current & MAX_LEFTHALF)
 
666
                                        effective &= ~(MAX_TOPHALF | MAX_LEFTHALF);
 
667
                                else if (current & MAX_TOPHALF && current & MAX_RIGHTHALF)
 
668
                                        effective &= ~(MAX_TOPHALF | MAX_RIGHTHALF);
 
669
                                else if (current & MAX_BOTTOMHALF && current & MAX_LEFTHALF)
 
670
                                        effective &= ~(MAX_BOTTOMHALF | MAX_LEFTHALF);
 
671
                                else if (current & MAX_BOTTOMHALF && current & MAX_RIGHTHALF)
 
672
                                        effective &= ~(MAX_BOTTOMHALF | MAX_RIGHTHALF);
 
673
                        } else if (requested & MAX_LEFTHALF) {
633
674
                                if (!(requested & (MAX_TOPHALF | MAX_BOTTOMHALF)))
634
675
                                        effective |= MAX_VERTICAL;
635
676
                                else