1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148
|
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
Copyright (C) 2012 Martin Gräßlin <m.graesslin@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "options.h"
#include "config-kwin.h"
#include "utils.h"
#include "platform.h"
#ifndef KCMRULES
#include <QProcess>
#include "screens.h"
#include "settings.h"
#include <kwinglplatform.h>
#include <QOpenGLContext>
#endif //KCMRULES
namespace KWin
{
#ifndef KCMRULES
int currentRefreshRate()
{
return Options::currentRefreshRate();
}
int Options::currentRefreshRate()
{
int rate = -1;
QString syncScreenName(QLatin1String("primary screen"));
if (options->refreshRate() > 0) { // use manually configured refresh rate
rate = options->refreshRate();
} else if (Screens::self()->count() > 0) {
// prefer the refreshrate calculated from the screens mode information
// at least the nvidia driver reports 50Hz BS ... *again*!
int syncScreen = 0;
if (Screens::self()->count() > 1) {
const QByteArray syncDisplayDevice(qgetenv("__GL_SYNC_DISPLAY_DEVICE"));
// if __GL_SYNC_DISPLAY_DEVICE is exported, the GPU shall sync to that device
// so we try to use its refresh rate
if (!syncDisplayDevice.isEmpty()) {
for (int i = 0; i < Screens::self()->count(); ++i) {
if (Screens::self()->name(i) == syncDisplayDevice) {
syncScreenName = Screens::self()->name(i);
syncScreen = i;
break;
}
}
}
}
rate = qRound(Screens::self()->refreshRate(syncScreen)); // TODO forward float precision?
}
// 0Hz or less is invalid, so we fallback to a default rate
if (rate <= 0)
rate = 60; // and not shitty 50Hz for sure! *grrr*
// QTimer gives us 1msec (1000Hz) at best, so we ignore anything higher;
// however, additional throttling prevents very high rates from taking place anyway
else if (rate > 1000)
rate = 1000;
qCDebug(KWIN_CORE) << "Vertical Refresh rate " << rate << "Hz (" << syncScreenName << ")";
return rate;
}
Options::Options(QObject *parent)
: QObject(parent)
, m_settings(new Settings(kwinApp()->config()))
, m_focusPolicy(ClickToFocus)
, m_nextFocusPrefersMouse(false)
, m_clickRaise(false)
, m_autoRaise(false)
, m_autoRaiseInterval(0)
, m_delayFocusInterval(0)
, m_shadeHover(false)
, m_shadeHoverInterval(0)
, m_separateScreenFocus(false)
, m_placement(Placement::NoPlacement)
, m_borderSnapZone(0)
, m_windowSnapZone(0)
, m_centerSnapZone(0)
, m_snapOnlyWhenOverlapping(false)
, m_rollOverDesktops(false)
, m_focusStealingPreventionLevel(0)
, m_legacyFullscreenSupport(false)
, m_killPingTimeout(0)
, m_hideUtilityWindowsForInactive(false)
, m_inactiveTabsSkipTaskbar(false)
, m_autogroupSimilarWindows(false)
, m_autogroupInForeground(false)
, m_compositingMode(Options::defaultCompositingMode())
, m_useCompositing(Options::defaultUseCompositing())
, m_compositingInitialized(Options::defaultCompositingInitialized())
, m_hiddenPreviews(Options::defaultHiddenPreviews())
, m_glSmoothScale(Options::defaultGlSmoothScale())
, m_xrenderSmoothScale(Options::defaultXrenderSmoothScale())
, m_maxFpsInterval(Options::defaultMaxFpsInterval())
, m_refreshRate(Options::defaultRefreshRate())
, m_vBlankTime(Options::defaultVBlankTime())
, m_glStrictBinding(Options::defaultGlStrictBinding())
, m_glStrictBindingFollowsDriver(Options::defaultGlStrictBindingFollowsDriver())
, m_glCoreProfile(Options::defaultGLCoreProfile())
, m_glPreferBufferSwap(Options::defaultGlPreferBufferSwap())
, m_glPlatformInterface(Options::defaultGlPlatformInterface())
, m_windowsBlockCompositing(true)
, OpTitlebarDblClick(Options::defaultOperationTitlebarDblClick())
, CmdActiveTitlebar1(Options::defaultCommandActiveTitlebar1())
, CmdActiveTitlebar2(Options::defaultCommandActiveTitlebar2())
, CmdActiveTitlebar3(Options::defaultCommandActiveTitlebar3())
, CmdInactiveTitlebar1(Options::defaultCommandInactiveTitlebar1())
, CmdInactiveTitlebar2(Options::defaultCommandInactiveTitlebar2())
, CmdInactiveTitlebar3(Options::defaultCommandInactiveTitlebar3())
, CmdTitlebarWheel(Options::defaultCommandTitlebarWheel())
, CmdWindow1(Options::defaultCommandWindow1())
, CmdWindow2(Options::defaultCommandWindow2())
, CmdWindow3(Options::defaultCommandWindow3())
, CmdWindowWheel(Options::defaultCommandWindowWheel())
, CmdAll1(Options::defaultCommandAll1())
, CmdAll2(Options::defaultCommandAll2())
, CmdAll3(Options::defaultCommandAll3())
, CmdAllWheel(Options::defaultCommandAllWheel())
, CmdAllModKey(Options::defaultKeyCmdAllModKey())
, electric_border_maximize(false)
, electric_border_tiling(false)
, electric_border_corner_ratio(0.0)
, borderless_maximized_windows(false)
, show_geometry_tip(false)
, condensed_title(false)
, animationSpeed(Options::defaultAnimationSpeed())
{
m_settings->setDefaults();
syncFromKcfgc();
}
Options::~Options()
{
}
void Options::setFocusPolicy(FocusPolicy focusPolicy)
{
if (m_focusPolicy == focusPolicy) {
return;
}
m_focusPolicy = focusPolicy;
emit focusPolicyChanged();
if (m_focusPolicy == ClickToFocus) {
setAutoRaise(false);
setAutoRaiseInterval(0);
setDelayFocusInterval(0);
}
}
void Options::setNextFocusPrefersMouse(bool nextFocusPrefersMouse)
{
if (m_nextFocusPrefersMouse == nextFocusPrefersMouse) {
return;
}
m_nextFocusPrefersMouse = nextFocusPrefersMouse;
emit nextFocusPrefersMouseChanged();
}
void Options::setClickRaise(bool clickRaise)
{
if (m_autoRaise) {
// important: autoRaise implies ClickRaise
clickRaise = true;
}
if (m_clickRaise == clickRaise) {
return;
}
m_clickRaise = clickRaise;
emit clickRaiseChanged();
}
void Options::setAutoRaise(bool autoRaise)
{
if (m_focusPolicy == ClickToFocus) {
autoRaise = false;
}
if (m_autoRaise == autoRaise) {
return;
}
m_autoRaise = autoRaise;
if (m_autoRaise) {
// important: autoRaise implies ClickRaise
setClickRaise(true);
}
emit autoRaiseChanged();
}
void Options::setAutoRaiseInterval(int autoRaiseInterval)
{
if (m_focusPolicy == ClickToFocus) {
autoRaiseInterval = 0;
}
if (m_autoRaiseInterval == autoRaiseInterval) {
return;
}
m_autoRaiseInterval = autoRaiseInterval;
emit autoRaiseIntervalChanged();
}
void Options::setDelayFocusInterval(int delayFocusInterval)
{
if (m_focusPolicy == ClickToFocus) {
delayFocusInterval = 0;
}
if (m_delayFocusInterval == delayFocusInterval) {
return;
}
m_delayFocusInterval = delayFocusInterval;
emit delayFocusIntervalChanged();
}
void Options::setShadeHover(bool shadeHover)
{
if (m_shadeHover == shadeHover) {
return;
}
m_shadeHover = shadeHover;
emit shadeHoverChanged();
}
void Options::setShadeHoverInterval(int shadeHoverInterval)
{
if (m_shadeHoverInterval == shadeHoverInterval) {
return;
}
m_shadeHoverInterval = shadeHoverInterval;
emit shadeHoverIntervalChanged();
}
void Options::setSeparateScreenFocus(bool separateScreenFocus)
{
if (m_separateScreenFocus == separateScreenFocus) {
return;
}
m_separateScreenFocus = separateScreenFocus;
emit separateScreenFocusChanged(m_separateScreenFocus);
}
void Options::setPlacement(int placement)
{
if (m_placement == static_cast<Placement::Policy>(placement)) {
return;
}
m_placement = static_cast<Placement::Policy>(placement);
emit placementChanged();
}
void Options::setBorderSnapZone(int borderSnapZone)
{
if (m_borderSnapZone == borderSnapZone) {
return;
}
m_borderSnapZone = borderSnapZone;
emit borderSnapZoneChanged();
}
void Options::setWindowSnapZone(int windowSnapZone)
{
if (m_windowSnapZone == windowSnapZone) {
return;
}
m_windowSnapZone = windowSnapZone;
emit windowSnapZoneChanged();
}
void Options::setCenterSnapZone(int centerSnapZone)
{
if (m_centerSnapZone == centerSnapZone) {
return;
}
m_centerSnapZone = centerSnapZone;
emit centerSnapZoneChanged();
}
void Options::setSnapOnlyWhenOverlapping(bool snapOnlyWhenOverlapping)
{
if (m_snapOnlyWhenOverlapping == snapOnlyWhenOverlapping) {
return;
}
m_snapOnlyWhenOverlapping = snapOnlyWhenOverlapping;
emit snapOnlyWhenOverlappingChanged();
}
void Options::setRollOverDesktops(bool rollOverDesktops)
{
if (m_rollOverDesktops == rollOverDesktops) {
return;
}
m_rollOverDesktops = rollOverDesktops;
emit rollOverDesktopsChanged(m_rollOverDesktops);
}
void Options::setFocusStealingPreventionLevel(int focusStealingPreventionLevel)
{
if (!focusPolicyIsReasonable()) {
focusStealingPreventionLevel = 0;
}
if (m_focusStealingPreventionLevel == focusStealingPreventionLevel) {
return;
}
m_focusStealingPreventionLevel = qMax(0, qMin(4, focusStealingPreventionLevel));
emit focusStealingPreventionLevelChanged();
}
void Options::setLegacyFullscreenSupport(bool legacyFullscreenSupport)
{
if (m_legacyFullscreenSupport == legacyFullscreenSupport) {
return;
}
m_legacyFullscreenSupport = legacyFullscreenSupport;
emit legacyFullscreenSupportChanged();
}
void Options::setOperationTitlebarDblClick(WindowOperation operationTitlebarDblClick)
{
if (OpTitlebarDblClick == operationTitlebarDblClick) {
return;
}
OpTitlebarDblClick = operationTitlebarDblClick;
emit operationTitlebarDblClickChanged();
}
void Options::setOperationMaxButtonLeftClick(WindowOperation op)
{
if (opMaxButtonLeftClick == op) {
return;
}
opMaxButtonLeftClick = op;
emit operationMaxButtonLeftClickChanged();
}
void Options::setOperationMaxButtonRightClick(WindowOperation op)
{
if (opMaxButtonRightClick == op) {
return;
}
opMaxButtonRightClick = op;
emit operationMaxButtonRightClickChanged();
}
void Options::setOperationMaxButtonMiddleClick(WindowOperation op)
{
if (opMaxButtonMiddleClick == op) {
return;
}
opMaxButtonMiddleClick = op;
emit operationMaxButtonMiddleClickChanged();
}
void Options::setCommandActiveTitlebar1(MouseCommand commandActiveTitlebar1)
{
if (CmdActiveTitlebar1 == commandActiveTitlebar1) {
return;
}
CmdActiveTitlebar1 = commandActiveTitlebar1;
emit commandActiveTitlebar1Changed();
}
void Options::setCommandActiveTitlebar2(MouseCommand commandActiveTitlebar2)
{
if (CmdActiveTitlebar2 == commandActiveTitlebar2) {
return;
}
CmdActiveTitlebar2 = commandActiveTitlebar2;
emit commandActiveTitlebar2Changed();
}
void Options::setCommandActiveTitlebar3(MouseCommand commandActiveTitlebar3)
{
if (CmdActiveTitlebar3 == commandActiveTitlebar3) {
return;
}
CmdActiveTitlebar3 = commandActiveTitlebar3;
emit commandActiveTitlebar3Changed();
}
void Options::setCommandInactiveTitlebar1(MouseCommand commandInactiveTitlebar1)
{
if (CmdInactiveTitlebar1 == commandInactiveTitlebar1) {
return;
}
CmdInactiveTitlebar1 = commandInactiveTitlebar1;
emit commandInactiveTitlebar1Changed();
}
void Options::setCommandInactiveTitlebar2(MouseCommand commandInactiveTitlebar2)
{
if (CmdInactiveTitlebar2 == commandInactiveTitlebar2) {
return;
}
CmdInactiveTitlebar2 = commandInactiveTitlebar2;
emit commandInactiveTitlebar2Changed();
}
void Options::setCommandInactiveTitlebar3(MouseCommand commandInactiveTitlebar3)
{
if (CmdInactiveTitlebar3 == commandInactiveTitlebar3) {
return;
}
CmdInactiveTitlebar3 = commandInactiveTitlebar3;
emit commandInactiveTitlebar3Changed();
}
void Options::setCommandWindow1(MouseCommand commandWindow1)
{
if (CmdWindow1 == commandWindow1) {
return;
}
CmdWindow1 = commandWindow1;
emit commandWindow1Changed();
}
void Options::setCommandWindow2(MouseCommand commandWindow2)
{
if (CmdWindow2 == commandWindow2) {
return;
}
CmdWindow2 = commandWindow2;
emit commandWindow2Changed();
}
void Options::setCommandWindow3(MouseCommand commandWindow3)
{
if (CmdWindow3 == commandWindow3) {
return;
}
CmdWindow3 = commandWindow3;
emit commandWindow3Changed();
}
void Options::setCommandWindowWheel(MouseCommand commandWindowWheel)
{
if (CmdWindowWheel == commandWindowWheel) {
return;
}
CmdWindowWheel = commandWindowWheel;
emit commandWindowWheelChanged();
}
void Options::setCommandAll1(MouseCommand commandAll1)
{
if (CmdAll1 == commandAll1) {
return;
}
CmdAll1 = commandAll1;
emit commandAll1Changed();
}
void Options::setCommandAll2(MouseCommand commandAll2)
{
if (CmdAll2 == commandAll2) {
return;
}
CmdAll2 = commandAll2;
emit commandAll2Changed();
}
void Options::setCommandAll3(MouseCommand commandAll3)
{
if (CmdAll3 == commandAll3) {
return;
}
CmdAll3 = commandAll3;
emit commandAll3Changed();
}
void Options::setKeyCmdAllModKey(uint keyCmdAllModKey)
{
if (CmdAllModKey == keyCmdAllModKey) {
return;
}
CmdAllModKey = keyCmdAllModKey;
emit keyCmdAllModKeyChanged();
}
void Options::setShowGeometryTip(bool showGeometryTip)
{
if (show_geometry_tip == showGeometryTip) {
return;
}
show_geometry_tip = showGeometryTip;
emit showGeometryTipChanged();
}
void Options::setCondensedTitle(bool condensedTitle)
{
if (condensed_title == condensedTitle) {
return;
}
condensed_title = condensedTitle;
emit condensedTitleChanged();
}
void Options::setElectricBorderMaximize(bool electricBorderMaximize)
{
if (electric_border_maximize == electricBorderMaximize) {
return;
}
electric_border_maximize = electricBorderMaximize;
emit electricBorderMaximizeChanged();
}
void Options::setElectricBorderTiling(bool electricBorderTiling)
{
if (electric_border_tiling == electricBorderTiling) {
return;
}
electric_border_tiling = electricBorderTiling;
emit electricBorderTilingChanged();
}
void Options::setElectricBorderCornerRatio(float electricBorderCornerRatio)
{
if (electric_border_corner_ratio == electricBorderCornerRatio) {
return;
}
electric_border_corner_ratio = electricBorderCornerRatio;
emit electricBorderCornerRatioChanged();
}
void Options::setBorderlessMaximizedWindows(bool borderlessMaximizedWindows)
{
if (borderless_maximized_windows == borderlessMaximizedWindows) {
return;
}
borderless_maximized_windows = borderlessMaximizedWindows;
emit borderlessMaximizedWindowsChanged();
}
void Options::setKillPingTimeout(int killPingTimeout)
{
if (m_killPingTimeout == killPingTimeout) {
return;
}
m_killPingTimeout = killPingTimeout;
emit killPingTimeoutChanged();
}
void Options::setHideUtilityWindowsForInactive(bool hideUtilityWindowsForInactive)
{
if (m_hideUtilityWindowsForInactive == hideUtilityWindowsForInactive) {
return;
}
m_hideUtilityWindowsForInactive = hideUtilityWindowsForInactive;
emit hideUtilityWindowsForInactiveChanged();
}
void Options::setInactiveTabsSkipTaskbar(bool inactiveTabsSkipTaskbar)
{
if (m_inactiveTabsSkipTaskbar == inactiveTabsSkipTaskbar) {
return;
}
m_inactiveTabsSkipTaskbar = inactiveTabsSkipTaskbar;
emit inactiveTabsSkipTaskbarChanged();
}
void Options::setAutogroupSimilarWindows(bool autogroupSimilarWindows)
{
if (m_autogroupSimilarWindows == autogroupSimilarWindows) {
return;
}
m_autogroupSimilarWindows = autogroupSimilarWindows;
emit autogroupSimilarWindowsChanged();
}
void Options::setAutogroupInForeground(bool autogroupInForeground)
{
if (m_autogroupInForeground == autogroupInForeground) {
return;
}
m_autogroupInForeground = autogroupInForeground;
emit autogroupInForegroundChanged();
}
void Options::setCompositingMode(int compositingMode)
{
if (m_compositingMode == static_cast<CompositingType>(compositingMode)) {
return;
}
m_compositingMode = static_cast<CompositingType>(compositingMode);
emit compositingModeChanged();
}
void Options::setUseCompositing(bool useCompositing)
{
if (m_useCompositing == useCompositing) {
return;
}
m_useCompositing = useCompositing;
emit useCompositingChanged();
}
void Options::setCompositingInitialized(bool compositingInitialized)
{
if (m_compositingInitialized == compositingInitialized) {
return;
}
m_compositingInitialized = compositingInitialized;
emit compositingInitializedChanged();
}
void Options::setHiddenPreviews(int hiddenPreviews)
{
if (m_hiddenPreviews == static_cast<HiddenPreviews>(hiddenPreviews)) {
return;
}
m_hiddenPreviews = static_cast<HiddenPreviews>(hiddenPreviews);
emit hiddenPreviewsChanged();
}
void Options::setGlSmoothScale(int glSmoothScale)
{
if (m_glSmoothScale == glSmoothScale) {
return;
}
m_glSmoothScale = glSmoothScale;
emit glSmoothScaleChanged();
}
void Options::setXrenderSmoothScale(bool xrenderSmoothScale)
{
if (m_xrenderSmoothScale == xrenderSmoothScale) {
return;
}
m_xrenderSmoothScale = xrenderSmoothScale;
emit xrenderSmoothScaleChanged();
}
void Options::setMaxFpsInterval(qint64 maxFpsInterval)
{
if (m_maxFpsInterval == maxFpsInterval) {
return;
}
m_maxFpsInterval = maxFpsInterval;
emit maxFpsIntervalChanged();
}
void Options::setRefreshRate(uint refreshRate)
{
if (m_refreshRate == refreshRate) {
return;
}
m_refreshRate = refreshRate;
emit refreshRateChanged();
}
void Options::setVBlankTime(qint64 vBlankTime)
{
if (m_vBlankTime == vBlankTime) {
return;
}
m_vBlankTime = vBlankTime;
emit vBlankTimeChanged();
}
void Options::setGlStrictBinding(bool glStrictBinding)
{
if (m_glStrictBinding == glStrictBinding) {
return;
}
m_glStrictBinding = glStrictBinding;
emit glStrictBindingChanged();
}
void Options::setGlStrictBindingFollowsDriver(bool glStrictBindingFollowsDriver)
{
if (m_glStrictBindingFollowsDriver == glStrictBindingFollowsDriver) {
return;
}
m_glStrictBindingFollowsDriver = glStrictBindingFollowsDriver;
emit glStrictBindingFollowsDriverChanged();
}
void Options::setGLCoreProfile(bool value)
{
if (m_glCoreProfile == value) {
return;
}
m_glCoreProfile = value;
emit glCoreProfileChanged();
}
void Options::setWindowsBlockCompositing(bool value)
{
if (m_windowsBlockCompositing == value) {
return;
}
m_windowsBlockCompositing = value;
emit windowsBlockCompositingChanged();
}
void Options::setGlPreferBufferSwap(char glPreferBufferSwap)
{
if (glPreferBufferSwap == 'a') {
// buffer cpying is very fast with the nvidia blob
// but due to restrictions in DRI2 *incredibly* slow for all MESA drivers
// see http://www.x.org/releases/X11R7.7/doc/dri2proto/dri2proto.txt, item 2.5
if (GLPlatform::instance()->driver() == Driver_NVidia)
glPreferBufferSwap = CopyFrontBuffer;
else if (GLPlatform::instance()->driver() != Driver_Unknown) // undetected, finally resolved when context is initialized
glPreferBufferSwap = ExtendDamage;
}
if (m_glPreferBufferSwap == (GlSwapStrategy)glPreferBufferSwap) {
return;
}
m_glPreferBufferSwap = (GlSwapStrategy)glPreferBufferSwap;
emit glPreferBufferSwapChanged();
}
void Options::setGlPlatformInterface(OpenGLPlatformInterface interface)
{
// check environment variable
const QByteArray envOpenGLInterface(qgetenv("KWIN_OPENGL_INTERFACE"));
if (!envOpenGLInterface.isEmpty()) {
if (qstrcmp(envOpenGLInterface, "egl") == 0) {
qCDebug(KWIN_CORE) << "Forcing EGL native interface through environment variable";
interface = EglPlatformInterface;
} else if (qstrcmp(envOpenGLInterface, "glx") == 0) {
qCDebug(KWIN_CORE) << "Forcing GLX native interface through environment variable";
interface = GlxPlatformInterface;
}
}
if (kwinApp()->shouldUseWaylandForCompositing() && interface == GlxPlatformInterface) {
// Glx is impossible on Wayland, enforce egl
qCDebug(KWIN_CORE) << "Forcing EGL native interface for Wayland mode";
interface = EglPlatformInterface;
}
#if !HAVE_EPOXY_GLX
qCDebug(KWIN_CORE) << "Forcing EGL native interface as compiled without GLX support";
interface = EglPlatformInterface;
#endif
if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES) {
qCDebug(KWIN_CORE) << "Forcing EGL native interface as Qt uses OpenGL ES";
interface = EglPlatformInterface;
} else if (qstrcmp(qgetenv("KWIN_COMPOSE"), "O2ES") == 0) {
qCDebug(KWIN_CORE) << "Forcing EGL native interface as OpenGL ES requested through KWIN_COMPOSE environment variable.";
interface = EglPlatformInterface;
}
if (m_glPlatformInterface == interface) {
return;
}
m_glPlatformInterface = interface;
emit glPlatformInterfaceChanged();
}
void Options::reparseConfiguration()
{
m_settings->config()->reparseConfiguration();
}
void Options::updateSettings()
{
loadConfig();
// Read button tooltip animation effect from kdeglobals
// Since we want to allow users to enable window decoration tooltips
// and not kstyle tooltips and vise-versa, we don't read the
// "EffectNoTooltip" setting from kdeglobals.
// QToolTip::setGloballyEnabled( d->show_tooltips );
// KDE4 this probably needs to be done manually in clients
// Driver-specific config detection
setCompositingInitialized(false);
reloadCompositingSettings();
emit configChanged();
}
void Options::loadConfig()
{
m_settings->load();
syncFromKcfgc();
// Electric borders
KConfigGroup config(m_settings->config(), "Windows");
OpTitlebarDblClick = windowOperation(config.readEntry("TitlebarDoubleClickCommand", "Maximize"), true);
setOperationMaxButtonLeftClick(windowOperation(config.readEntry("MaximizeButtonLeftClickCommand", "Maximize"), true));
setOperationMaxButtonMiddleClick(windowOperation(config.readEntry("MaximizeButtonMiddleClickCommand", "Maximize (vertical only)"), true));
setOperationMaxButtonRightClick(windowOperation(config.readEntry("MaximizeButtonRightClickCommand", "Maximize (horizontal only)"), true));
// Mouse bindings
config = KConfigGroup(m_settings->config(), "MouseBindings");
// TODO: add properties for missing options
CmdTitlebarWheel = mouseWheelCommand(config.readEntry("CommandTitlebarWheel", "Switch to Window Tab to the Left/Right"));
CmdAllModKey = (config.readEntry("CommandAllKey", "Alt") == QStringLiteral("Meta")) ? Qt::Key_Meta : Qt::Key_Alt;
CmdAllWheel = mouseWheelCommand(config.readEntry("CommandAllWheel", "Nothing"));
setCommandActiveTitlebar1(mouseCommand(config.readEntry("CommandActiveTitlebar1", "Raise"), true));
setCommandActiveTitlebar2(mouseCommand(config.readEntry("CommandActiveTitlebar2", "Start Window Tab Drag"), true));
setCommandActiveTitlebar3(mouseCommand(config.readEntry("CommandActiveTitlebar3", "Operations menu"), true));
setCommandInactiveTitlebar1(mouseCommand(config.readEntry("CommandInactiveTitlebar1", "Activate and raise"), true));
setCommandInactiveTitlebar2(mouseCommand(config.readEntry("CommandInactiveTitlebar2", "Start Window Tab Drag"), true));
setCommandInactiveTitlebar3(mouseCommand(config.readEntry("CommandInactiveTitlebar3", "Operations menu"), true));
setCommandWindow1(mouseCommand(config.readEntry("CommandWindow1", "Activate, raise and pass click"), false));
setCommandWindow2(mouseCommand(config.readEntry("CommandWindow2", "Activate and pass click"), false));
setCommandWindow3(mouseCommand(config.readEntry("CommandWindow3", "Activate and pass click"), false));
setCommandWindowWheel(mouseCommand(config.readEntry("CommandWindowWheel", "Scroll"), false));
setCommandAll1(mouseCommand(config.readEntry("CommandAll1", "Move"), false));
setCommandAll2(mouseCommand(config.readEntry("CommandAll2", "Toggle raise and lower"), false));
setCommandAll3(mouseCommand(config.readEntry("CommandAll3", "Resize"), false));
// TODO: should they be moved into reloadCompositingSettings?
config = KConfigGroup(m_settings->config(), "Compositing");
setMaxFpsInterval(1 * 1000 * 1000 * 1000 / config.readEntry("MaxFPS", Options::defaultMaxFps()));
setRefreshRate(config.readEntry("RefreshRate", Options::defaultRefreshRate()));
setVBlankTime(config.readEntry("VBlankTime", Options::defaultVBlankTime()) * 1000); // config in micro, value in nano resolution
// Modifier Only Shortcuts
config = KConfigGroup(m_settings->config(), "ModifierOnlyShortcuts");
m_modifierOnlyShortcuts.clear();
if (config.hasKey("Shift")) {
m_modifierOnlyShortcuts.insert(Qt::ShiftModifier, config.readEntry("Shift", QStringList()));
}
if (config.hasKey("Control")) {
m_modifierOnlyShortcuts.insert(Qt::ControlModifier, config.readEntry("Control", QStringList()));
}
if (config.hasKey("Alt")) {
m_modifierOnlyShortcuts.insert(Qt::AltModifier, config.readEntry("Alt", QStringList()));
}
m_modifierOnlyShortcuts.insert(Qt::MetaModifier, config.readEntry("Meta", QStringList{QStringLiteral("org.kde.plasmashell"),
QStringLiteral("/PlasmaShell"),
QStringLiteral("org.kde.PlasmaShell"),
QStringLiteral("activateLauncherMenu")}));
}
void Options::syncFromKcfgc()
{
setShowGeometryTip(m_settings->geometryTip());
setCondensedTitle(m_settings->condensedTitle());
setFocusPolicy(m_settings->focusPolicy());
setNextFocusPrefersMouse(m_settings->nextFocusPrefersMouse());
setSeparateScreenFocus(m_settings->separateScreenFocus());
setRollOverDesktops(m_settings->rollOverDesktops());
setLegacyFullscreenSupport(m_settings->legacyFullscreenSupport());
setFocusStealingPreventionLevel(m_settings->focusStealingPreventionLevel());
#ifdef KWIN_BUILD_DECORATIONS
setPlacement(m_settings->placement());
#else
setPlacement(Placement::Maximizing);
#endif
setAutoRaise(m_settings->autoRaise());
setAutoRaiseInterval(m_settings->autoRaiseInterval());
setDelayFocusInterval(m_settings->delayFocusInterval());
setShadeHover(m_settings->shadeHover());
setShadeHoverInterval(m_settings->shadeHoverInterval());
setClickRaise(m_settings->clickRaise());
setBorderSnapZone(m_settings->borderSnapZone());
setWindowSnapZone(m_settings->windowSnapZone());
setCenterSnapZone(m_settings->centerSnapZone());
setSnapOnlyWhenOverlapping(m_settings->snapOnlyWhenOverlapping());
setKillPingTimeout(m_settings->killPingTimeout());
setHideUtilityWindowsForInactive(m_settings->hideUtilityWindowsForInactive());
setInactiveTabsSkipTaskbar(m_settings->inactiveTabsSkipTaskbar());
setAutogroupSimilarWindows(m_settings->autogroupSimilarWindows());
setAutogroupInForeground(m_settings->autogroupInForeground());
setBorderlessMaximizedWindows(m_settings->borderlessMaximizedWindows());
setElectricBorderMaximize(m_settings->electricBorderMaximize());
setElectricBorderTiling(m_settings->electricBorderTiling());
setElectricBorderCornerRatio(m_settings->electricBorderCornerRatio());
setWindowsBlockCompositing(m_settings->windowsBlockCompositing());
}
bool Options::loadCompositingConfig (bool force)
{
KConfigGroup config(m_settings->config(), "Compositing");
bool useCompositing = false;
CompositingType compositingMode = NoCompositing;
QString compositingBackend = config.readEntry("Backend", "OpenGL");
if (compositingBackend == QStringLiteral("XRender"))
compositingMode = XRenderCompositing;
else if (compositingBackend == "QPainter")
compositingMode = QPainterCompositing;
else
compositingMode = OpenGLCompositing;
if (const char *c = getenv("KWIN_COMPOSE")) {
switch(c[0]) {
case 'O':
qCDebug(KWIN_CORE) << "Compositing forced to OpenGL mode by environment variable";
compositingMode = OpenGLCompositing;
useCompositing = true;
break;
case 'X':
qCDebug(KWIN_CORE) << "Compositing forced to XRender mode by environment variable";
compositingMode = XRenderCompositing;
useCompositing = true;
break;
case 'Q':
qCDebug(KWIN_CORE) << "Compositing forced to QPainter mode by environment variable";
compositingMode = QPainterCompositing;
useCompositing = true;
break;
case 'N':
if (getenv("KDE_FAILSAFE"))
qCDebug(KWIN_CORE) << "Compositing disabled forcefully by KDE failsafe mode";
else
qCDebug(KWIN_CORE) << "Compositing disabled forcefully by environment variable";
compositingMode = NoCompositing;
break;
default:
qCDebug(KWIN_CORE) << "Unknown KWIN_COMPOSE mode set, ignoring";
break;
}
}
setCompositingMode(compositingMode);
const bool platformSupportsNoCompositing = kwinApp()->platform()->supportedCompositors().contains(NoCompositing);
if (m_compositingMode == NoCompositing && platformSupportsNoCompositing) {
setUseCompositing(false);
return false; // do not even detect compositing preferences if explicitly disabled
}
// it's either enforced by env or by initial resume from "suspend" or we check the settings
setUseCompositing(useCompositing || force || config.readEntry("Enabled", Options::defaultUseCompositing() || !platformSupportsNoCompositing));
if (!m_useCompositing)
return false; // not enforced or necessary and not "enabled" by settings
return true;
}
void Options::reloadCompositingSettings(bool force)
{
if (!loadCompositingConfig(force)) {
return;
}
m_settings->load();
syncFromKcfgc();
// from now on we've an initial setup and don't have to reload settings on compositing activation
// see Workspace::setupCompositing(), composite.cpp
setCompositingInitialized(true);
// Compositing settings
KConfigGroup config(m_settings->config(), "Compositing");
setGlSmoothScale(qBound(-1, config.readEntry("GLTextureFilter", Options::defaultGlSmoothScale()), 2));
setGlStrictBindingFollowsDriver(!config.hasKey("GLStrictBinding"));
if (!isGlStrictBindingFollowsDriver()) {
setGlStrictBinding(config.readEntry("GLStrictBinding", Options::defaultGlStrictBinding()));
}
setGLCoreProfile(config.readEntry("GLCore", Options::defaultGLCoreProfile()));
char c = 0;
const QString s = config.readEntry("GLPreferBufferSwap", QString(Options::defaultGlPreferBufferSwap()));
if (!s.isEmpty())
c = s.at(0).toAscii();
if (c != 'a' && c != 'c' && c != 'p' && c != 'e')
c = 0;
setGlPreferBufferSwap(c);
m_xrenderSmoothScale = config.readEntry("XRenderSmoothScale", false);
HiddenPreviews previews = Options::defaultHiddenPreviews();
// 4 - off, 5 - shown, 6 - always, other are old values
int hps = config.readEntry("HiddenPreviews", 5);
if (hps == 4)
previews = HiddenPreviewsNever;
else if (hps == 5)
previews = HiddenPreviewsShown;
else if (hps == 6)
previews = HiddenPreviewsAlways;
setHiddenPreviews(previews);
// TOOD: add setter
animationSpeed = qBound(0, config.readEntry("AnimationSpeed", Options::defaultAnimationSpeed()), 6);
auto interfaceToKey = [](OpenGLPlatformInterface interface) {
switch (interface) {
case GlxPlatformInterface:
return QStringLiteral("glx");
case EglPlatformInterface:
return QStringLiteral("egl");
default:
return QString();
}
};
auto keyToInterface = [](const QString &key) {
if (key == QStringLiteral("glx")) {
return GlxPlatformInterface;
} else if (key == QStringLiteral("egl")) {
return EglPlatformInterface;
}
return defaultGlPlatformInterface();
};
setGlPlatformInterface(keyToInterface(config.readEntry("GLPlatformInterface", interfaceToKey(m_glPlatformInterface))));
}
// restricted should be true for operations that the user may not be able to repeat
// if the window is moved out of the workspace (e.g. if the user moves a window
// by the titlebar, and moves it too high beneath Kicker at the top edge, they
// may not be able to move it back, unless they know about Alt+LMB)
Options::WindowOperation Options::windowOperation(const QString &name, bool restricted)
{
if (name == QStringLiteral("Move"))
return restricted ? MoveOp : UnrestrictedMoveOp;
else if (name == QStringLiteral("Resize"))
return restricted ? ResizeOp : UnrestrictedResizeOp;
else if (name == QStringLiteral("Maximize"))
return MaximizeOp;
else if (name == QStringLiteral("Minimize"))
return MinimizeOp;
else if (name == QStringLiteral("Close"))
return CloseOp;
else if (name == QStringLiteral("OnAllDesktops"))
return OnAllDesktopsOp;
else if (name == QStringLiteral("Shade"))
return ShadeOp;
else if (name == QStringLiteral("Operations"))
return OperationsOp;
else if (name == QStringLiteral("Maximize (vertical only)"))
return VMaximizeOp;
else if (name == QStringLiteral("Maximize (horizontal only)"))
return HMaximizeOp;
else if (name == QStringLiteral("Lower"))
return LowerOp;
return NoOp;
}
Options::MouseCommand Options::mouseCommand(const QString &name, bool restricted)
{
QString lowerName = name.toLower();
if (lowerName == QStringLiteral("raise")) return MouseRaise;
if (lowerName == QStringLiteral("lower")) return MouseLower;
if (lowerName == QStringLiteral("operations menu")) return MouseOperationsMenu;
if (lowerName == QStringLiteral("toggle raise and lower")) return MouseToggleRaiseAndLower;
if (lowerName == QStringLiteral("activate and raise")) return MouseActivateAndRaise;
if (lowerName == QStringLiteral("activate and lower")) return MouseActivateAndLower;
if (lowerName == QStringLiteral("activate")) return MouseActivate;
if (lowerName == QStringLiteral("activate, raise and pass click")) return MouseActivateRaiseAndPassClick;
if (lowerName == QStringLiteral("activate and pass click")) return MouseActivateAndPassClick;
if (lowerName == QStringLiteral("scroll")) return MouseNothing;
if (lowerName == QStringLiteral("activate and scroll")) return MouseActivateAndPassClick;
if (lowerName == QStringLiteral("activate, raise and scroll")) return MouseActivateRaiseAndPassClick;
if (lowerName == QStringLiteral("activate, raise and move"))
return restricted ? MouseActivateRaiseAndMove : MouseActivateRaiseAndUnrestrictedMove;
if (lowerName == QStringLiteral("move")) return restricted ? MouseMove : MouseUnrestrictedMove;
if (lowerName == QStringLiteral("resize")) return restricted ? MouseResize : MouseUnrestrictedResize;
if (lowerName == QStringLiteral("shade")) return MouseShade;
if (lowerName == QStringLiteral("minimize")) return MouseMinimize;
if (lowerName == QStringLiteral("start window tab drag")) return MouseDragTab;
if (lowerName == QStringLiteral("close")) return MouseClose;
if (lowerName == QStringLiteral("increase opacity")) return MouseOpacityMore;
if (lowerName == QStringLiteral("decrease opacity")) return MouseOpacityLess;
if (lowerName == QStringLiteral("nothing")) return MouseNothing;
return MouseNothing;
}
Options::MouseWheelCommand Options::mouseWheelCommand(const QString &name)
{
QString lowerName = name.toLower();
if (lowerName == QStringLiteral("raise/lower")) return MouseWheelRaiseLower;
if (lowerName == QStringLiteral("shade/unshade")) return MouseWheelShadeUnshade;
if (lowerName == QStringLiteral("maximize/restore")) return MouseWheelMaximizeRestore;
if (lowerName == QStringLiteral("above/below")) return MouseWheelAboveBelow;
if (lowerName == QStringLiteral("previous/next desktop")) return MouseWheelPreviousNextDesktop;
if (lowerName == QStringLiteral("change opacity")) return MouseWheelChangeOpacity;
if (lowerName == QStringLiteral("switch to window tab to the left/right")) return MouseWheelChangeCurrentTab;
if (lowerName == QStringLiteral("nothing")) return MouseWheelNothing;
return MouseWheelChangeCurrentTab;
}
bool Options::showGeometryTip() const
{
return show_geometry_tip;
}
bool Options::condensedTitle() const
{
return condensed_title;
}
Options::MouseCommand Options::wheelToMouseCommand(MouseWheelCommand com, int delta) const
{
switch(com) {
case MouseWheelRaiseLower:
return delta > 0 ? MouseRaise : MouseLower;
case MouseWheelShadeUnshade:
return delta > 0 ? MouseSetShade : MouseUnsetShade;
case MouseWheelMaximizeRestore:
return delta > 0 ? MouseMaximize : MouseRestore;
case MouseWheelAboveBelow:
return delta > 0 ? MouseAbove : MouseBelow;
case MouseWheelPreviousNextDesktop:
return delta > 0 ? MousePreviousDesktop : MouseNextDesktop;
case MouseWheelChangeOpacity:
return delta > 0 ? MouseOpacityMore : MouseOpacityLess;
case MouseWheelChangeCurrentTab:
return delta > 0 ? MousePreviousTab : MouseNextTab;
default:
return MouseNothing;
}
}
#endif
double Options::animationTimeFactor() const
{
const double factors[] = { 0, 0.2, 0.5, 1, 2, 4, 20 };
return factors[ animationSpeed ];
}
Options::WindowOperation Options::operationMaxButtonClick(Qt::MouseButtons button) const
{
return button == Qt::RightButton ? opMaxButtonRightClick :
button == Qt::MidButton ? opMaxButtonMiddleClick :
opMaxButtonLeftClick;
}
QStringList Options::modifierOnlyDBusShortcut(Qt::KeyboardModifier mod) const
{
return m_modifierOnlyShortcuts.value(mod);
}
bool Options::isUseCompositing() const
{
return m_useCompositing || kwinApp()->platform()->requiresCompositing();
}
} // namespace
|