| 908 | } |
| 909 | |
| 910 | addWindow(metaWindow, index, row) { |
| 911 | if (!this.selectedWindow) |
| 912 | this.selectedWindow = metaWindow; |
| 913 | if (this.indexOf(metaWindow) !== -1) |
| 914 | return false; |
| 915 | |
| 916 | if (row !== undefined && this[index]) { |
| 917 | let column = this[index]; |
| 918 | column.splice(row, 0, metaWindow); |
| 919 | } else { |
| 920 | this.splice(index, 0, [metaWindow]); |
| 921 | } |
| 922 | |
| 923 | /* |
| 924 | * Fix (still needed in 45) for bug where move_frame sometimes triggers |
| 925 | * another move back to its original position. Make sure tiled windows are |
| 926 | * always positioned correctly (synced with clone position). |
| 927 | */ |
| 928 | this.signals.connect(metaWindow, 'position-changed', w => { |
| 929 | if (inGrab) |
| 930 | return; |
| 931 | |
| 932 | let f = w.get_frame_rect(); |
| 933 | let clone = w.clone; |
| 934 | let x = this.visibleX(w); |
| 935 | let y = this.monitor.y + clone.targetY; |
| 936 | x = Math.min(this.width - stack_margin, Math.max(stack_margin - f.width, x)); |
| 937 | x += this.monitor.x; |
| 938 | |
| 939 | // check if mismatch tracking needed, otherwise leave |
| 940 | if (f.x === x && f.y === y) { |
| 941 | // delete any mismatch counter (e.g. from previous attempt) |
| 942 | delete w._pos_mismatch_count; |
| 943 | return; |
| 944 | } |
| 945 | |
| 946 | // guard against recursively calling this method |
| 947 | // see https://github.com/paperwm/PaperWM/issues/769 |
| 948 | if (w._pos_mismatch_count && |
| 949 | w._pos_mismatch_count > 1) { |
| 950 | console.warn(`clone/window position-changed recursive call: ${w.title}`); |
| 951 | return; |
| 952 | } |
| 953 | |
| 954 | // mismatch detected |
| 955 | // move frame to ensure window position matches clone |
| 956 | try { |
| 957 | if (!w._pos_mismatch_count) { |
| 958 | w._pos_mismatch_count = 0; |
| 959 | } |
| 960 | else { |
| 961 | w._pos_mismatch_count += 1; |
| 962 | } |
| 963 | w.move_frame(true, x, y); |
| 964 | } |
| 965 | catch (ex) { |
| 966 | |
| 967 | } |